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: Push Docker image to GitHub Packages | |
# This workflow runs when any of the following occur: | |
# - A push is made to a branch called `main` or `seed` | |
# - A tag starting with "v" is created | |
on: | |
push: | |
branches: | |
- main | |
- seed | |
tags: | |
- v* | |
env: | |
PROJECT: example-project | |
jobs: | |
push: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
# need to repeat the build for following directories: | |
# - csp1_producer | |
# - csp1_consumer | |
# - csp1_transformer | |
# - csp2_producer | |
# - csp2_transformer | |
# - dashboard | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Build and push csp1_producer | |
run: | | |
cd csp1_producer | |
# todo: csp2_transformer | |
for DIR in csp1_producer csp1_consumer csp1_transformer csp2_producer dashboard ;do | |
IMAGE_NAME=$PROJECT/$DIR | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo "Building $IMAGE_NAME:$VERSION" | |
echo VERSION=$VERSION | |
cd ../$DIR | |
docker build . --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
echo "Pushing $IMAGE_ID:$VERSION" | |
docker push $IMAGE_ID:$VERSION | |
done |