diff --git a/README.md b/README.md index 4eeb85f..a8ffbdc 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,38 @@ RUN --mount=type=secret,id=ANDROID_KEYSTORE \ latest: true ``` +### cache +Можно использовать cache-from и cache-to + +```yaml +- id: set-tags + run: | + commit_sha=${{ github.sha }} + commit_sha=${commit_sha:0:10} + time=`date +%Y%m%d%H%M` + + echo "tag=${{ inputs.area }}-${{ inputs.platform }}-${time}-${{ github.ref_name }}-${commit_sha}" >> $GITHUB_OUTPUT +# nosemgrep +- uses: orangeappsru/build-images-action@main + id: build-images + with: + registry: ${{ vars.REGISTRY }} + registry-user: ${{ secrets.REGISTRY_USER }} + registry-password: ${{ secrets.REGISTRY_PASSWORD }} + tag: ${{ steps.set-tags.outputs.tag }} + operation: build-and-push + cache-from: type=gha + cache-to: type=gha,mode=max + build-opts: | + - name: server + args: + - name: GITHUB_USER + value: ${{ github.repository_owner }} + - name: GITHUB_TOKEN + value: ${{ secrets.COMMON_TOKEN }} + - name: nginx +``` + Если будет использоваться ghcr.io, то в случае нескольких образов latest тег будет запушен следующим образом: `ghcr.io//:-latest` ## Inputs diff --git a/js-action/src/index.js b/js-action/src/index.js index 676fb24..dc1a215 100644 --- a/js-action/src/index.js +++ b/js-action/src/index.js @@ -24,6 +24,7 @@ async function main() { const buildOpts = yamlParse(core.getInput('build-opts')); const githubRegistry = 'ghcr.io'; + if (!isMainThread) { // Worker треды: const { image } = workerData; @@ -132,18 +133,15 @@ async function main() { let resultPlatforms = ''; if (platforms != '') { - resultPlatforms = `--platform ${platforms}`; + resultPlatforms = platforms; } if ('platforms' in image) { - resultPlatforms = `--platform ${image.platforms}`; + resultPlatforms = image.platforms; } - let load = '--load'; let multiPlatform = false; - // disable --load if multiple platforms if (resultPlatforms.split(',').length > 1) { multiPlatform = true; - load = ''; } // latest @@ -162,7 +160,7 @@ async function main() { } // build image commands - commands['build'] = [`docker buildx build ${file} ${args} ${secrets} ${resultPlatforms} ${load} ${resultCacheFrom} ${resultCacheTo} --tag ${buildImage} --tag ${buildTmpTag} ${target} .`]; + commands['build'] = [`docker buildx build ${file} ${args} ${secrets} --load ${resultCacheFrom} ${resultCacheTo} --tag ${buildImage} --tag ${buildTmpTag} ${target} .`]; // pre push image commands commands['prePush'] = [ @@ -179,8 +177,12 @@ async function main() { } if (multiPlatform) { + commands['build'] = []; // create buildTmpTag for current platform commands['build'].push(`docker buildx build ${file} ${args} ${secrets} --load ${resultCacheFrom} ${resultCacheTo} --tag ${buildTmpTag} ${target} .`); + for (p of resultPlatforms.split(',')) { + commands['build'].push(`docker buildx build ${file} ${args} ${secrets} --platform ${p} --load ${resultCacheFrom} ${resultCacheTo} --tag ${buildImage} ${target} .`); + } outputBuiltImages[image.name] = buildTmpTag; 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} .`];