Reduced input variables

This commit is contained in:
2026-05-21 20:25:33 -05:00
parent 72d84d5556
commit 178987a0f1
5 changed files with 75 additions and 124 deletions

View File

@@ -11,7 +11,6 @@ Table of Contents
- [Installation](#installation) - [Installation](#installation)
- [Usage](#usage) - [Usage](#usage)
- [Deploy](#deploy) - [Deploy](#deploy)
- [Slug](#slug)
- [Cleanup](#cleanup) - [Cleanup](#cleanup)
- [Roadmap](#roadmap) - [Roadmap](#roadmap)
@@ -72,65 +71,39 @@ See `examples/deploy.yml` for a complete workflow covering production, preview,
### Deploy ### Deploy
Builds the Docker image, starts the container, and registers a Pangolin resource. Builds the Docker image, starts the container, and registers a Pangolin resource. The branch name drives everything else: pushes to the repo's default branch deploy as `production`, all other branches deploy as previews with a slugified tag, a deterministic host port, and a `${slug}.${app-name}` subdomain.
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/deploy@v1 - uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/deploy@v1
with: with:
app-name: my-app app-name: my-app
tag: production branch: ${{ github.ref_name }}
port: "3001"
environment: production
subdomain: my-app
Inputs Inputs
`app-name` `app-name`
Application name (used for image/container naming) Application name (used for image/container naming, and as the production subdomain)
`tag` `branch`
Image/container tag (e.g. `production` or a branch slug) Branch name. Matches against `github.event.repository.default_branch` to decide production vs. preview. `refs/heads/` prefix is stripped.
`port`
Host port to expose
`internal-port` `internal-port`
Port the app listens on inside the container (default `3000`) Port the app listens on inside the container (default `3000`)
`environment`
`production` or `preview`
`subdomain`
Subdomain for the Pangolin resource
`build-args` `build-args`
Extra `KEY=VALUE` docker build args (space-separated) Extra `KEY=VALUE` docker build args (space-separated)
### Slug
Derives a URL-safe slug and a deterministic port from a branch name. Strips `refs/heads/` so either `github.ref_name` or `github.event.ref` works.
- id: slug
uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/slug@v1
with:
branch: ${{ github.ref_name }}
Outputs: `slug`, `port`.
### Cleanup ### Cleanup
Stops the preview container and removes its Pangolin resource. Intended for `delete` branch events. Stops the preview container and removes its Pangolin resource. Intended for `delete` branch events — the slug is derived from the branch name internally.
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/cleanup@v1 - uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/cleanup@v1
with: with:
app-name: my-app app-name: my-app
slug: ${{ steps.slug.outputs.slug }} branch: ${{ github.event.ref }}
## Roadmap ## Roadmap

View File

@@ -1,27 +1,41 @@
name: Cleanup Preview name: Cleanup Preview
description: Stop container and remove Pangolin resource description: Stop container and remove Pangolin resource for a deleted branch
inputs: inputs:
app-name: app-name:
required: true required: true
description: Application name (used for image/container naming) description: Application name (used for image/container naming)
slug: branch:
required: true required: true
description: Branch slug to clean up description: Branch name being cleaned up
runs: runs:
using: composite using: composite
steps: steps:
- name: Derive cleanup parameters
id: derive
shell: bash
env:
BRANCH: ${{ inputs.branch }}
run: |
BRANCH="${BRANCH#refs/heads/}"
SLUG=$(echo "$BRANCH" | tr '/_' '--' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | cut -c1-40)
REPO_SLUG="${GITHUB_REPOSITORY//\//-}"
{
echo "slug=$SLUG"
echo "resource-name=${REPO_SLUG}-${SLUG}"
} >> "$GITHUB_OUTPUT"
- name: Remove Pangolin resource - name: Remove Pangolin resource
shell: bash shell: bash
run: | run: |
bash ${{ github.action_path }}/pangolin-delete.sh \ bash ${{ github.action_path }}/pangolin-delete.sh \
--resource-name "${{ inputs.app-name }}-${{ inputs.slug }}" --resource-name "${{ steps.derive.outputs.resource-name }}"
- name: Stop preview container - name: Stop preview container
shell: bash shell: bash
run: | run: |
CONTAINER="${{ inputs.app-name }}-${{ inputs.slug }}" CONTAINER="${{ inputs.app-name }}-${{ steps.derive.outputs.slug }}"
docker stop "$CONTAINER" 2>/dev/null || true docker stop "$CONTAINER" 2>/dev/null || true
docker rm "$CONTAINER" 2>/dev/null || true docker rm "$CONTAINER" 2>/dev/null || true
docker rmi "${{ inputs.app-name }}:${{ inputs.slug }}" 2>/dev/null || true docker rmi "${{ inputs.app-name }}:${{ steps.derive.outputs.slug }}" 2>/dev/null || true

View File

@@ -5,22 +5,13 @@ inputs:
app-name: app-name:
required: true required: true
description: Application name (used for image/container naming) description: Application name (used for image/container naming)
tag: branch:
required: true required: true
description: Image/container tag (e.g., "production" or a branch slug) description: Branch name; the repo's default branch deploys as production, everything else as a preview
port:
required: true
description: Host port to expose
internal-port: internal-port:
required: false required: false
default: "3000" default: "3000"
description: Port the app listens on inside the container description: Port the app listens on inside the container
environment:
required: true
description: Environment name ("production" or "preview")
subdomain:
required: true
description: Subdomain for Pangolin resource
build-args: build-args:
required: false required: false
default: "" default: ""
@@ -29,16 +20,50 @@ inputs:
runs: runs:
using: composite using: composite
steps: steps:
- name: Derive deploy parameters
id: derive
shell: bash
env:
APP_NAME: ${{ inputs.app-name }}
BRANCH: ${{ inputs.branch }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
BRANCH="${BRANCH#refs/heads/}"
DEFAULT_BRANCH="${DEFAULT_BRANCH:-main}"
if [[ "$BRANCH" == "$DEFAULT_BRANCH" ]]; then
TAG="production"
ENVIRONMENT="production"
SUBDOMAIN="$APP_NAME"
PORT=$(( 10000 + ( $(echo -n "${APP_NAME}-production" | cksum | awk '{print $1}') % 10000 ) ))
else
SLUG=$(echo "$BRANCH" | tr '/_' '--' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | cut -c1-40)
TAG="$SLUG"
ENVIRONMENT="preview"
SUBDOMAIN="${SLUG}.${APP_NAME}"
PORT=$(( 20000 + ( $(echo -n "$SLUG" | cksum | awk '{print $1}') % 10000 ) ))
fi
REPO_SLUG="${GITHUB_REPOSITORY//\//-}"
{
echo "tag=$TAG"
echo "environment=$ENVIRONMENT"
echo "subdomain=$SUBDOMAIN"
echo "port=$PORT"
echo "resource-name=${REPO_SLUG}-${TAG}"
} >> "$GITHUB_OUTPUT"
- name: Build Docker image - name: Build Docker image
shell: bash shell: bash
run: | run: |
BUILD_ARGS="--build-arg APP_ENV=${{ inputs.environment }}" BUILD_ARGS="--build-arg APP_ENV=${{ steps.derive.outputs.environment }}"
for arg in ${{ inputs.build-args }}; do for arg in ${{ inputs.build-args }}; do
BUILD_ARGS="$BUILD_ARGS --build-arg $arg" BUILD_ARGS="$BUILD_ARGS --build-arg $arg"
done done
docker build \ docker build \
$BUILD_ARGS \ $BUILD_ARGS \
-t ${{ inputs.app-name }}:${{ inputs.tag }} \ -t ${{ inputs.app-name }}:${{ steps.derive.outputs.tag }} \
-f dockerfile . -f dockerfile .
- name: Deploy container - name: Deploy container
@@ -46,17 +71,16 @@ runs:
run: | run: |
bash ${{ github.action_path }}/deploy.sh \ bash ${{ github.action_path }}/deploy.sh \
--name "${{ inputs.app-name }}" \ --name "${{ inputs.app-name }}" \
--tag "${{ inputs.tag }}" \ --tag "${{ steps.derive.outputs.tag }}" \
--port "${{ inputs.port }}" \ --port "${{ steps.derive.outputs.port }}" \
--internal-port "${{ inputs.internal-port }}" \ --internal-port "${{ inputs.internal-port }}" \
--env "${{ inputs.environment }}" --env "${{ steps.derive.outputs.environment }}"
- name: Register Pangolin resource - name: Register Pangolin resource
shell: bash shell: bash
run: | run: |
REPO_SLUG="${GITHUB_REPOSITORY//\//-}"
bash ${{ github.action_path }}/pangolin-upsert.sh \ bash ${{ github.action_path }}/pangolin-upsert.sh \
--subdomain "${{ inputs.subdomain }}" \ --subdomain "${{ steps.derive.outputs.subdomain }}" \
--port "${{ inputs.port }}" \ --port "${{ steps.derive.outputs.port }}" \
--resource-name "${REPO_SLUG}-${{ inputs.tag }}" \ --resource-name "${{ steps.derive.outputs.resource-name }}" \
--target-ip "$PANGOLIN_TARGET_IP" --target-ip "$PANGOLIN_TARGET_IP"

View File

@@ -2,7 +2,7 @@ name: Deploy
on: on:
push: push:
branches: ["main", "**"] branches: ["**"]
delete: delete:
env: env:
@@ -14,8 +14,8 @@ env:
PANGOLIN_TARGET_IP: ${{ secrets.PANGOLIN_TARGET_IP }} PANGOLIN_TARGET_IP: ${{ secrets.PANGOLIN_TARGET_IP }}
jobs: jobs:
deploy-production: deploy:
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'push'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -23,43 +23,12 @@ jobs:
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/deploy@v1 - uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/deploy@v1
with: with:
app-name: ${{ vars.APP_NAME }} app-name: ${{ vars.APP_NAME }}
tag: production
port: ${{ vars.PROD_PORT }}
internal-port: ${{ vars.INTERNAL_PORT }}
environment: production
subdomain: ${{ vars.PROD_SUBDOMAIN }}
deploy-preview:
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compute preview slug
id: slug
uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/slug@v1
with:
branch: ${{ github.ref_name }} branch: ${{ github.ref_name }}
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/deploy@v1
with:
app-name: ${{ vars.APP_NAME }}
tag: ${{ steps.slug.outputs.slug }}
port: ${{ steps.slug.outputs.port }}
internal-port: ${{ vars.INTERNAL_PORT }}
environment: preview
subdomain: ${{ steps.slug.outputs.slug }}.${{ vars.APP_NAME }}
cleanup-preview: cleanup-preview:
if: github.event_name == 'delete' && github.event.ref_type == 'branch' if: github.event_name == 'delete' && github.event.ref_type == 'branch'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Compute preview slug
id: slug
uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/slug@v1
with:
branch: ${{ github.event.ref }}
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: main ref: main
@@ -67,4 +36,4 @@ jobs:
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/cleanup@v1 - uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/cleanup@v1
with: with:
app-name: ${{ vars.APP_NAME }} app-name: ${{ vars.APP_NAME }}
slug: ${{ steps.slug.outputs.slug }} branch: ${{ github.event.ref }}

View File

@@ -1,29 +0,0 @@
name: Compute Preview Slug
description: Derive a URL-safe slug and deterministic port from a branch name
inputs:
branch:
required: true
description: Branch name to slugify
outputs:
slug:
description: URL-safe branch slug
value: ${{ steps.compute.outputs.slug }}
port:
description: Deterministic port derived from the slug
value: ${{ steps.compute.outputs.port }}
runs:
using: composite
steps:
- name: Compute slug and port
id: compute
shell: bash
run: |
BRANCH="${{ inputs.branch }}"
BRANCH="${BRANCH#refs/heads/}"
SLUG=$(echo "$BRANCH" | tr '/' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | cut -c1-40)
echo "slug=$SLUG" >> "$GITHUB_OUTPUT"
PORT=$(( 20000 + ( $(echo -n "$SLUG" | cksum | awk '{print $1}') % 10000 ) ))
echo "port=$PORT" >> "$GITHUB_OUTPUT"