wip #47
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
strategy: | |
matrix: | |
folders: | |
- infra/postgres | |
- infra/keycloak | |
- infra/nginx | |
- infra/promtail | |
- infra/loki | |
- infra/prometheus | |
- infra/grafana | |
- apps/api | |
- apps/ui | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Sets the folder and application names for the build | |
id: set-folder | |
run: | | |
echo "folder=$(dirname ${{ matrix.folders }})" >> $GITHUB_ENV | |
echo "app=$(basename ${{ matrix.folders }})" >> $GITHUB_ENV | |
- name: Check for changes in the directory | |
id: check-changes | |
run: | | |
git fetch origin | |
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} ${{ github.sha }} | grep "^${{ matrix.folders }}/" || true) | |
if [ -z "$CHANGED_FILES" ]; then | |
echo "No changes in ${{ matrix.folders }}. Skipping build." | |
echo "changes_in_directory=false" >> $GITHUB_ENV | |
else | |
echo "Changes detected in ${{ matrix.folders }}. Proceeding with build." | |
echo "changes_in_directory=true" >> $GITHUB_ENV | |
- name: Login to GitHub Container Registry | |
if: env.changes_in_directory == 'true' | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.REGISTRY_TOKEN }} | |
- name: Build and Push Docker Image | |
if: env.changes_in_directory == 'true' | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./${{ env.folder }}/${{ env.app }}/Dockerfile | |
push: true | |
tags: ghcr.io/neumanf/mally-${{ env.app }}:latest | |
deploy: | |
runs-on: self-hosted | |
needs: build | |
steps: | |
- name: Deploy | |
run: | | |
cd $HOME/mally && | |
docker compose -f docker-compose.stack.yml pull && | |
docker stack deploy -c docker-compose.stack.yml mally |