mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 20:41:09 +02:00
fix(ci): pass version tags to docker-compose via .env file
The CD workflow was pulling the correct versioned image but docker-compose was using the default 'latest' tag because version variables weren't being set. Now the workflow: 1. Computes the correct version variable name (e.g., TODO_WEB_VERSION) 2. Updates the .env file on the staging server with the version 3. docker-compose reads from .env and uses the correct image tag 4. Verifies the correct image is running after deployment This fixes deployments where the container would keep running an old image even after a new version was pushed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7f7b8b6db0
commit
c96820daf7
1 changed files with 39 additions and 2 deletions
41
.github/workflows/cd-staging-tagged.yml
vendored
41
.github/workflows/cd-staging-tagged.yml
vendored
|
|
@ -316,21 +316,54 @@ jobs:
|
||||||
env:
|
env:
|
||||||
VERSION: ${{ needs.parse-deployment.outputs.version }}
|
VERSION: ${{ needs.parse-deployment.outputs.version }}
|
||||||
IMAGE_NAME: ${{ matrix.image_name }}
|
IMAGE_NAME: ${{ matrix.image_name }}
|
||||||
|
APP_TYPE: ${{ matrix.app }}
|
||||||
|
PROJECT: ${{ needs.parse-deployment.outputs.project }}
|
||||||
run: |
|
run: |
|
||||||
|
# Compute the version variable name locally (before SSH)
|
||||||
|
# Map: todo-web -> TODO_WEB_VERSION, chat-backend -> CHAT_VERSION
|
||||||
|
case "$IMAGE_NAME" in
|
||||||
|
*-web)
|
||||||
|
PROJECT_UPPER=$(echo "$PROJECT" | tr '[:lower:]-' '[:upper:]_')
|
||||||
|
VERSION_VAR="${PROJECT_UPPER}_WEB_VERSION"
|
||||||
|
;;
|
||||||
|
*-backend)
|
||||||
|
PROJECT_UPPER=$(echo "$PROJECT" | tr '[:lower:]-' '[:upper:]_')
|
||||||
|
VERSION_VAR="${PROJECT_UPPER}_VERSION"
|
||||||
|
;;
|
||||||
|
mana-core-auth)
|
||||||
|
VERSION_VAR="AUTH_VERSION"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
VERSION_VAR=$(echo "$IMAGE_NAME" | tr '[:lower:]-' '[:upper:]_')_VERSION
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "Will set $VERSION_VAR=$VERSION for docker-compose"
|
||||||
|
|
||||||
ssh ${{ secrets.STAGING_USER }}@${{ secrets.STAGING_HOST }} << EOF
|
ssh ${{ secrets.STAGING_USER }}@${{ secrets.STAGING_HOST }} << EOF
|
||||||
cd ~/manacore-staging
|
cd ~/manacore-staging
|
||||||
|
|
||||||
echo "Deploying $IMAGE_NAME:$VERSION to staging..."
|
echo "Deploying $IMAGE_NAME:$VERSION to staging..."
|
||||||
|
|
||||||
# Pull the new image
|
# Pull the new image with specific version tag
|
||||||
docker pull ${{ env.IMAGE_PREFIX }}/$IMAGE_NAME:$VERSION
|
docker pull ${{ env.IMAGE_PREFIX }}/$IMAGE_NAME:$VERSION
|
||||||
|
|
||||||
|
# Update .env file with the version for this service
|
||||||
|
# This ensures docker-compose uses the correct image tag
|
||||||
|
if grep -q "^$VERSION_VAR=" .env 2>/dev/null; then
|
||||||
|
sed -i "s/^$VERSION_VAR=.*/$VERSION_VAR=$VERSION/" .env
|
||||||
|
else
|
||||||
|
echo "$VERSION_VAR=$VERSION" >> .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Updated .env: $VERSION_VAR=$VERSION"
|
||||||
|
grep "$VERSION_VAR" .env || true
|
||||||
|
|
||||||
# Service name matches docker-compose service name (with hyphens)
|
# Service name matches docker-compose service name (with hyphens)
|
||||||
SERVICE_NAME="$IMAGE_NAME"
|
SERVICE_NAME="$IMAGE_NAME"
|
||||||
|
|
||||||
if docker compose ps -a | grep -q "$IMAGE_NAME"; then
|
if docker compose ps -a | grep -q "$IMAGE_NAME"; then
|
||||||
echo "Updating existing service: \$SERVICE_NAME"
|
echo "Updating existing service: \$SERVICE_NAME"
|
||||||
docker compose pull \$SERVICE_NAME || true
|
|
||||||
docker compose up -d --no-deps --force-recreate \$SERVICE_NAME
|
docker compose up -d --no-deps --force-recreate \$SERVICE_NAME
|
||||||
else
|
else
|
||||||
echo "Service \$SERVICE_NAME not found in compose, starting..."
|
echo "Service \$SERVICE_NAME not found in compose, starting..."
|
||||||
|
|
@ -341,6 +374,10 @@ jobs:
|
||||||
sleep 10
|
sleep 10
|
||||||
docker compose ps \$SERVICE_NAME
|
docker compose ps \$SERVICE_NAME
|
||||||
|
|
||||||
|
# Verify correct image is running
|
||||||
|
echo "Running image:"
|
||||||
|
docker inspect --format='{{.Config.Image}}' ${IMAGE_NAME}-staging 2>/dev/null || true
|
||||||
|
|
||||||
# Cleanup old images
|
# Cleanup old images
|
||||||
docker image prune -f
|
docker image prune -f
|
||||||
EOF
|
EOF
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue