From 496f7c32620b93a1df766a9dbf5c4b1b04e054e5 Mon Sep 17 00:00:00 2001 From: Dmitry Sergeev Date: Thu, 11 Jul 2024 21:10:19 +0400 Subject: [PATCH] WIP --- action.yaml | 10 ++++++++++ js-action/action.yaml | 8 ++++++++ js-action/src/index.js | 33 ++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/action.yaml b/action.yaml index d6e00bc..1088ccf 100644 --- a/action.yaml +++ b/action.yaml @@ -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' @@ -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 }} diff --git a/js-action/action.yaml b/js-action/action.yaml index 88bf92a..29c3ece 100644 --- a/js-action/action.yaml +++ b/js-action/action.yaml @@ -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: diff --git a/js-action/src/index.js b/js-action/src/index.js index 3c77f77..c1734bb 100644 --- a/js-action/src/index.js +++ b/js-action/src/index.js @@ -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')); @@ -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}`; @@ -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'] = [ @@ -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);