env: LOCAL_REGISTRY: registry.wimill.xyz REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} name: Build and push docker image on: push: branches: [main] tags: ["*"] pull_request: types: [opened, synchronize, reopened] concurrency: group: ${{ github.ref }} cancel-in-progress: true jobs: build: runs-on: [self-hosted, new] steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Docker meta local id: metalocal uses: docker/metadata-action@v4 with: images: ${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - name: Build and push privately uses: docker/build-push-action@v3 if: github.event_name == 'pull_request' with: context: . push: true tags: | ${{ steps.metalocal.outputs.tags }} labels: ${{ steps.metalocal.outputs.labels }} cache-from: type=registry,ref=${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache cache-to: type=registry,ref=${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max - name: Docker meta if: github.event_name != 'pull_request' id: meta uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - name: Login to registry if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push publically uses: docker/build-push-action@v3 if: github.event_name != 'pull_request' with: context: . push: true tags: | ${{ steps.metalocal.outputs.tags }} ${{ steps.meta.outputs.tags }} labels: ${{ steps.metalocal.outputs.labels }} cache-from: type=registry,ref=${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache cache-to: type=registry,ref=${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max