Skip to content

Commit

Permalink
ci: use registry cache
Browse files Browse the repository at this point in the history
Reorder steps based on logical flow
  • Loading branch information
pythoninthegrass committed Oct 16, 2024
1 parent bd9f88e commit 90fc909
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract image name from Dockerfile
id: image_name
run: |
IMAGE=$(grep "LABEL org.opencontainers.image.title" Dockerfile | cut -d'"' -f2)
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
- name: Set password by container registry
run: |
case "${{ env.REGISTRY_URL }}" in
Expand All @@ -55,6 +49,20 @@ jobs:
;;
esac
- name: Log into container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASS }}

- name: Extract image name from Dockerfile
id: image_name
run: |
IMAGE=$(grep "LABEL org.opencontainers.image.title" Dockerfile | cut -d'"' -f2)
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -71,28 +79,12 @@ jobs:
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up QEMU
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASS }}

- name: Set up Docker Buildx cache
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
uses: docker/build-push-action@v6
with:
Expand All @@ -101,5 +93,5 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache,mode=max

0 comments on commit 90fc909

Please sign in to comment.