Skip to content

Commit

Permalink
🧰 chore: Faster Builds using GHA Cache (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrosenbauer authored Jul 12, 2024
1 parent 3fa56c2 commit 84547c6
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 11 deletions.
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ runs:
with:
project_id: ${{ inputs.gcp_project_id }}

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

- name: '🐳 Authorize Docker push'
shell: bash
run: gcloud auth configure-docker us-docker.pkg.dev --quiet
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
],
"devDependencies": {
"@joggr/tempo": "^0.6.0",
"@types/github-script": "github:actions/github-script",
"husky": "^9.0.11",
"yaml": "^2.3.4"
},
Expand Down
19 changes: 8 additions & 11 deletions scripts/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ function getMultilineInput(env, name) {
/**
* Build & Push Docker Image
*
* @param {object} payload
* @param {object} payload.context
* @param {object} payload.core
* @param {object} payload.github
* @param {object} payload.exec
* @param {import('@types/github-script').AsyncFunctionArguments} payload
*/
module.exports = async ({ github, context, exec, core, env }) => {
const dockerBuildArgs = getMultilineInput(env, 'DOCKER_BUILD_ARGS');
Expand Down Expand Up @@ -60,18 +56,19 @@ module.exports = async ({ github, context, exec, core, env }) => {
});

await exec.exec('docker', [
'buildx',
'build',
'--push',
'--cache-from',
'type=gha',
'--cache-to',
'type=gha,mode=max',
...buildArgs,
...tags,
'--tag',
`${fullImageName}:${githubSha}`,
'--file',
'--file',
`${dockerDirectory}/${dockerFileName}`,
`${dockerDirectory}`
]);
await exec.exec('docker', [
'push',
`us-docker.pkg.dev/${gcpProjectId}/${gcpArtifactRepository}/${name}`,
'--all-tags'
]);
}
Loading

0 comments on commit 84547c6

Please sign in to comment.