Reduced input variables
This commit is contained in:
41
README.md
41
README.md
@@ -11,7 +11,6 @@ Table of Contents
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Deploy](#deploy)
|
||||
- [Slug](#slug)
|
||||
- [Cleanup](#cleanup)
|
||||
- [Roadmap](#roadmap)
|
||||
|
||||
@@ -72,65 +71,39 @@ See `examples/deploy.yml` for a complete workflow covering production, preview,
|
||||
|
||||
### 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
|
||||
with:
|
||||
app-name: my-app
|
||||
tag: production
|
||||
port: "3001"
|
||||
environment: production
|
||||
subdomain: my-app
|
||||
branch: ${{ github.ref_name }}
|
||||
|
||||
Inputs
|
||||
|
||||
`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)
|
||||
|
||||
`port`
|
||||
|
||||
Host port to expose
|
||||
Branch name. Matches against `github.event.repository.default_branch` to decide production vs. preview. `refs/heads/` prefix is stripped.
|
||||
|
||||
`internal-port`
|
||||
|
||||
Port the app listens on inside the container (default `3000`)
|
||||
|
||||
`environment`
|
||||
|
||||
`production` or `preview`
|
||||
|
||||
`subdomain`
|
||||
|
||||
Subdomain for the Pangolin resource
|
||||
|
||||
`build-args`
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
with:
|
||||
app-name: my-app
|
||||
slug: ${{ steps.slug.outputs.slug }}
|
||||
branch: ${{ github.event.ref }}
|
||||
|
||||
## Roadmap
|
||||
|
||||
|
||||
@@ -1,27 +1,41 @@
|
||||
name: Cleanup Preview
|
||||
description: Stop container and remove Pangolin resource
|
||||
description: Stop container and remove Pangolin resource for a deleted branch
|
||||
|
||||
inputs:
|
||||
app-name:
|
||||
required: true
|
||||
description: Application name (used for image/container naming)
|
||||
slug:
|
||||
branch:
|
||||
required: true
|
||||
description: Branch slug to clean up
|
||||
description: Branch name being cleaned up
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
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
|
||||
shell: bash
|
||||
run: |
|
||||
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
|
||||
shell: bash
|
||||
run: |
|
||||
CONTAINER="${{ inputs.app-name }}-${{ inputs.slug }}"
|
||||
CONTAINER="${{ inputs.app-name }}-${{ steps.derive.outputs.slug }}"
|
||||
docker stop "$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
|
||||
|
||||
@@ -5,22 +5,13 @@ inputs:
|
||||
app-name:
|
||||
required: true
|
||||
description: Application name (used for image/container naming)
|
||||
tag:
|
||||
branch:
|
||||
required: true
|
||||
description: Image/container tag (e.g., "production" or a branch slug)
|
||||
port:
|
||||
required: true
|
||||
description: Host port to expose
|
||||
description: Branch name; the repo's default branch deploys as production, everything else as a preview
|
||||
internal-port:
|
||||
required: false
|
||||
default: "3000"
|
||||
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:
|
||||
required: false
|
||||
default: ""
|
||||
@@ -29,16 +20,50 @@ inputs:
|
||||
runs:
|
||||
using: composite
|
||||
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
|
||||
shell: bash
|
||||
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
|
||||
BUILD_ARGS="$BUILD_ARGS --build-arg $arg"
|
||||
done
|
||||
docker build \
|
||||
$BUILD_ARGS \
|
||||
-t ${{ inputs.app-name }}:${{ inputs.tag }} \
|
||||
-t ${{ inputs.app-name }}:${{ steps.derive.outputs.tag }} \
|
||||
-f dockerfile .
|
||||
|
||||
- name: Deploy container
|
||||
@@ -46,17 +71,16 @@ runs:
|
||||
run: |
|
||||
bash ${{ github.action_path }}/deploy.sh \
|
||||
--name "${{ inputs.app-name }}" \
|
||||
--tag "${{ inputs.tag }}" \
|
||||
--port "${{ inputs.port }}" \
|
||||
--tag "${{ steps.derive.outputs.tag }}" \
|
||||
--port "${{ steps.derive.outputs.port }}" \
|
||||
--internal-port "${{ inputs.internal-port }}" \
|
||||
--env "${{ inputs.environment }}"
|
||||
--env "${{ steps.derive.outputs.environment }}"
|
||||
|
||||
- name: Register Pangolin resource
|
||||
shell: bash
|
||||
run: |
|
||||
REPO_SLUG="${GITHUB_REPOSITORY//\//-}"
|
||||
bash ${{ github.action_path }}/pangolin-upsert.sh \
|
||||
--subdomain "${{ inputs.subdomain }}" \
|
||||
--port "${{ inputs.port }}" \
|
||||
--resource-name "${REPO_SLUG}-${{ inputs.tag }}" \
|
||||
--subdomain "${{ steps.derive.outputs.subdomain }}" \
|
||||
--port "${{ steps.derive.outputs.port }}" \
|
||||
--resource-name "${{ steps.derive.outputs.resource-name }}" \
|
||||
--target-ip "$PANGOLIN_TARGET_IP"
|
||||
|
||||
@@ -2,7 +2,7 @@ name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main", "**"]
|
||||
branches: ["**"]
|
||||
delete:
|
||||
|
||||
env:
|
||||
@@ -14,8 +14,8 @@ env:
|
||||
PANGOLIN_TARGET_IP: ${{ secrets.PANGOLIN_TARGET_IP }}
|
||||
|
||||
jobs:
|
||||
deploy-production:
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
deploy:
|
||||
if: github.event_name == 'push'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -23,43 +23,12 @@ jobs:
|
||||
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/deploy@v1
|
||||
with:
|
||||
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 }}
|
||||
|
||||
- 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:
|
||||
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
|
||||
runs-on: ubuntu-latest
|
||||
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
|
||||
with:
|
||||
ref: main
|
||||
@@ -67,4 +36,4 @@ jobs:
|
||||
- uses: https://git.zyrrus.dev/eighty-six/node-deploy-action/cleanup@v1
|
||||
with:
|
||||
app-name: ${{ vars.APP_NAME }}
|
||||
slug: ${{ steps.slug.outputs.slug }}
|
||||
branch: ${{ github.event.ref }}
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user