forked from LengKundee/MQL5-Google-Onedrive
153 lines
4.4 KiB
YAML
153 lines
4.4 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: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-test:
|
|
name: Build and Test Docker Dev Image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
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: |
|
|
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ github.sha }} \
|
|
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: |
|
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ github.sha }} || \
|
|
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
|