|
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 | - dev |
| 8 | + tags: |
| 9 | + - '**' |
| 10 | + paths-ignore: |
| 11 | + - README.md |
8 | 12 | pull_request: |
| 13 | + paths-ignore: |
| 14 | + - README.md |
9 | 15 | jobs: |
10 | 16 | build: |
11 | 17 | runs-on: ubuntu-latest |
@@ -41,19 +47,68 @@ jobs: |
41 | 47 | echo "Status: ${{ steps.buildx.outputs.status }}" |
42 | 48 | echo "Flags: ${{ steps.buildx.outputs.flags }}" |
43 | 49 | echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
44 | | - - name: Build candidate |
| 50 | + - name: Cache Docker layers |
| 51 | + uses: actions/cache@v2 |
| 52 | + id: cache |
| 53 | + with: |
| 54 | + path: /tmp/.buildx-cache |
| 55 | + key: ${{ runner.os }}-buildx-ghcache-${{ github.sha }} |
| 56 | + restore-keys: | |
| 57 | + ${{ runner.os }}-buildx-ghcache- |
| 58 | + - name: Build candidate image |
45 | 59 | id: build_candidate |
46 | 60 | uses: docker/build-push-action@v2 |
47 | 61 | with: |
48 | 62 | context: . |
49 | 63 | file: Dockerfile |
50 | 64 | platforms: ${{ env.PLATFORMS }} |
51 | 65 | push: true |
52 | | - tags: localhost:5000/golang-with-libgit2:latest |
53 | | - - name: Inspect candidate |
| 66 | + tags: localhost:5000/${{ github.repository_owner }}/golang-with-libgit2:latest |
| 67 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 68 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 69 | + - name: Inspect candidate image |
54 | 70 | run: | |
55 | | - docker buildx imagetools inspect localhost:5000/golang-with-libgit2:latest |
56 | | - - name: Test candidate |
| 71 | + docker buildx imagetools inspect localhost:5000/${{ github.repository_owner }}/golang-with-libgit2:latest |
| 72 | + - name: Test candidate image |
57 | 73 | id: test_candidate |
58 | 74 | run: | |
59 | | - IMG=localhost:5000/golang-with-libgit2 make test |
| 75 | + IMG=localhost:5000/${{ github.repository_owner }}/golang-with-libgit2 make test |
| 76 | + - # Temp fix |
| 77 | + # https://github.com/docker/build-push-action/issues/252 |
| 78 | + # https://github.com/moby/buildkit/issues/1896 |
| 79 | + name: Move cache |
| 80 | + run: | |
| 81 | + rm -rf /tmp/.buildx-cache |
| 82 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 83 | + - name: Login to GHCR |
| 84 | + if: github.event_name != 'pull_request' |
| 85 | + uses: docker/login-action@v1 |
| 86 | + with: |
| 87 | + registry: ghcr.io |
| 88 | + username: ${{ github.repository_owner }} |
| 89 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + - name: Compose release candidate metadata |
| 91 | + id: meta |
| 92 | + uses: docker/metadata-action@v3 |
| 93 | + if: github.event_name != 'pull_request' |
| 94 | + with: |
| 95 | + images: | |
| 96 | + ghcr.io/${{ github.repository_owner }}/golang-with-libgit2 |
| 97 | + tags: | |
| 98 | + type=schedule |
| 99 | + type=ref,event=branch |
| 100 | + type=ref,event=tag |
| 101 | + type=sha |
| 102 | + type=sha,format=long |
| 103 | + - name: Release candidate image |
| 104 | + id: release_candidate |
| 105 | + if: github.event_name != 'pull_request' |
| 106 | + uses: docker/build-push-action@v2 |
| 107 | + with: |
| 108 | + context: . |
| 109 | + file: Dockerfile |
| 110 | + platforms: ${{ env.PLATFORMS }} |
| 111 | + push: true |
| 112 | + tags: ${{ steps.meta.outputs.tags }} |
| 113 | + labels: ${{ steps.meta.outputs.labels }} |
| 114 | + cache-from: type=local,src=/tmp/.buildx-cache |
0 commit comments