mirror of
https://gitea.com/docker/metadata-action.git
synced 2024-11-21 19:49:32 +01:00
Provide outputs as env vars
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
05d22bf317
commit
6729545cde
5 changed files with 84 additions and 5 deletions
39
.github/workflows/ci.yml
vendored
39
.github/workflows/ci.yml
vendored
|
@ -37,6 +37,9 @@ jobs:
|
|||
type=ref,event=tag
|
||||
type=ref,event=pr
|
||||
type=sha
|
||||
-
|
||||
name: Print envs
|
||||
run: env|sort
|
||||
|
||||
tag-schedule:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -224,6 +227,14 @@ jobs:
|
|||
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 "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:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -350,3 +361,31 @@ jobs:
|
|||
with:
|
||||
script: |
|
||||
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
|
||||
|
|
17
README.md
17
README.md
|
@ -297,6 +297,23 @@ Following outputs are available
|
|||
| `json` | String | JSON output of tags and labels |
|
||||
| `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
|
||||
|
||||
| Name | Type | Description |
|
||||
|
|
15
src/main.ts
15
src/main.ts
|
@ -41,7 +41,7 @@ async function run() {
|
|||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
}
|
||||
core.setOutput('version', version.main || '');
|
||||
setOutput('version', version.main || '');
|
||||
|
||||
// Docker tags
|
||||
const tags: Array<string> = meta.getTags();
|
||||
|
@ -54,7 +54,7 @@ async function run() {
|
|||
}
|
||||
core.endGroup();
|
||||
}
|
||||
core.setOutput('tags', tags.join(inputs.sepTags));
|
||||
setOutput('tags', tags.join(inputs.sepTags));
|
||||
|
||||
// Docker labels
|
||||
const labels: Array<string> = meta.getLabels();
|
||||
|
@ -63,24 +63,29 @@ async function run() {
|
|||
core.info(label);
|
||||
}
|
||||
core.endGroup();
|
||||
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||
setOutput('labels', labels.join(inputs.sepLabels));
|
||||
|
||||
// JSON
|
||||
const jsonOutput = meta.getJSON();
|
||||
core.startGroup(`JSON output`);
|
||||
core.info(JSON.stringify(jsonOutput, null, 2));
|
||||
core.endGroup();
|
||||
core.setOutput('json', jsonOutput);
|
||||
setOutput('json', JSON.stringify(jsonOutput));
|
||||
|
||||
// Bake file definition
|
||||
const bakeFile: string = meta.getBakeFile();
|
||||
core.startGroup(`Bake file definition`);
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
core.endGroup();
|
||||
core.setOutput('bake-file', bakeFile);
|
||||
setOutput('bake-file', bakeFile);
|
||||
} catch (error) {
|
||||
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();
|
||||
|
|
6
test/json.Dockerfile
Normal file
6
test/json.Dockerfile
Normal 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
12
test/output.Dockerfile
Normal 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
|
Loading…
Reference in a new issue