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

@@ -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"