From ae03c90c13f0728ac3d9aa1b561bad94933d5649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20K=C3=A6r=20J=C3=B8rgensen?= Date: Wed, 23 Oct 2024 14:07:32 +0200 Subject: [PATCH] Update Api-Docker-Image-CI.yml --- .github/workflows/Api-Docker-Image-CI.yml | 32 ++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Api-Docker-Image-CI.yml b/.github/workflows/Api-Docker-Image-CI.yml index 574c59b..3df2df3 100644 --- a/.github/workflows/Api-Docker-Image-CI.yml +++ b/.github/workflows/Api-Docker-Image-CI.yml @@ -10,8 +10,34 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Build the Docker image + + # Cache Docker layers + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-docker-${{ hashFiles('**/*.dockerfile') }} + restore-keys: | + ${{ runner.os }}-docker- + + # Set up Docker Buildx (for advanced caching features) + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Build and push the Docker image with cache + - name: Build and push the Docker image run: | echo ${{ secrets.REGISTRY_PASSWORD }} | docker login registry.jazper.dk --username ${{ secrets.REGISTRY_USERNAME }} --password-stdin - docker build -f ./Api.Dockerfile -t registry.jazper.dk/notam-management-api:latest . - docker push registry.jazper.dk/notam-management-api:latest \ No newline at end of file + docker buildx build \ + --cache-from=type=local,src=/tmp/.buildx-cache \ + --cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max \ + -f ./Api.Dockerfile \ + -t registry.jazper.dk/notam-management-api:latest \ + --push . + + # Move new cache to the original location after build + - name: Update Docker cache + if: success() + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache