Skip to content

Commit

Permalink
ci: different cache approach
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkens committed Jul 29, 2024
1 parent 7a2f391 commit c6359d1
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,39 @@ jobs:
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- name: Login to ghcr.io
if: ${{ github.ref == 'refs/heads/main' }} || ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build & push (main)
if: ${{ github.ref == 'refs/heads/main' }}
env:
USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo ${GHCR_TOKEN} | docker login ghcr.io -u ${USERNAME} --password-stdin
docker buildx build --push \
--cache-from=type=gha --cache-to=type=gha,mode=max \
--cache-from=ghcr.io/${USERNAME}/ghstats:main \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/${USERNAME}/ghstats:main .
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ github.repository }}:main
- name: build & push (tag)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ref="$(echo ${{ github.ref}} | cut -d'/' -f3)"
echo ${GHCR_TOKEN} | docker login ghcr.io -u ${USERNAME} --password-stdin
docker buildx build --push \
--cache-from=type=gha --cache-to=type=gha,mode=max \
--cache-from=ghcr.io/${USERNAME}/ghstats:main \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/${USERNAME}/ghstats:${ref} -t ghcr.io/${USERNAME}/ghstats:latest .
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
ghcr.io/${{ github.repository }}:latest
- name: Create Github Release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit c6359d1

Please sign in to comment.