# Builds the Docker image and pushes it to Gitea's built-in container registry # on every push to main. Tags each build as :latest and :. # # PREREQUISITES on your Gitea instance: # 1. Actions must be enabled (app.ini: [actions] ENABLED = true) and at least # one act_runner registered. # 2. The runner must be able to build images. act_runner needs access to a # Docker daemon — either run the runner with the host Docker socket mounted # (-v /var/run/docker.sock:/var/run/docker.sock) or in docker-in-docker mode. # 3. The Package Registry must be enabled (it is by default). # # TOKEN: the workflow tries the auto-injected GITHUB_TOKEN first. If your Gitea # version does not grant it package-write scope, create a Personal Access Token # with "write:package" scope and add it as a repository secret named # REGISTRY_TOKEN (Repo > Settings > Actions > Secrets). name: build-image on: push: branches: [main] jobs: build-and-push: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Compute registry host and image name id: meta run: | # Registry host = the Gitea instance host (strip the scheme). echo "registry=$(echo '${{ github.server_url }}' | sed -E 's#^https?://##')" >> "$GITHUB_OUTPUT" # Image path must be lowercase for OCI registries. echo "image=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to the Gitea container registry uses: docker/login-action@v3 with: registry: ${{ steps.meta.outputs.registry }} username: ${{ github.actor }} password: ${{ secrets.REGISTRY_TOKEN || secrets.GITHUB_TOKEN }} - name: Build and push uses: docker/build-push-action@v6 with: context: . push: true tags: | ${{ steps.meta.outputs.registry }}/${{ steps.meta.outputs.image }}:latest ${{ steps.meta.outputs.registry }}/${{ steps.meta.outputs.image }}:${{ github.sha }}