Skip to content

Build and Push

Build and Push #2

Workflow file for this run

name: Build and Push Frontend & Backend
on:
workflow_dispatch:
push:
branches-ignore:
- gh-pages
paths:
- 'src/**'
- 'charts/**'
pull_request:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase owner name
id: repo
run: |
echo "owner_lower=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Determine tag(s) from branch or Chart.yaml
id: vars
run: |
BRANCH="${GITHUB_REF#refs/heads/}"
OWNER_LOWER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')
# Get the first chart directory name under charts/
CHART_NAME=$(basename $(find ./charts -mindepth 1 -maxdepth 1 -type d | head -n 1))
if [ "$BRANCH" = "main" ]; then
VERSION=$(awk -F': ' '/^appVersion:/ { gsub(/"/, "", $2); print $2 }' "./charts/$CHART_NAME/Chart.yaml")
echo "Main branch detected. Using chart version: $VERSION and 'latest'"
TAGS="ghcr.io/${OWNER_LOWER}/${CHART_NAME}:$VERSION\nghcr.io/${OWNER_LOWER}/${CHART_NAME}:latest"
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo -e "$TAGS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
VERSION=$(echo "$BRANCH" | sed 's#/#-#g')
echo "Non-main branch detected. Using branch name as tag: $VERSION"
echo "tags=ghcr.io/${OWNER_LOWER}/${CHART_NAME}:$VERSION" >> $GITHUB_OUTPUT
fi
echo "chart_name=$CHART_NAME" >> $GITHUB_OUTPUT
- name: Debug Tags
run: |
echo "Frontend Tags:"
echo "${{ steps.vars.outputs.frontend_tags }}"
echo "Backend Tags:"
echo "${{ steps.vars.outputs.backend_tags }}"
- name: Build and Push Image
uses: docker/build-push-action@v5
with:
context: ./src/
file: ./src/Dockerfile
push: true
platforms: linux/amd64
tags: ${{ steps.vars.outputs.frontend_tags }}