MQL5-Google-Onedrive/.github/workflows/ci-cd-docker-dev.yml
google-labs-jules[bot] 57ef1597f7 fix(ci): use dynamic docker tag in build workflow
Fixes the CI build failure by dynamically sourcing the Docker image tag from the metadata action's output in the test and deploy steps.

The previous workflow hardcoded a tag using the full-length commit SHA, which caused a mismatch with the short-SHA tag generated by the build step, resulting in a "manifest unknown" error. This change ensures the correct tag is used throughout the CI pipeline.

Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
2026-01-29 17:14:40 +00:00

157 lines
4.6 KiB
YAML

name: CI/CD - Docker Dev Deployment
on:
push:
branches: [ main, develop ]
paths:
- 'Dockerfile.dev'
- 'docker-compose.dev.yml'
- 'scripts/**'
- '.github/workflows/ci-cd-docker-dev.yml'
pull_request:
branches: [ main, develop ]
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'dev'
type: choice
options:
- dev
- cloud
env:
REGISTRY: ghcr.io
IMAGE_NAME: a6-9v/mql5-google-onedrive
jobs:
build-and-test:
name: Build and Test Docker Dev Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
dev_tag_line: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=dev-
- name: Build Docker Dev image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.dev
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Run tests in container
run: |
DEV_TAG=$(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | grep 'dev-' | head -n 1)
docker run --rm $DEV_TAG \
python -c "import sys; print('Python:', sys.version); sys.exit(0)"
- name: Image digest
run: echo ${{ steps.meta.outputs.digest }}
deploy-dev:
name: Deploy Dev Environment
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' || github.event_name == 'workflow_dispatch'
environment:
name: dev
url: https://mql5-automation-dev.example.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull latest dev image
run: |
DEV_TAG=$(echo "${{ needs.build-and-test.outputs.dev_tag_line }}" | tr ',' '\n' | grep 'dev-' | head -n 1)
docker pull $DEV_TAG || \
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop || \
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main
- name: Deploy to Docker Desktop (Local)
if: runner.os == 'Windows'
run: |
echo "Deploying to Docker Desktop..."
docker-compose -f docker-compose.dev.yml up -d
docker ps
- name: Deploy notification
uses: 8398a7/action-slack@v3
if: always()
with:
status: ${{ job.status }}
text: 'Deployment to dev environment completed'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
deploy-cloud:
name: Deploy to Cloud Platform
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'cloud')
environment:
name: production
url: https://mql5-automation.fly.dev
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Fly.io
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy to Fly.io
run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Deploy to Render (if configured)
if: false # Enable when Render is configured
run: |
echo "Render deployment would happen here"
# Render auto-deploys from GitHub integration