Skip to content

[EVOL]: CI/CD using env variables #36

[EVOL]: CI/CD using env variables

[EVOL]: CI/CD using env variables #36

name: Docker Compose Deploy
on:
push:
branches: ["main"]
release:
types: ["created"]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
env:
REGISTRY: ghcr.io
PSQL_DB_HOST: ${{ secrets.PSQL_DB_HOST }}
PSQL_DB_NAME: ${{ secrets.PSQL_DB_NAME }}
PSQL_DB_USER: ${{ secrets.PSQL_DB_USER }}
PSQL_DB_PASSWORD: ${{ secrets.PSQL_DB_PASSWORD }}
PSQL_DB_PORT: ${{ secrets.PSQL_DB_PORT }}
GITLAB_PRIVATE_TOKEN: ${{ secrets.GITLAB_PRIVATE_TOKEN }}
GITHUB_PRIVATE_TOKEN: ${{ secrets.GITHUB_PRIVATE_TOKEN }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
V6Y_STATIC_ANALYZER_API_PATH: ${{ secrets.V6Y_STATIC_ANALYZER_API_PATH }}
V6Y_STATIC_ANALYZER_API_PORT: ${{ secrets.V6Y_STATIC_ANALYZER_API_PORT }}
V6Y_DEVOPS_API_PATH: ${{ secrets.V6Y_DEVOPS_API_PATH }}
V6Y_DEVOPS_API_PORT: ${{ secrets.V6Y_DEVOPS_API_PORT }}
V6Y_DYNAMIC_ANALYZER_API_PATH: ${{ secrets.V6Y_DYNAMIC_ANALYZER_API_PATH }}
V6Y_DYNAMIC_ANALYZER_API_PORT: ${{ secrets.V6Y_DYNAMIC_ANALYZER_API_PORT }}
V6Y_MAIN_API_PATH: ${{ secrets.V6Y_MAIN_API_PATH }}
V6Y_MAIN_API_PORT: ${{ secrets.V6Y_MAIN_API_PORT }}
V6Y_BFF_API_PATH: ${{ secrets.V6Y_BFF_API_PATH }}
V6Y_BFF_API_PORT: ${{ secrets.V6Y_BFF_API_PORT }}
NEXT_PUBLIC_V6Y_BFF_PATH: ${{ secrets.NEXT_PUBLIC_V6Y_BFF_PATH }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Docker
run: |
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
docker --version
- name: Install Docker Compose
run: |
DOCKER_COMPOSE_VERSION=$(curl -s "https://api.github.com/repos/docker/compose/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
sudo curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Determine Image Tag
id: set-tag
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
echo "IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "release" ]]; then
echo "IMAGE_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
fi
shell: bash
- name: Log into Docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Update docker-compose.yml with dynamic image names
run: |
sed -i "s|<registry-owner>|${{ github.repository_owner }}|g" docker-compose.yml
sed -i "s|:latest|:${{ env.IMAGE_TAG }}|g" docker-compose.yml
- name: Validate Docker Compose Configuration
run: docker-compose -f docker-compose.yml config
- name: Build and push images using Docker Compose
run: |
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml push
- name: Deploy services using Docker Compose
if: github.event_name == 'push' || github.event_name == 'release'
run: |
docker-compose -f docker-compose.yml pull
docker-compose -f docker-compose.yml up -d