Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
identw committed Jul 11, 2024
1 parent e0911f7 commit 496f7c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
10 changes: 10 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ inputs:
description: 'latest tag'
required: false
default: 'false'
cache-from:
description: 'cache from https://docs.docker.com/build/ci/github-actions/cache/'
required: false
default: ''
cache-to:
description: 'cache from https://docs.docker.com/build/ci/github-actions/cache/'
required: false
default: ''
outputs:
copy-files:
description: 'copy files'
Expand Down Expand Up @@ -68,3 +76,5 @@ runs:
platforms: ${{ inputs.platforms }}
token: ${{ inputs.registry-password }}
latest: ${{ inputs.latest }}
cache-from: ${{ inputs.cache-from }}
cache-to: ${{ inputs.cache-to }}
8 changes: 8 additions & 0 deletions js-action/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ inputs:
description: 'latest tag'
required: false
default: 'false'
cache-from:
description: 'cache from https://docs.docker.com/build/ci/github-actions/cache/'
required: false
default: ''
cache-to:
description: 'cache from https://docs.docker.com/build/ci/github-actions/cache/'
required: false
default: ''

outputs:
copy-files:
Expand Down
33 changes: 26 additions & 7 deletions js-action/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ async function main() {
const latest = core.getInput('latest');
const operation = core.getInput('operation');
const platforms = core.getInput('platforms');
const cacheFrom = core.getInput('cache-from');
const cacheTo = core.getInput('cache-to');
const repoName = context.payload.repository.name.toLowerCase();
const org = context.payload.repository.owner.login.toLowerCase();
const buildOpts = yamlParse(core.getInput('build-opts'));
Expand Down Expand Up @@ -112,6 +114,25 @@ async function main() {
}
}

let resultCacheFrom = cacheFrom;
if ('cache-from' in image) {
resultCacheFrom = image['cache-from'];
}
if (resultCacheFrom != '') {
resultCacheFrom = `--cache-from ${resultCacheFrom}`;
}

let resultCacheTo = cacheTo;
if ('cache-to' in image) {
resultCacheTo = image['cache-to'];
}
if (resultCacheTo != '') {
resultCacheTo = `--cache-to ${resultCacheTo}`;
}

console.log(`resultCacheFrom: ${resultCacheFrom}`);
console.log(`resultCacheTo: ${resultCacheTo}`);

let resultPlatforms = '';
if (platforms != '') {
resultPlatforms = `--platform ${platforms}`;
Expand All @@ -138,11 +159,9 @@ async function main() {
} else {
resultLatest = false;
}
console.log(`resultLatest: ${resultLatest}`);
console.log(typeof resultLatest);

// build image commands
commands['build'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} ${load} --tag ${buildImage} --tag ${buildTmpTag} ${target} .`];
commands['build'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} ${load} ${resultCacheFrom} ${resultCacheTo} --tag ${buildImage} --tag ${buildTmpTag} ${target} .`];

// pre push image commands
commands['prePush'] = [
Expand All @@ -160,12 +179,12 @@ async function main() {

if (multiPlatform) {
// create buildTmpTag for current platform
commands['build'].push(`docker buildx build ${file} ${args} ${secrets} --load --tag ${buildTmpTag} ${target} .`);
commands['build'].push(`docker buildx build ${file} ${args} ${secrets} --load ${resultCacheFrom} ${resultCacheTo} --tag ${buildTmpTag} ${target} .`);
outputBuiltImages[image.name] = buildTmpTag;
commands['prePush'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} --push --tag ${prePushImage} ${target} .`];
commands['push'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} --push --tag ${pushImage} ${target} .`];
commands['prePush'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} --push ${resultCacheFrom} ${resultCacheTo} --tag ${prePushImage} ${target} .`];
commands['push'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} --push ${resultCacheFrom} ${resultCacheTo} --tag ${pushImage} ${target} .`];
if (resultLatest) {
commands['push'].push(`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} --push --tag ${pushImageLatest} ${target} .`);
commands['push'].push(`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} --push ${resultCacheFrom} ${resultCacheTo} --tag ${pushImageLatest} ${target} .`);
}
}
imagesCommands.push(commands);
Expand Down

0 comments on commit 496f7c3

Please sign in to comment.