Merge pull request #257 from crazy-max/env-output
ci / multi-images (push) Successful in 8s Details
ci / tag-schedule () (push) Successful in 7s Details
ci / tag-schedule (cron-{{date 'YYYYMMDD'}}) (push) Successful in 7s Details
ci / tag-schedule (schedule) (push) Successful in 8s Details
ci / tag-schedule ({{date 'YYYYMMDD-HHmmss'}}) (push) Successful in 8s Details
ci / tag-match (\d.\d, 0) (push) Successful in 8s Details
ci / tag-match (\d.\d.\d, 0) (push) Successful in 8s Details
ci / tag-match (v(.*), 1) (push) Successful in 8s Details
ci / tag-semver (auto) (push) Successful in 8s Details
ci / tag-semver (false) (push) Successful in 8s Details
ci / tag-semver (true) (push) Successful in 8s Details
ci / flavor (push) Successful in 8s Details
ci / images (push) Successful in 8s Details
ci / labels (push) Successful in 8s Details
ci / global-exps (push) Successful in 8s Details
ci / json (push) Failing after 11s Details
ci / docker-push (push) Failing after 18s Details
ci / bake (push) Failing after 12s Details
ci / sep-tags ( ) (push) Successful in 8s Details
ci / sep-tags (,) (push) Successful in 9s Details
ci / output-env (push) Failing after 10s Details

Provide outputs as env vars
This commit is contained in:
CrazyMax 2023-01-13 14:33:40 +01:00 committed by GitHub
commit 507c2f2dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 86 additions and 7 deletions

View File

@ -37,6 +37,9 @@ jobs:
type=ref,event=tag type=ref,event=tag
type=ref,event=pr type=ref,event=pr
type=sha type=sha
-
name: Print envs
run: env|sort
tag-schedule: tag-schedule:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -224,6 +227,14 @@ jobs:
echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}"
echo "revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}" echo "revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}"
echo "created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}" echo "created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}"
-
name: JSON build arg
uses: docker/build-push-action@v3
with:
context: ./test
file: ./test/json.Dockerfile
build-args: |
BUILDINFO=${{ steps.meta.outputs.json }}
docker-push: docker-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -350,3 +361,31 @@ jobs:
with: with:
script: | script: |
console.log(`${{ steps.meta.outputs.tags }}`); console.log(`${{ steps.meta.outputs.tags }}`);
output-env:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Docker meta
id: meta
uses: ./
with:
images: |
${{ env.DOCKER_IMAGE }}
ghcr.io/name/app
labels: |
maintainer=CrazyMax
-
name: Build
uses: docker/build-push-action@v3
with:
context: ./test
file: ./test/output.Dockerfile
build-args: |
DOCKER_METADATA_OUTPUT_VERSION
DOCKER_METADATA_OUTPUT_TAGS
DOCKER_METADATA_OUTPUT_LABELS
DOCKER_METADATA_OUTPUT_JSON

View File

@ -297,6 +297,23 @@ Following outputs are available
| `json` | String | JSON output of tags and labels | | `json` | String | JSON output of tags and labels |
| `bake-file` | File | [Bake file definition](https://docs.docker.com/build/customize/bake/file-definition/) path | | `bake-file` | File | [Bake file definition](https://docs.docker.com/build/customize/bake/file-definition/) path |
Alternatively, each output is also exported as an environment variable:
* `DOCKER_METADATA_OUTPUT_VERSION`
* `DOCKER_METADATA_OUTPUT_TAGS`
* `DOCKER_METADATA_OUTPUT_LABELS`
* `DOCKER_METADATA_OUTPUT_JSON`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE`
So it can be used with our [Docker Build Push action](https://github.com/docker/build-push-action/):
```yaml
- uses: docker/build-push-action@v3
with:
build-args: |
DOCKER_METADATA_OUTPUT_JSON
```
### environment variables ### environment variables
| Name | Type | Description | | Name | Type | Description |

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,7 @@ async function run() {
core.info(version.main || ''); core.info(version.main || '');
core.endGroup(); core.endGroup();
} }
core.setOutput('version', version.main || ''); setOutput('version', version.main || '');
// Docker tags // Docker tags
const tags: Array<string> = meta.getTags(); const tags: Array<string> = meta.getTags();
@ -54,7 +54,7 @@ async function run() {
} }
core.endGroup(); core.endGroup();
} }
core.setOutput('tags', tags.join(inputs.sepTags)); setOutput('tags', tags.join(inputs.sepTags));
// Docker labels // Docker labels
const labels: Array<string> = meta.getLabels(); const labels: Array<string> = meta.getLabels();
@ -63,24 +63,29 @@ async function run() {
core.info(label); core.info(label);
} }
core.endGroup(); core.endGroup();
core.setOutput('labels', labels.join(inputs.sepLabels)); setOutput('labels', labels.join(inputs.sepLabels));
// JSON // JSON
const jsonOutput = meta.getJSON(); const jsonOutput = meta.getJSON();
core.startGroup(`JSON output`); core.startGroup(`JSON output`);
core.info(JSON.stringify(jsonOutput, null, 2)); core.info(JSON.stringify(jsonOutput, null, 2));
core.endGroup(); core.endGroup();
core.setOutput('json', jsonOutput); setOutput('json', JSON.stringify(jsonOutput));
// Bake file definition // Bake file definition
const bakeFile: string = meta.getBakeFile(); const bakeFile: string = meta.getBakeFile();
core.startGroup(`Bake file definition`); core.startGroup(`Bake file definition`);
core.info(fs.readFileSync(bakeFile, 'utf8')); core.info(fs.readFileSync(bakeFile, 'utf8'));
core.endGroup(); core.endGroup();
core.setOutput('bake-file', bakeFile); setOutput('bake-file', bakeFile);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
} }
function setOutput(name: string, value: string) {
core.setOutput(name, value);
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
}
run(); run();

6
test/json.Dockerfile Normal file
View File

@ -0,0 +1,6 @@
# syntax=docker/dockerfile:1
FROM alpine
RUN apk add --no-cache coreutils jq
ARG BUILDINFO
RUN printenv BUILDINFO
RUN echo $BUILDINFO | jq

12
test/output.Dockerfile Normal file
View File

@ -0,0 +1,12 @@
# syntax=docker/dockerfile:1
FROM alpine
RUN apk add --no-cache coreutils jq
ARG DOCKER_METADATA_OUTPUT_VERSION
ARG DOCKER_METADATA_OUTPUT_TAGS
ARG DOCKER_METADATA_OUTPUT_LABELS
ARG DOCKER_METADATA_OUTPUT_JSON
RUN printenv DOCKER_METADATA_OUTPUT_VERSION
RUN printenv DOCKER_METADATA_OUTPUT_TAGS
RUN printenv DOCKER_METADATA_OUTPUT_LABELS
RUN printenv DOCKER_METADATA_OUTPUT_JSON
RUN echo $DOCKER_METADATA_OUTPUT_JSON | jq