name: Build and publish Docker image on: push: branches: - main workflow_dispatch: permissions: contents: read packages: write jobs: build-and-publish: runs-on: ubuntu-latest steps: - name: Check out source uses: actions/checkout@v4 - name: Log in to Gitea Container Registry env: REGISTRY_USERNAME: ${{ gitea.actor }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} run: | printf '%s' "$REGISTRY_TOKEN" | docker login git.anchorhost.eu --username "$REGISTRY_USERNAME" --password-stdin - name: Build and tag image env: COMMIT_SHA: ${{ gitea.sha }} DOCKER_IMAGE: git.anchorhost.eu/anchorhost.eu/anchorhost-backend run: | docker build \ --label "org.opencontainers.image.revision=$COMMIT_SHA" \ --tag "$DOCKER_IMAGE:backend" \ --tag "$DOCKER_IMAGE:main-${COMMIT_SHA:0:12}" \ . - name: Push image env: COMMIT_SHA: ${{ gitea.sha }} DOCKER_IMAGE: git.anchorhost.eu/anchorhost.eu/anchorhost-backend run: | docker push "$DOCKER_IMAGE:backend" docker push "$DOCKER_IMAGE:main-${COMMIT_SHA:0:12}" - name: Log out from Gitea Container Registry if: always() run: docker logout