|
| 1 | +name: Publish Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + publish: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Get image tag |
| 13 | + id: image_tag |
| 14 | + run: echo ::set-output name=tag::${GITHUB_REF:10} |
| 15 | + |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v2 |
| 18 | + |
| 19 | + - name: Create Docker context |
| 20 | + run: docker context create mycontext |
| 21 | + |
| 22 | + - name: Set up Docker Buildx |
| 23 | + id: buildx |
| 24 | + uses: docker/setup-buildx-action@v1 |
| 25 | + with: |
| 26 | + endpoint: mycontext |
| 27 | + |
| 28 | + - name: Cache Docker layers |
| 29 | + uses: actions/cache@v2 |
| 30 | + with: |
| 31 | + path: /tmp/.buildx-cache |
| 32 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 33 | + restore-keys: | |
| 34 | + ${{ runner.os }}-buildx- |
| 35 | +
|
| 36 | + - name: Login to GHCR |
| 37 | + uses: docker/login-action@v1 |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Get repo in lowercase |
| 44 | + id: repo_name |
| 45 | + run: echo ::set-output name=repo::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') |
| 46 | + |
| 47 | + - name: Build & push image |
| 48 | + uses: docker/build-push-action@v2 |
| 49 | + with: |
| 50 | + context: . |
| 51 | + builder: ${{ steps.buildx.outputs.name }} |
| 52 | + push: true |
| 53 | + tags: ghcr.io/${{ steps.repo_name.outputs.repo }}:${{ steps.image_tag.outputs.tag }},ghcr.io/${{ steps.repo_name.outputs.repo }}:latest |
| 54 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 55 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 56 | + |
| 57 | + # Temp fix |
| 58 | + # https://github.com/docker/build-push-action/issues/252 |
| 59 | + # https://github.com/moby/buildkit/issues/1896 |
| 60 | + - name: Move cache |
| 61 | + run: | |
| 62 | + rm -rf /tmp/.buildx-cache |
| 63 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments