|
| 1 | +name: Build Docker Image |
| 2 | + |
| 3 | +on: [push, pull_request, workflow_dispatch] |
| 4 | + |
| 5 | +env: |
| 6 | + REGISTRY: ghcr.io |
| 7 | + IMAGE_NAME: ${{ github.repository }} |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Docker Buildx |
| 21 | + uses: docker/setup-buildx-action@v3 |
| 22 | + |
| 23 | + - name: Log in to GitHub Container Registry |
| 24 | + uses: docker/login-action@v3 |
| 25 | + with: |
| 26 | + registry: ${{ env.REGISTRY }} |
| 27 | + username: ${{ github.actor }} |
| 28 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Extract metadata |
| 31 | + id: meta |
| 32 | + uses: docker/metadata-action@v5 |
| 33 | + with: |
| 34 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 35 | + tags: | |
| 36 | + type=ref,event=branch |
| 37 | + type=ref,event=pr |
| 38 | + type=sha,prefix={{branch}}- |
| 39 | + type=raw,value=latest,enable={{is_default_branch}} |
| 40 | +
|
| 41 | + - name: Build and push Docker image |
| 42 | + uses: docker/build-push-action@v5 |
| 43 | + with: |
| 44 | + context: . |
| 45 | + file: docker/Dockerfile |
| 46 | + platforms: linux/amd64 |
| 47 | + push: true |
| 48 | + tags: ${{ steps.meta.outputs.tags }} |
| 49 | + labels: ${{ steps.meta.outputs.labels }} |
| 50 | + cache-from: type=gha |
| 51 | + cache-to: type=gha,mode=max |
| 52 | + |
| 53 | + - name: Image summary |
| 54 | + run: | |
| 55 | + echo "### Docker Image Built 🐳" >> $GITHUB_STEP_SUMMARY |
| 56 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 57 | + echo "**Tags:**" >> $GITHUB_STEP_SUMMARY |
| 58 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 59 | + echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
| 60 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments