Skip to content

Commit

Permalink
cache builds
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Jul 13, 2023
1 parent 20a924d commit 0bc6b1d
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions .github/workflows/trigger-build-on-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,43 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Prepare
id: prep
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="${REPOSITORY}/hs_docker_base"
echo ::set-output name=tagged_image::${IMAGE}:${TAG}
echo ::set-output name=tag::${TAG}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Docker Login
run: |
echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USER --password-stdin
# Build the Docker image
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Build
run: |
export DOCKER_TAG="${REPOSITORY}/hs_docker_base:${GITHUB_SHA}"
docker build -t $DOCKER_TAG .
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Push Docker Image
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
docker push $DOCKER_TAG
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 comments on commit 0bc6b1d

Please sign in to comment.