name: Docker on: push: branches: - "**" paths: - 'backend/**' - 'frontend/**' - 'docker/**' - '.github/workflows/docker.yml' pull_request: branches: - main - master paths: - 'backend/**' - 'frontend/**' - 'docker/**' - '.github/workflows/docker.yml' workflow_dispatch: {} jobs: build: name: Docker Build & Push runs-on: ubuntu-latest permissions: contents: read steps: - name: Checkout code uses: actions/checkout@v7 with: submodules: false - name: Set up QEMU (multi-arch builds) if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: docker/setup-qemu-action@v4 - name: Configure Gitea Go registry working-directory: ${{ github.workspace }} shell: bash env: PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }} PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }} run: | set -euo pipefail if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2 exit 1 fi netrc_path="$RUNNER_TEMP/gitea-go.netrc" umask 077 { printf 'machine repos.gfranz.ch\n' printf 'login %s\n' "$PACKAGE_REGISTRY_USERNAME" printf 'password %s\n' "$PACKAGE_REGISTRY_TOKEN" } > "$netrc_path" { printf 'NETRC=%s\n' "$netrc_path" printf 'GOAUTH=netrc\n' printf 'GOPROXY=https://repos.gfranz.ch/api/packages/Gabriel20xx/go,https://proxy.golang.org\n' printf 'GONOSUMDB=repos.gfranz.ch/Gabriel20xx/shared/*\n' } >> "$GITHUB_ENV" - name: Configure Gitea npm registry working-directory: ${{ github.workspace }} shell: bash env: PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }} PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }} run: | set -euo pipefail if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2 exit 1 fi npmrc_path="$RUNNER_TEMP/gitea-npmrc" umask 077 { printf '@gabriel20xx:registry=https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/\n' printf '//repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken=%s\n' "$PACKAGE_REGISTRY_TOKEN" printf 'always-auth=true\n' } > "$npmrc_path" printf 'NPM_CONFIG_USERCONFIG=%s\n' "$npmrc_path" >> "$GITHUB_ENV" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Log in to Docker Hub if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: docker/login-action@v4 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract Docker metadata id: meta uses: docker/metadata-action@v6 with: images: ${{ vars.DOCKERHUB_USERNAME }}/collabtableserver tags: | type=ref,event=branch type=sha,prefix=sha-,format=short type=raw,value=latest,enable={{is_default_branch}} - name: Build and push uses: docker/build-push-action@v7 with: secret-files: | gitea_npmrc=${{ runner.temp }}/gitea-npmrc gitea_go_netrc=${{ runner.temp }}/gitea-go.netrc context: . file: ./docker/Dockerfile platforms: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && 'linux/amd64,linux/arm64' || 'linux/amd64' }} push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=${{ vars.DOCKERHUB_USERNAME }}/collabtableserver:buildcache cache-to: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && format('type=registry,ref={0}/collabtableserver:buildcache,mode=max', vars.DOCKERHUB_USERNAME) || '' }} provenance: false