# Build and Push Docker Images name: Build on: push: branches: [ main ] tags: - 'v*' env: REGISTRY: ${{ vars.PACKAGES_REGISTRY }} IMAGE_NAME: ${{ gitea.repository }} jobs: build-and-push: name: Build and Push Docker Images runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') strategy: matrix: component: [api, chat, worker, frontend] steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Container Registry uses: docker/login-action@v3 with: registry: ${{ vars.PACKAGES_REGISTRY }} username: ${{ secrets.USERNAME }} password: ${{ secrets.TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ vars.PACKAGES_REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.component }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . file: deploy/docker/Dockerfile.${{ matrix.component }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=${{ vars.PACKAGES_REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.component }}:buildcache cache-to: type=registry,ref=${{ vars.PACKAGES_REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.component }}:buildcache,mode=max