ci-actions/deploy-site/action.yaml

71 lines
2.1 KiB
YAML

name: Deploy Site
description: Deploy static site via S3 and Nomad dispatch
inputs:
site-name:
description: 'Site identifier (used as service name in Nomad)'
required: true
traefik-rule:
description: 'Traefik routing rule (e.g., Host(`example.com`) or Host(`example.com`) || Host(`www.example.com`))'
required: true
source-dir:
description: 'Directory containing built site'
required: false
default: '.'
s3-endpoint:
description: 'S3 endpoint'
required: false
default: 'https://s3.toph.so'
runs:
using: composite
steps:
- name: Install AWS CLI
shell: bash
run: |
if ! command -v aws &> /dev/null; then
curl -sL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
unzip -q /tmp/awscliv2.zip -d /tmp
sudo /tmp/aws/install
fi
- name: Package and upload to S3
shell: bash
run: |
cd "${{ inputs.source-dir }}"
ARTIFACT_NAME="${{ github.sha }}.tar.gz"
tar czf "/tmp/${ARTIFACT_NAME}" .
# Configure AWS CLI for S3
export AWS_ACCESS_KEY_ID="${{ env.S3_ACCESS_KEY }}"
export AWS_SECRET_ACCESS_KEY="${{ env.S3_SECRET_KEY }}"
export AWS_ENDPOINT_URL="${{ inputs.s3-endpoint }}"
export AWS_EC2_METADATA_DISABLED=true
# Upload to S3
aws s3 cp "/tmp/${ARTIFACT_NAME}" "s3://artifacts/${ARTIFACT_NAME}"
# Make publicly readable
aws s3api put-object-acl \
--bucket artifacts \
--key "${ARTIFACT_NAME}" \
--acl public-read
echo "📦 Artifact uploaded: ${{ inputs.s3-endpoint }}/artifacts/${ARTIFACT_NAME}"
- name: Deploy via Nomad
shell: bash
run: |
nomad job dispatch static-site \
-meta site_name=${{ inputs.site-name }} \
-meta traefik_rule="${{ inputs.traefik-rule }}" \
-meta artifact_url=${{ inputs.s3-endpoint }}/artifacts/${{ github.sha }}.tar.gz
- name: Deployment summary
shell: bash
run: |
echo "✅ Deployed ${{ inputs.site-name }}"
echo "📋 Traefik rule: ${{ inputs.traefik-rule }}"