|
| 1 | +name: Build & Push Image |
| 2 | +'on': |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + workflow_dispatch: |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + environment: prod |
| 11 | + permissions: |
| 12 | + id-token: write |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + steps: |
| 16 | + - name: Checkout Code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Generate build version |
| 20 | + run: | |
| 21 | + echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT |
| 22 | + echo "commit=$(git rev-parse --short=8 HEAD)" >> $GITHUB_OUTPUT |
| 23 | + echo "currdate=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT |
| 24 | + id: version |
| 25 | + |
| 26 | + - name: Extract metadata (tags, labels) for Docker |
| 27 | + id: meta |
| 28 | + uses: docker/metadata-action@v5 |
| 29 | + with: |
| 30 | + images: | |
| 31 | + ghcr.io/${{ github.repository_owner }}/deck-web-base |
| 32 | + tags: | |
| 33 | + type=raw,value=${{ steps.version.outputs.branch }} |
| 34 | + type=raw,value=${{ steps.version.outputs.commit }} |
| 35 | + flavor: latest=true |
| 36 | + |
| 37 | + - name: Generate build cache tag |
| 38 | + run: | |
| 39 | + echo "ghcr=ghcr.io/${{ github.repository_owner }}/deck-web-base:buildcache" >> $GITHUB_OUTPUT |
| 40 | + id: buildcache |
| 41 | + |
| 42 | + - name: Set up QEMU |
| 43 | + uses: docker/setup-qemu-action@v3 |
| 44 | + |
| 45 | + - name: Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@v3 |
| 47 | + with: |
| 48 | + driver-opts: | |
| 49 | + image=moby/buildkit:latest |
| 50 | +
|
| 51 | + - name: Login to GitHub Container Registry |
| 52 | + uses: docker/login-action@v3 |
| 53 | + with: |
| 54 | + registry: ghcr.io |
| 55 | + username: ${{ github.repository_owner }} |
| 56 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Build and Push Docker image |
| 59 | + id: docker_build |
| 60 | + uses: docker/build-push-action@v6 |
| 61 | + with: |
| 62 | + context: . |
| 63 | + file: ./Dockerfile |
| 64 | + push: true |
| 65 | + tags: ${{ steps.meta.outputs.tags }} |
| 66 | + labels: ${{ steps.meta.outputs.labels }} |
| 67 | + cache-from: type=registry,ref=${{ steps.buildcache.outputs.ghcr }} |
| 68 | + cache-to: type=registry,ref=${{ steps.buildcache.outputs.ghcr }},mode=max |
0 commit comments