started the admin panel branch #21
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: Publish Images | |
on: | |
push: | |
branches: | |
- '*' | |
tags: | |
- 'v*' | |
env: | |
BACKEND_IMAGE: newsletter-k8s_backend | |
FRONTEND_IMAGE: newsletter-k8s_frontend | |
jobs: | |
push: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Build and push images | |
run: | | |
for dir in backend frontend; do | |
IMAGE_NAME_VAR="${dir^^}_IMAGE" # Convert directory name to uppercase for env var | |
IMAGE_NAME=${!IMAGE_NAME_VAR} # Get the corresponding image name from env | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | |
echo "Building and pushing $IMAGE_ID..." | |
# Build the Docker image | |
docker build ./$dir --file ./$dir/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | |
# Prepare version tags | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') # Ensure lowercase | |
VERSION=latest | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo ${{ github.ref_name }} | sed -e 's/^v//') | |
[ "${{ github.ref_name }}" == "main" ] && VERSION=latest | |
# Tag and push the image | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
done |