fix(deploy): correct env vars, docker compose project names, and workflow outputs
- Standardize environment variable from IS_PROD to PROD across all scripts - Add missing -p flag to docker compose commands for consistent project naming - Fix GitHub Actions workflow to use environment vars instead of job outputs - Consolidate metadata setup and fix artifact naming in build/deploy jobs - Correct service paths in docker-compose_core.yml
This commit is contained in:
parent
f20c4f9474
commit
291231c886
9 changed files with 104 additions and 70 deletions
82
.github/workflows/build_deploy.yml
vendored
82
.github/workflows/build_deploy.yml
vendored
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
repo-path: ${{ steps.meta.outputs.REPO_PROJECT_PATH }}
|
||||
image-tar: ${{ steps.meta.outputs.REPO_NAME_ONLY }}-${{ github.ref_name }}_${{ github.sha }}.tar
|
||||
tags: ${{ steps.generated_docker_tags.outputs.tag }}
|
||||
prod: ${{ steps.env.outputs.prod }}
|
||||
prod: ${{ steps.meta.outputs.prod }}
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v4
|
||||
|
|
@ -25,26 +25,20 @@ jobs:
|
|||
- name: Ensure scripts are executable
|
||||
run: chmod +x scripts/*.sh
|
||||
|
||||
- name: Get full and partial repository name
|
||||
- name: Setup build metadata and environment
|
||||
id: meta
|
||||
run: |
|
||||
echo "✅ Exit script on any error"
|
||||
set -eu -o pipefail
|
||||
|
||||
# Parse repository name and set outputs
|
||||
eval "$(./scripts/parse-repository-name.sh '${{ github.repository }}')"
|
||||
echo "REPO=$REPO" >> $GITHUB_OUTPUT
|
||||
echo "REPO_NAME_ONLY=$REPO_NAME_ONLY" >> $GITHUB_OUTPUT
|
||||
echo "REPO_PROJECT_PATH=$REPO_PROJECT_PATH" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Set PROD environment variable
|
||||
id: env
|
||||
run: |
|
||||
echo "✅ Exit script on any error"
|
||||
set -eu -o pipefail
|
||||
|
||||
# Determine PROD environment
|
||||
prod_value=""
|
||||
|
||||
echo "🔍 Check if PROD is set via vars; if not, determine from github.ref"
|
||||
if [ -z "${{ vars.PROD }}" ]; then
|
||||
prod_value="${{ startsWith(github.ref, 'refs/tags/v') && !endsWith(github.ref, '-prerelease') }}"
|
||||
|
|
@ -53,12 +47,18 @@ jobs:
|
|||
prod_value="${{ vars.PROD }}"
|
||||
echo "📦 PROD mode already set to: ${prod_value}"
|
||||
fi
|
||||
|
||||
echo "prod=${prod_value}" >> $GITHUB_OUTPUT
|
||||
|
||||
# Set environment variables for subsequent steps
|
||||
echo "🖊️ Writing determined values to GITHUB_ENV:"
|
||||
echo "PROD=${prod_value}" >> $GITHUB_ENV
|
||||
echo "PROD=${prod_value} -> GITHUB_ENV"
|
||||
echo "prod=${prod_value}" >> $GITHUB_OUTPUT
|
||||
echo "IMAGE_TAR_NAME=${REPO_NAME_ONLY}-${{ github.ref_name }}_${{ github.sha }}.tar" >> $GITHUB_ENV
|
||||
echo "IMAGE_TAR_NAME=${REPO_NAME_ONLY}-${{ github.ref_name }}_${{ github.sha }}.tar -> GITHUB_ENV"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Generate tags
|
||||
id: generated_docker_tags
|
||||
run: |
|
||||
|
|
@ -126,7 +126,7 @@ jobs:
|
|||
- name: Upload container as artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: docker-image
|
||||
name: ${{ env.IMAGE_TAR_NAME }}
|
||||
path: ${{ runner.temp }}/${{ steps.meta.outputs.REPO_NAME_ONLY }}-${{ github.ref_name }}_${{ github.sha }}.tar
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
|
@ -136,7 +136,8 @@ jobs:
|
|||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
|
||||
environment: ${{ needs.build.outputs.prod == 'true' && 'production' || 'staging' }}
|
||||
# Determine environment based on ref
|
||||
environment: ${{ (startsWith(github.ref, 'refs/tags/v') && !endsWith(github.ref, '-prerelease')) && 'production' || 'staging' }}
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v4
|
||||
|
|
@ -144,12 +145,45 @@ jobs:
|
|||
- name: Ensure scripts are executable
|
||||
run: chmod +x scripts/*.sh
|
||||
|
||||
- name: Setup deployment metadata and environment
|
||||
id: meta
|
||||
run: |
|
||||
echo "✅ Exit script on any error"
|
||||
set -eu -o pipefail
|
||||
|
||||
# Parse repository name and set outputs
|
||||
eval "$(./scripts/parse-repository-name.sh '${{ github.repository }}')"
|
||||
echo "REPO=$REPO" >> $GITHUB_OUTPUT
|
||||
echo "REPO_NAME_ONLY=$REPO_NAME_ONLY" >> $GITHUB_OUTPUT
|
||||
echo "REPO_PROJECT_PATH=$REPO_PROJECT_PATH" >> $GITHUB_OUTPUT
|
||||
|
||||
# Determine PROD environment
|
||||
prod_value=""
|
||||
echo "🔍 Check if PROD is set via vars; if not, determine from github.ref"
|
||||
if [ -z "${{ vars.PROD }}" ]; then
|
||||
prod_value="${{ startsWith(github.ref, 'refs/tags/v') && !endsWith(github.ref, '-prerelease') }}"
|
||||
echo "📦 PROD mode unset, determined from github.ref (starts with v and does not end with -prerelease?): ${prod_value}"
|
||||
else
|
||||
prod_value="${{ vars.PROD }}"
|
||||
echo "📦 PROD mode already set to: ${prod_value}"
|
||||
fi
|
||||
echo "prod=${prod_value}" >> $GITHUB_OUTPUT
|
||||
|
||||
# Set all deployment environment variables
|
||||
echo "📝 Setting deployment environment variables"
|
||||
echo "REPO_PROJECT_PATH=${REPO_PROJECT_PATH}" >> $GITHUB_ENV
|
||||
echo "REPO_NAME_ONLY=${REPO_NAME_ONLY}" >> $GITHUB_ENV
|
||||
echo "IMAGE_TAR_NAME=${REPO_NAME_ONLY}-${{ github.ref_name }}_${{ github.sha }}.tar" >> $GITHUB_ENV
|
||||
echo "PROD=${prod_value}" >> $GITHUB_ENV
|
||||
|
||||
- name: Download container artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: docker-image
|
||||
name: ${{ env.IMAGE_TAR_NAME }}
|
||||
path: ${{ runner.temp }}
|
||||
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
fail-on-missing: true
|
||||
|
||||
- name: Get Deploy Secrets
|
||||
uses: bitwarden/sm-action@v2
|
||||
with:
|
||||
|
|
@ -184,10 +218,10 @@ jobs:
|
|||
- name: Deploy to Server
|
||||
env:
|
||||
DOCKER_HOST: ssh://deploy
|
||||
REPO_PROJECT_PATH: ${{ needs.build.outputs.repo-path }}
|
||||
REPO_NAME_ONLY: ${{ needs.build.outputs.repo-name }}
|
||||
IMAGE_TAR: ${{ runner.temp }}/${{ needs.build.outputs.image-tar }}
|
||||
IS_PROD: ${{ needs.build.outputs.prod }}
|
||||
REPO_PROJECT_PATH: ${{ env.REPO_PROJECT_PATH }}
|
||||
REPO_NAME_ONLY: ${{ env.REPO_NAME_ONLY }}
|
||||
IMAGE_TAR: ${{ runner.temp }}/${{ env.IMAGE_TAR_NAME }}
|
||||
PROD: ${{ env.PROD }}
|
||||
run: |
|
||||
echo "✅ Exit script on any error"
|
||||
set -eu -o pipefail
|
||||
|
|
@ -196,7 +230,7 @@ jobs:
|
|||
- name: Health Check and Rollback
|
||||
run: |
|
||||
# Determine the correct URL based on environment
|
||||
if [ "${{ needs.build.outputs.prod }}" = "true" ]; then
|
||||
if [ "${{ env.PROD }}" = "true" ]; then
|
||||
# Ensure PRODUCTION_DOMAIN is set
|
||||
if [ -z "${{ vars.PRODUCTION_DOMAIN }}" ]; then
|
||||
echo "Error: PRODUCTION_DOMAIN is not set"
|
||||
|
|
@ -215,5 +249,5 @@ jobs:
|
|||
# Copy script to remote and execute
|
||||
scp scripts/health-check-and-rollback.sh deploy:/tmp/
|
||||
ssh deploy "chmod +x /tmp/health-check-and-rollback.sh"
|
||||
ssh deploy "/tmp/health-check-and-rollback.sh '${{ needs.build.outputs.repo-path }}' '${{ needs.build.outputs.prod }}' '$HEALTH_CHECK_URL' 30"
|
||||
ssh deploy "/tmp/health-check-and-rollback.sh '${{ env.REPO_PROJECT_PATH }}' '${{ env.PROD }}' '$HEALTH_CHECK_URL' 30"
|
||||
ssh deploy "rm -f /tmp/health-check-and-rollback.sh"
|
||||
Loading…
Add table
Add a link
Reference in a new issue