Files
node-deploy-action/deploy/action.yml
2026-05-21 20:25:33 -05:00

87 lines
2.9 KiB
YAML

name: Deploy Container
description: Build Docker image, deploy container, and register with Pangolin
inputs:
app-name:
required: true
description: Application name (used for image/container naming)
branch:
required: true
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
build-args:
required: false
default: ""
description: Extra docker build args (space-separated KEY=VALUE pairs)
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=${{ 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 }}:${{ steps.derive.outputs.tag }} \
-f dockerfile .
- name: Deploy container
shell: bash
run: |
bash ${{ github.action_path }}/deploy.sh \
--name "${{ inputs.app-name }}" \
--tag "${{ steps.derive.outputs.tag }}" \
--port "${{ steps.derive.outputs.port }}" \
--internal-port "${{ inputs.internal-port }}" \
--env "${{ steps.derive.outputs.environment }}"
- name: Register Pangolin resource
shell: bash
run: |
bash ${{ github.action_path }}/pangolin-upsert.sh \
--subdomain "${{ steps.derive.outputs.subdomain }}" \
--port "${{ steps.derive.outputs.port }}" \
--resource-name "${{ steps.derive.outputs.resource-name }}" \
--target-ip "$PANGOLIN_TARGET_IP"