name: Publish Docker Image on: push: branches: - master jobs: docker: runs-on: ubuntu-latest steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Set variables id: prep run: | DOCKER_IMAGE=server REPOSITORY="$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" # Repository name must be lowercase in image tags if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then GITHUB_SHA=$(jq -r .pull_request.head.sha < "$GITHUB_EVENT_PATH") # GITHUB_SHA is the merge SHA, not the head commit SHA in a PR, replace it. fi TAGS="ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:${GITHUB_SHA}" if [ "${GITHUB_REF}" = "refs/heads/master" ]; then TAGS="$TAGS,ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:latest,ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:master" fi echo "tags=${TAGS}" >> $GITHUB_OUTPUT - name: Log in to GitHub Docker Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and Push container image uses: docker/build-push-action@v5 with: push: true tags: ${{ steps.prep.outputs.tags }}