Skip to content

Commit

Permalink
ci: add cache from gha runners for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
matteovivona committed Jun 11, 2024
1 parent 137b5df commit 780cbfd
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Docker
on:
release:
types: [published]
workflow_dispatch:

permissions: read-all

env:
IMAGE_NAME: ducktors/turborepo-remote-cache

jobs:
docker-build:
name: Docker Build
Expand All @@ -15,38 +19,29 @@ jobs:
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Get package version
id: package-version
uses: martinbeentjes/npm-get-version-action@3cf273023a0dda27efcd3164bdfb51908dd46a5b # main
with:
path: .
- name: Set correct environment
run: |
TAG=${{ steps.package-version.outputs.current-version}}
echo "TAG=$TAG" >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0

- name: Login to DockerHub
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
platforms: linux/x86_64,linux/arm64
push: true
tags: |
ducktors/turborepo-remote-cache:latest
ducktors/turborepo-remote-cache:${{ env.TAG }}
cache-from: |
ducktors/turborepo-remote-cache:latest
run: |
docker buildx build \
--file Dockerfile \
--platform linux/amd64,linux/arm64 \
--tag ${{env.IMAGE_NAME}}:latest \
--tag ${{env.IMAGE_NAME}}:${{ steps.package-version.outputs.current-version}} \
--cache-from=type=gha \
--cache-to=type=gha,mode=max \
--push .

0 comments on commit 780cbfd

Please sign in to comment.