|
| 1 | +name: Push Prod Image to GHCR |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + packages: write |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + publish-docker-image: |
| 13 | + name: Build and Push |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + strategy: |
| 17 | + fail-fast: true |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - dockerfile: ./.docker/web.Dockerfile |
| 21 | + image: ghcr.io/sparcs/biseo-web |
| 22 | + - dockerfile: ./.docker/api.Dockerfile |
| 23 | + image: ghcr.io/sparcs/biseo-api |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + |
| 32 | + - name: Cache Docker Layers |
| 33 | + uses: actions/cache@v3 |
| 34 | + with: |
| 35 | + path: /tmp/.buildx-cache |
| 36 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-buildx- |
| 39 | +
|
| 40 | + - name: Log in to Github Container Registry |
| 41 | + uses: docker/login-action@v3 |
| 42 | + with: |
| 43 | + registry: "ghcr.io" |
| 44 | + username: ${{ github.actor }} |
| 45 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + |
| 47 | + - name: Extract Metadata |
| 48 | + id: meta |
| 49 | + uses: docker/metadata-action@v5 |
| 50 | + with: |
| 51 | + images: ${{ matrix.image }} |
| 52 | + tags: | |
| 53 | + type=raw,value=latest |
| 54 | + type=sha,format=long |
| 55 | +
|
| 56 | + - name: Build and push Docker image |
| 57 | + uses: docker/build-push-action@v5 |
| 58 | + with: |
| 59 | + context: . |
| 60 | + file: ${{ matrix.dockerfile }} |
| 61 | + push: true |
| 62 | + tags: ${{ steps.meta.outputs.tags }} |
| 63 | + labels: ${{ steps.meta.outputs.labels }} |
| 64 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 65 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 66 | + |
| 67 | + - name: Move cache |
| 68 | + run: | |
| 69 | + rm -rf /tmp/.buildx-cache |
| 70 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 71 | + |
0 commit comments