mirror of
https://github.com/docker/metadata-action.git
synced 2025-04-19 06:59:33 +02:00
Compare commits
No commits in common. "master" and "v4.3.0" have entirely different histories.
@ -1,12 +1,2 @@
|
|||||||
/coverage
|
/coverage
|
||||||
|
/node_modules
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
|
||||||
.pnp.*
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
/dist/**
|
|
||||||
/coverage/**
|
|
||||||
/node_modules/**
|
|
@ -1,19 +1,18 @@
|
|||||||
{
|
{
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
"es6": true,
|
"es2021": true,
|
||||||
"jest": true
|
"jest/globals": true
|
||||||
},
|
},
|
||||||
"extends": [
|
"extends": [
|
||||||
"eslint:recommended",
|
"eslint:recommended",
|
||||||
"plugin:@typescript-eslint/eslint-recommended",
|
|
||||||
"plugin:@typescript-eslint/recommended",
|
"plugin:@typescript-eslint/recommended",
|
||||||
"plugin:jest/recommended",
|
"plugin:jest/recommended",
|
||||||
"plugin:prettier/recommended"
|
"plugin:prettier/recommended"
|
||||||
],
|
],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2023,
|
"ecmaVersion": "latest",
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,5 +1,3 @@
|
|||||||
/.yarn/releases/** binary
|
|
||||||
/.yarn/plugins/** binary
|
|
||||||
/__tests__/fixtures/** -linguist-detectable
|
/__tests__/fixtures/** -linguist-detectable
|
||||||
/dist/** linguist-generated=true
|
/dist/** linguist-generated=true
|
||||||
/lib/** linguist-generated=true
|
/lib/** linguist-generated=true
|
||||||
|
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
* @crazy-max
|
3
.github/CODE_OF_CONDUCT.md
vendored
3
.github/CODE_OF_CONDUCT.md
vendored
@ -1,3 +0,0 @@
|
|||||||
# Code of conduct
|
|
||||||
|
|
||||||
- [Moby community guidelines](https://github.com/moby/moby/blob/master/CONTRIBUTING.md#moby-community-guidelines)
|
|
101
.github/ISSUE_TEMPLATE/bug.yml
vendored
101
.github/ISSUE_TEMPLATE/bug.yml
vendored
@ -1,101 +0,0 @@
|
|||||||
# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema
|
|
||||||
name: Bug Report
|
|
||||||
description: Report a bug
|
|
||||||
labels:
|
|
||||||
- status/triage
|
|
||||||
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Thank you for taking the time to report a bug!
|
|
||||||
If this is a security issue please report it to the [Docker Security team](mailto:security@docker.com).
|
|
||||||
|
|
||||||
- type: checkboxes
|
|
||||||
attributes:
|
|
||||||
label: Contributing guidelines
|
|
||||||
description: >
|
|
||||||
Make sure you've read the contributing guidelines before proceeding.
|
|
||||||
options:
|
|
||||||
- label: I've read the [contributing guidelines](https://github.com/docker/metadata-action/blob/master/.github/CONTRIBUTING.md) and wholeheartedly agree
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: checkboxes
|
|
||||||
attributes:
|
|
||||||
label: "I've found a bug, and:"
|
|
||||||
description: |
|
|
||||||
Make sure that your request fulfills all of the following requirements.
|
|
||||||
If one requirement cannot be satisfied, explain in detail why.
|
|
||||||
options:
|
|
||||||
- label: The documentation does not mention anything about my problem
|
|
||||||
- label: There are no open or closed issues that are related to my problem
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Description
|
|
||||||
description: >
|
|
||||||
Provide a brief description of the bug in 1-2 sentences.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Expected behaviour
|
|
||||||
description: >
|
|
||||||
Describe precisely what you'd expect to happen.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Actual behaviour
|
|
||||||
description: >
|
|
||||||
Describe precisely what is actually happening.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: input
|
|
||||||
attributes:
|
|
||||||
label: Repository URL
|
|
||||||
description: >
|
|
||||||
Enter the URL of the repository where you are experiencing the
|
|
||||||
issue. If your repository is private, provide a link to a minimal
|
|
||||||
repository that reproduces the issue.
|
|
||||||
|
|
||||||
- type: input
|
|
||||||
attributes:
|
|
||||||
label: Workflow run URL
|
|
||||||
description: >
|
|
||||||
Enter the URL of the GitHub Action workflow run if public (e.g.
|
|
||||||
`https://github.com/<user>/<repo>/actions/runs/<id>`)
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: YAML workflow
|
|
||||||
description: |
|
|
||||||
Provide the YAML of the workflow that's causing the issue.
|
|
||||||
Make sure to remove any sensitive information.
|
|
||||||
render: yaml
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Workflow logs
|
|
||||||
description: >
|
|
||||||
[Attach](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/attaching-files)
|
|
||||||
the [log file of your workflow run](https://docs.github.com/en/actions/managing-workflow-runs/using-workflow-run-logs#downloading-logs)
|
|
||||||
and make sure to remove any sensitive information.
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: BuildKit logs
|
|
||||||
description: >
|
|
||||||
If applicable, provide the [BuildKit container logs](https://docs.docker.com/build/ci/github-actions/configure-builder/#buildkit-container-logs)
|
|
||||||
render: text
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Additional info
|
|
||||||
description: |
|
|
||||||
Provide any additional information that could be useful.
|
|
34
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
34
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
---
|
||||||
|
|
||||||
|
### Behaviour
|
||||||
|
|
||||||
|
#### Steps to reproduce this issue
|
||||||
|
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
|
||||||
|
#### Expected behaviour
|
||||||
|
|
||||||
|
> Tell us what should happen
|
||||||
|
|
||||||
|
#### Actual behaviour
|
||||||
|
|
||||||
|
> Tell us what happens instead
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
* Repository URL (if public):
|
||||||
|
* Build URL (if public):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
# paste your YAML workflow file here and remove sensitive data
|
||||||
|
```
|
||||||
|
|
||||||
|
### Logs
|
||||||
|
|
||||||
|
> Download the [log file of your build](https://docs.github.com/en/actions/managing-workflow-runs/using-workflow-run-logs#downloading-logs)
|
||||||
|
> and [attach it](https://docs.github.com/en/github/managing-your-work-on-github/file-attachments-on-issues-and-pull-requests) to this issue.
|
9
.github/ISSUE_TEMPLATE/config.yml
vendored
9
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,9 +0,0 @@
|
|||||||
# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
|
|
||||||
blank_issues_enabled: true
|
|
||||||
contact_links:
|
|
||||||
- name: Questions and Discussions
|
|
||||||
url: https://github.com/docker/metadata-action/discussions/new
|
|
||||||
about: Use Github Discussions to ask questions and/or open discussion topics.
|
|
||||||
- name: Documentation
|
|
||||||
url: https://docs.docker.com/build/ci/github-actions/
|
|
||||||
about: Read the documentation.
|
|
15
.github/ISSUE_TEMPLATE/feature.yml
vendored
15
.github/ISSUE_TEMPLATE/feature.yml
vendored
@ -1,15 +0,0 @@
|
|||||||
# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema
|
|
||||||
name: Feature request
|
|
||||||
description: Missing functionality? Come tell us about it!
|
|
||||||
labels:
|
|
||||||
- kind/enhancement
|
|
||||||
- status/triage
|
|
||||||
|
|
||||||
body:
|
|
||||||
- type: textarea
|
|
||||||
id: description
|
|
||||||
attributes:
|
|
||||||
label: Description
|
|
||||||
description: What is the feature you want to see?
|
|
||||||
validations:
|
|
||||||
required: true
|
|
12
.github/SECURITY.md
vendored
12
.github/SECURITY.md
vendored
@ -1,12 +0,0 @@
|
|||||||
# Reporting security issues
|
|
||||||
|
|
||||||
The project maintainers take security seriously. If you discover a security
|
|
||||||
issue, please bring it to their attention right away!
|
|
||||||
|
|
||||||
**Please _DO NOT_ file a public issue**, instead send your report privately to
|
|
||||||
[security@docker.com](mailto:security@docker.com).
|
|
||||||
|
|
||||||
Security reports are greatly appreciated, and we will publicly thank you for it.
|
|
||||||
We also like to send gifts—if you'd like Docker swag, make sure to let
|
|
||||||
us know. We currently do not offer a paid security bounty program, but are not
|
|
||||||
ruling it out in the future.
|
|
32
.github/SUPPORT.md
vendored
Normal file
32
.github/SUPPORT.md
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Support [](https://isitmaintained.com/project/docker/metadata-action)
|
||||||
|
|
||||||
|
## Reporting an issue
|
||||||
|
|
||||||
|
Please do a search in [open issues](https://github.com/docker/metadata-action/issues?utf8=%E2%9C%93&q=) to see if the
|
||||||
|
issue or feature request has already been filed.
|
||||||
|
|
||||||
|
If you find your issue already exists, make relevant comments and add your
|
||||||
|
[reaction](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments). Use a reaction in place
|
||||||
|
of a "+1" comment.
|
||||||
|
|
||||||
|
:+1: - upvote
|
||||||
|
|
||||||
|
:-1: - downvote
|
||||||
|
|
||||||
|
If you cannot find an existing issue that describes your bug or feature, submit an issue using the guidelines below.
|
||||||
|
|
||||||
|
## Writing good bug reports and feature requests
|
||||||
|
|
||||||
|
File a single issue per problem and feature request.
|
||||||
|
|
||||||
|
* Do not enumerate multiple bugs or feature requests in the same issue.
|
||||||
|
* Do not add your issue as a comment to an existing issue unless it's for the identical input. Many issues look similar, but have different causes.
|
||||||
|
|
||||||
|
The more information you can provide, the more likely someone will be successful reproducing the issue and finding a fix.
|
||||||
|
|
||||||
|
You are now ready to [create a new issue](https://github.com/docker/metadata-action/issues/new/choose)!
|
||||||
|
|
||||||
|
## Closure policy
|
||||||
|
|
||||||
|
* Issues that don't have the information requested above (when applicable) will be closed immediately and the poster directed to the support guidelines.
|
||||||
|
* Issues that go a week without a response from original poster are subject to closure at our discretion.
|
1
.github/dependabot.yml
vendored
1
.github/dependabot.yml
vendored
@ -11,7 +11,6 @@ updates:
|
|||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
versioning-strategy: "increase"
|
|
||||||
allow:
|
allow:
|
||||||
- dependency-type: "production"
|
- dependency-type: "production"
|
||||||
labels:
|
labels:
|
||||||
|
340
.github/workflows/ci.yml
vendored
340
.github/workflows/ci.yml
vendored
@ -1,12 +1,8 @@
|
|||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 10 * * *'
|
- cron: '0 */4 * * *' # every 4 hours
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
@ -14,42 +10,20 @@ on:
|
|||||||
tags:
|
tags:
|
||||||
- 'v*.*.*'
|
- 'v*.*.*'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
- 'releases/v*'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOCKER_IMAGE: localhost:5000/name/app
|
DOCKER_IMAGE: localhost:5000/name/app
|
||||||
BUILDX_VERSION: latest
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
context:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
context:
|
|
||||||
- workflow
|
|
||||||
- git
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
context: ${{ matrix.context }}
|
|
||||||
|
|
||||||
multi-images:
|
multi-images:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -80,13 +54,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -116,13 +84,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -150,13 +112,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -181,13 +137,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -204,13 +154,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -220,18 +164,12 @@ jobs:
|
|||||||
name=ghcr.io/name/app,enable=${{ github.event_name == 'pull_request' }}
|
name=ghcr.io/name/app,enable=${{ github.event_name == 'pull_request' }}
|
||||||
name=ghcr.io/name/release,enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
name=ghcr.io/name/release,enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
|
||||||
custom-labels-annotations:
|
labels:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -244,24 +182,13 @@ jobs:
|
|||||||
org.opencontainers.image.title=MyCustomTitle
|
org.opencontainers.image.title=MyCustomTitle
|
||||||
org.opencontainers.image.description=this is a "good" example
|
org.opencontainers.image.description=this is a "good" example
|
||||||
org.opencontainers.image.vendor=MyCompany
|
org.opencontainers.image.vendor=MyCompany
|
||||||
annotations: |
|
|
||||||
maintainer=Foo
|
|
||||||
org.opencontainers.image.title=MyFooTitle
|
|
||||||
org.opencontainers.image.description=this is a "foo" example
|
|
||||||
org.opencontainers.image.vendor=MyFooCompany
|
|
||||||
|
|
||||||
global-exps:
|
global-exps:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -269,8 +196,6 @@ jobs:
|
|||||||
images: |
|
images: |
|
||||||
${{ env.DOCKER_IMAGE }}
|
${{ env.DOCKER_IMAGE }}
|
||||||
ghcr.io/name/app
|
ghcr.io/name/app
|
||||||
labels: |
|
|
||||||
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
|
|
||||||
tags: |
|
tags: |
|
||||||
type=sha
|
type=sha
|
||||||
type=raw,value=gexp-branch-{{branch}}
|
type=raw,value=gexp-branch-{{branch}}
|
||||||
@ -284,13 +209,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@ -308,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
|
||||||
@ -319,13 +246,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver-opts: network=host
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
@ -342,9 +263,17 @@ jobs:
|
|||||||
type=semver,pattern=v{{major}}.{{minor}}
|
type=semver,pattern=v{{major}}.{{minor}}
|
||||||
type=semver,pattern=v{{major}}
|
type=semver,pattern=v{{major}}
|
||||||
type=sha
|
type=sha
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
driver-opts: network=host
|
||||||
-
|
-
|
||||||
name: Build and push to local registry
|
name: Build and push to local registry
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: ./test
|
context: ./test
|
||||||
file: ./test/Dockerfile
|
file: ./test/Dockerfile
|
||||||
@ -361,18 +290,17 @@ jobs:
|
|||||||
name: Check manifest
|
name: Check manifest
|
||||||
run: |
|
run: |
|
||||||
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
|
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
|
||||||
|
-
|
||||||
|
name: Dump context
|
||||||
|
if: always()
|
||||||
|
uses: crazy-max/ghaction-dump-context@v1
|
||||||
|
|
||||||
bake:
|
bake:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
@ -390,14 +318,19 @@ jobs:
|
|||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
type=semver,pattern={{major}}
|
type=semver,pattern={{major}}
|
||||||
type=sha
|
type=sha
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./test/docker-bake.hcl
|
./test/docker-bake.hcl
|
||||||
cwd://${{ steps.docker_meta.outputs.bake-file-tags }}
|
${{ steps.docker_meta.outputs.bake-file }}
|
||||||
cwd://${{ steps.docker_meta.outputs.bake-file-labels }}
|
|
||||||
targets: |
|
targets: |
|
||||||
release
|
release
|
||||||
|
|
||||||
@ -412,13 +345,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@ -430,7 +357,7 @@ jobs:
|
|||||||
sep-tags: ${{ matrix.sep }}
|
sep-tags: ${{ matrix.sep }}
|
||||||
-
|
-
|
||||||
name: Tags
|
name: Tags
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
console.log(`${{ steps.meta.outputs.tags }}`);
|
console.log(`${{ steps.meta.outputs.tags }}`);
|
||||||
@ -440,13 +367,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@ -457,11 +378,9 @@ jobs:
|
|||||||
ghcr.io/name/app
|
ghcr.io/name/app
|
||||||
labels: |
|
labels: |
|
||||||
maintainer=CrazyMax
|
maintainer=CrazyMax
|
||||||
annotations: |
|
|
||||||
maintainer=Foo
|
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: ./test
|
context: ./test
|
||||||
file: ./test/output.Dockerfile
|
file: ./test/output.Dockerfile
|
||||||
@ -469,165 +388,4 @@ jobs:
|
|||||||
DOCKER_METADATA_OUTPUT_VERSION
|
DOCKER_METADATA_OUTPUT_VERSION
|
||||||
DOCKER_METADATA_OUTPUT_TAGS
|
DOCKER_METADATA_OUTPUT_TAGS
|
||||||
DOCKER_METADATA_OUTPUT_LABELS
|
DOCKER_METADATA_OUTPUT_LABELS
|
||||||
DOCKER_METADATA_OUTPUT_ANNOTATIONS
|
|
||||||
DOCKER_METADATA_OUTPUT_JSON
|
DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
|
||||||
no-output-env:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
DOCKER_METADATA_SET_OUTPUT_ENV: false
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
${{ env.DOCKER_IMAGE }}
|
|
||||||
ghcr.io/name/app
|
|
||||||
labels: |
|
|
||||||
maintainer=CrazyMax
|
|
||||||
annotations: |
|
|
||||||
maintainer=Foo
|
|
||||||
-
|
|
||||||
name: No output environment variables set
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
[[ "$(printenv | grep "^DOCKER_METADATA_OUTPUT_" | wc -l)" -eq 0 ]] || exit 1
|
|
||||||
|
|
||||||
bake-annotations:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
id: docker_meta
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
${{ env.DOCKER_IMAGE }}
|
|
||||||
ghcr.io/name/app
|
|
||||||
tags: |
|
|
||||||
type=schedule
|
|
||||||
type=ref,event=branch
|
|
||||||
type=ref,event=tag
|
|
||||||
type=ref,event=pr
|
|
||||||
type=semver,pattern={{version}}
|
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
type=semver,pattern={{major}}
|
|
||||||
type=sha
|
|
||||||
env:
|
|
||||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
|
||||||
-
|
|
||||||
name: Build
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
./test/docker-bake.hcl
|
|
||||||
cwd://${{ steps.docker_meta.outputs.bake-file-tags }}
|
|
||||||
cwd://${{ steps.docker_meta.outputs.bake-file-annotations }}
|
|
||||||
targets: |
|
|
||||||
release
|
|
||||||
|
|
||||||
no-images:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
tags: |
|
|
||||||
type=schedule
|
|
||||||
type=ref,event=branch
|
|
||||||
type=ref,event=tag
|
|
||||||
type=ref,event=pr
|
|
||||||
type=sha
|
|
||||||
-
|
|
||||||
name: Print envs
|
|
||||||
run: env|sort
|
|
||||||
|
|
||||||
bake-path-context:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
id: docker_meta
|
|
||||||
uses: ./
|
|
||||||
-
|
|
||||||
name: Build
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
source: .
|
|
||||||
files: |
|
|
||||||
./test/docker-bake.hcl
|
|
||||||
${{ steps.docker_meta.outputs.bake-file-tags }}
|
|
||||||
${{ steps.docker_meta.outputs.bake-file-labels }}
|
|
||||||
targets: |
|
|
||||||
release
|
|
||||||
|
|
||||||
sha-short:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
short-length:
|
|
||||||
- ''
|
|
||||||
- 16
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
|
||||||
driver: docker
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
${{ env.DOCKER_IMAGE }}
|
|
||||||
ghcr.io/name/app
|
|
||||||
tags: |
|
|
||||||
type=sha
|
|
||||||
env:
|
|
||||||
DOCKER_METADATA_SHORT_SHA_LENGTH: ${{ matrix.short-length }}
|
|
||||||
|
|
||||||
dump:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Dump context
|
|
||||||
uses: crazy-max/ghaction-dump-context@v2
|
|
||||||
|
21
.github/workflows/publish.yml
vendored
21
.github/workflows/publish.yml
vendored
@ -1,21 +0,0 @@
|
|||||||
name: publish
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types:
|
|
||||||
- published
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
id-token: write
|
|
||||||
packages: write
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: Publish
|
|
||||||
uses: actions/publish-immutable-action@v0.0.4
|
|
20
.github/workflows/test.yml
vendored
20
.github/workflows/test.yml
vendored
@ -1,28 +1,34 @@
|
|||||||
name: test
|
name: test
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
- 'releases/v*'
|
- 'releases/v*'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
- 'releases/v*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
name: Validate
|
||||||
|
uses: docker/bake-action@v2
|
||||||
|
with:
|
||||||
|
targets: validate
|
||||||
-
|
-
|
||||||
name: Test
|
name: Test
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v2
|
||||||
with:
|
with:
|
||||||
targets: test
|
targets: test
|
||||||
-
|
-
|
||||||
name: Upload coverage
|
name: Upload coverage
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
file: ./coverage/clover.xml
|
file: ./coverage/clover.xml
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
|
43
.github/workflows/validate.yml
vendored
43
.github/workflows/validate.yml
vendored
@ -1,43 +0,0 @@
|
|||||||
name: validate
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'master'
|
|
||||||
- 'releases/v*'
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
prepare:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
targets: ${{ steps.generate.outputs.targets }}
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: List targets
|
|
||||||
id: generate
|
|
||||||
uses: docker/bake-action/subaction/list-targets@v6
|
|
||||||
with:
|
|
||||||
target: validate
|
|
||||||
|
|
||||||
validate:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- prepare
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Validate
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
targets: ${{ matrix.target }}
|
|
71
.gitignore
vendored
71
.gitignore
vendored
@ -1,5 +1,12 @@
|
|||||||
# https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
/.dev
|
||||||
|
node_modules/
|
||||||
|
lib
|
||||||
|
|
||||||
|
# Jetbrains
|
||||||
|
/.idea
|
||||||
|
/*.iml
|
||||||
|
|
||||||
|
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
@ -7,7 +14,6 @@ npm-debug.log*
|
|||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
@ -18,14 +24,34 @@ pids
|
|||||||
*.seed
|
*.seed
|
||||||
*.pid.lock
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
# Coverage directory used by tools like istanbul
|
||||||
coverage
|
coverage
|
||||||
*.lcov
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
# Dependency directories
|
# Dependency directories
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
# TypeScript cache
|
# TypeScript cache
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
||||||
@ -35,19 +61,36 @@ jspm_packages/
|
|||||||
# Optional eslint cache
|
# Optional eslint cache
|
||||||
.eslintcache
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
# Yarn Integrity file
|
# Yarn Integrity file
|
||||||
.yarn-integrity
|
.yarn-integrity
|
||||||
|
|
||||||
# dotenv environment variable files
|
# dotenv environment variables file
|
||||||
.env
|
.env
|
||||||
.env.development.local
|
.env.test
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# yarn v2
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
.yarn/cache
|
.cache
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
# next.js build output
|
||||||
.yarn/install-state.gz
|
.next
|
||||||
.pnp.*
|
|
||||||
|
# nuxt.js build output
|
||||||
|
.nuxt
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/
|
|
541
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
541
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
File diff suppressed because one or more lines are too long
13
.yarnrc.yml
13
.yarnrc.yml
@ -1,13 +0,0 @@
|
|||||||
logFilters:
|
|
||||||
- code: YN0013
|
|
||||||
level: discard
|
|
||||||
- code: YN0019
|
|
||||||
level: discard
|
|
||||||
- code: YN0076
|
|
||||||
level: discard
|
|
||||||
|
|
||||||
nodeLinker: node-modules
|
|
||||||
|
|
||||||
plugins:
|
|
||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
|
255
README.md
255
README.md
@ -22,7 +22,6 @@ ___
|
|||||||
* [inputs](#inputs)
|
* [inputs](#inputs)
|
||||||
* [outputs](#outputs)
|
* [outputs](#outputs)
|
||||||
* [environment variables](#environment-variables)
|
* [environment variables](#environment-variables)
|
||||||
* [`context` input](#context-input)
|
|
||||||
* [`images` input](#images-input)
|
* [`images` input](#images-input)
|
||||||
* [`flavor` input](#flavor-input)
|
* [`flavor` input](#flavor-input)
|
||||||
* [`tags` input](#tags-input)
|
* [`tags` input](#tags-input)
|
||||||
@ -45,11 +44,9 @@ ___
|
|||||||
* [`{{base_ref}}`](#base_ref)
|
* [`{{base_ref}}`](#base_ref)
|
||||||
* [`{{is_default_branch}}`](#is_default_branch)
|
* [`{{is_default_branch}}`](#is_default_branch)
|
||||||
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
|
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
|
||||||
* [`{{commit_date '<format>' tz='<timezone>'}}`](#commit_date-format-tztimezone)
|
|
||||||
* [Major version zero](#major-version-zero)
|
* [Major version zero](#major-version-zero)
|
||||||
* [JSON output object](#json-output-object)
|
* [JSON output object](#json-output-object)
|
||||||
* [Overwrite labels and annotations](#overwrite-labels-and-annotations)
|
* [Overwrite labels](#overwrite-labels)
|
||||||
* [Annotations](#annotations)
|
|
||||||
* [Contributing](#contributing)
|
* [Contributing](#contributing)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -76,23 +73,23 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: name/app
|
images: name/app
|
||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@ -130,11 +127,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
name/app
|
name/app
|
||||||
@ -146,13 +143,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@ -206,10 +203,13 @@ jobs:
|
|||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
name/app
|
name/app
|
||||||
@ -221,16 +221,16 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./docker-bake.hcl
|
./docker-bake.hcl
|
||||||
cwd://${{ steps.meta.outputs.bake-file }}
|
${{ steps.meta.outputs.bake-file }}
|
||||||
targets: build
|
targets: build
|
||||||
```
|
```
|
||||||
|
|
||||||
Content of `${{ steps.meta.outputs.bake-file }}` file, combining tags and
|
Content of `${{ steps.meta.outputs.bake-file }}` file will look like this with
|
||||||
labels, will look like this with `refs/tags/v1.2.3` ref:
|
`refs/tags/v1.2.3` ref:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -261,27 +261,11 @@ labels, will look like this with `refs/tags/v1.2.3` ref:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use the `bake-file-tags` and `bake-file-labels` outputs if you
|
|
||||||
just want to use tags and/or labels respectively. The following example is
|
|
||||||
similar to the previous one:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
-
|
|
||||||
name: Build
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
./docker-bake.hcl
|
|
||||||
cwd://${{ steps.meta.outputs.bake-file-tags }}
|
|
||||||
cwd://${{ steps.meta.outputs.bake-file-labels }}
|
|
||||||
targets: build
|
|
||||||
```
|
|
||||||
|
|
||||||
## Customizing
|
## Customizing
|
||||||
|
|
||||||
### inputs
|
### inputs
|
||||||
|
|
||||||
The following inputs can be used as `step.with` keys:
|
Following inputs can be used as `step.with` keys
|
||||||
|
|
||||||
> `List` type is a newline-delimited string
|
> `List` type is a newline-delimited string
|
||||||
> ```yaml
|
> ```yaml
|
||||||
@ -291,49 +275,40 @@ The following inputs can be used as `step.with` keys:
|
|||||||
> org.opencontainers.image.vendor=MyCompany
|
> org.opencontainers.image.vendor=MyCompany
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|-------------------|--------|------------------------------------------------------------------------------|
|
|---------------------|--------|----------------------------------------------------------|
|
||||||
| `context` | String | Where to get context data. Allowed options are: `workflow` (default), `git`. |
|
| `images` | List | List of Docker images to use as base name for tags |
|
||||||
| `images` | List | List of Docker images to use as base name for tags |
|
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
||||||
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
||||||
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
| `labels` | List | List of custom labels |
|
||||||
| `labels` | List | List of custom labels |
|
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
||||||
| `annotations` | List | List of custom annotations |
|
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
||||||
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
|
||||||
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
|
||||||
| `sep-annotations` | String | Separator to use for annotations output (default `\n`) |
|
|
||||||
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
|
|
||||||
|
|
||||||
### outputs
|
### outputs
|
||||||
|
|
||||||
The following outputs are available:
|
Following outputs are available
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|-------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|---------------|---------|--------------------------------------------------------------------------------------------|
|
||||||
| `version` | String | Docker image version |
|
| `version` | String | Docker image version |
|
||||||
| `tags` | String | Docker tags |
|
| `tags` | String | Docker tags |
|
||||||
| `labels` | String | Docker labels |
|
| `labels` | String | Docker labels |
|
||||||
| `annotations` | String | [Annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
|
| `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-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
|
|
||||||
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
|
|
||||||
| `bake-file-annotations` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
|
|
||||||
|
|
||||||
Alternatively, each output is also exported as an environment variable when `DOCKER_METADATA_SET_OUTPUT_ENV` is `true`:
|
Alternatively, each output is also exported as an environment variable:
|
||||||
|
|
||||||
* `DOCKER_METADATA_OUTPUT_VERSION`
|
* `DOCKER_METADATA_OUTPUT_VERSION`
|
||||||
* `DOCKER_METADATA_OUTPUT_TAGS`
|
* `DOCKER_METADATA_OUTPUT_TAGS`
|
||||||
* `DOCKER_METADATA_OUTPUT_LABELS`
|
* `DOCKER_METADATA_OUTPUT_LABELS`
|
||||||
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS`
|
|
||||||
* `DOCKER_METADATA_OUTPUT_JSON`
|
* `DOCKER_METADATA_OUTPUT_JSON`
|
||||||
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_TAGS`
|
* `DOCKER_METADATA_OUTPUT_BAKE_FILE`
|
||||||
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_LABELS`
|
|
||||||
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS`
|
|
||||||
|
|
||||||
So it can be used with our [Docker Build Push action](https://github.com/docker/build-push-action/):
|
So it can be used with our [Docker Build Push action](https://github.com/docker/build-push-action/):
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: docker/build-push-action@v6
|
- uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
build-args: |
|
build-args: |
|
||||||
DOCKER_METADATA_OUTPUT_JSON
|
DOCKER_METADATA_OUTPUT_JSON
|
||||||
@ -341,26 +316,9 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/
|
|||||||
|
|
||||||
### environment variables
|
### environment variables
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|--------------------------------------|--------|----------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------------|------|------------------------------------------------------------------------------------------------------------|
|
||||||
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
|
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
|
||||||
| `DOCKER_METADATA_SHORT_SHA_LENGTH` | Number | Specifies the length of the [short commit SHA](#typesha) to ensure uniqueness. Default is `7`, but can be increased for larger repositories. |
|
|
||||||
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
|
|
||||||
| `DOCKER_METADATA_SET_OUTPUT_ENV` | Bool | If `true`, sets each output as an environment variable (default `true`) |
|
|
||||||
|
|
||||||
## `context` input
|
|
||||||
|
|
||||||
`context` defines where to get context metadata:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# default
|
|
||||||
context: workflow
|
|
||||||
# or
|
|
||||||
context: git
|
|
||||||
```
|
|
||||||
|
|
||||||
* `workflow`: Get context metadata from the workflow (GitHub context). See https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
|
||||||
* `git`: Get context metadata from the workflow and overrides some of them with current Git context, such as `ref` and `sha`.
|
|
||||||
|
|
||||||
## `images` input
|
## `images` input
|
||||||
|
|
||||||
@ -385,8 +343,6 @@ images: |
|
|||||||
* `name=<string>` image base name
|
* `name=<string>` image base name
|
||||||
* `enable=<true|false>` enable this entry (default `true`)
|
* `enable=<true|false>` enable this entry (default `true`)
|
||||||
|
|
||||||
If `images` is empty, tags will be generated without base name.
|
|
||||||
|
|
||||||
## `flavor` input
|
## `flavor` input
|
||||||
|
|
||||||
`flavor` defines a global behavior for [`tags`](#tags-input):
|
`flavor` defines a global behavior for [`tags`](#tags-input):
|
||||||
@ -705,26 +661,7 @@ tags: |
|
|||||||
type=sha,format=long
|
type=sha,format=long
|
||||||
```
|
```
|
||||||
|
|
||||||
Output Git short commit (or long if specified) as Docker tag like
|
Output Git short commit (or long if specified) as Docker tag like `sha-ad132f5`.
|
||||||
`sha-860c190`.
|
|
||||||
|
|
||||||
By default, the length of the short commit SHA is `7` characters. You can
|
|
||||||
increase this length for larger repositories by setting the
|
|
||||||
[`DOCKER_METADATA_SHORT_SHA_LENGTH` environment variable](#environment-variables):
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
name/app
|
|
||||||
tags: |
|
|
||||||
type=sha
|
|
||||||
env:
|
|
||||||
DOCKER_METADATA_SHORT_SHA_LENGTH: 12
|
|
||||||
```
|
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@ -758,7 +695,6 @@ generated by default (`auto` mode) for:
|
|||||||
|
|
||||||
* [`type=ref,event=tag`](#typeref)
|
* [`type=ref,event=tag`](#typeref)
|
||||||
* [`type=semver,pattern=...`](#typesemver)
|
* [`type=semver,pattern=...`](#typesemver)
|
||||||
* [`type=pep440,pattern=...`](#typepep440)
|
|
||||||
* [`type=match,pattern=...`](#typematch)
|
* [`type=match,pattern=...`](#typematch)
|
||||||
|
|
||||||
For conditionally tagging with latest for a specific branch name, e.g. if your
|
For conditionally tagging with latest for a specific branch name, e.g. if your
|
||||||
@ -800,8 +736,7 @@ Each tags `type` attribute has a default priority:
|
|||||||
### Global expressions
|
### Global expressions
|
||||||
|
|
||||||
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions
|
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions
|
||||||
for `prefix`, `suffix`, `value` and `enable` attributes of `tags` input are
|
for `prefix`, `suffix`, `value` and `enable` attributes are available:
|
||||||
available:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
tags: |
|
tags: |
|
||||||
@ -811,13 +746,6 @@ tags: |
|
|||||||
type=raw,value=mytag-{{branch}}-{{sha}}
|
type=raw,value=mytag-{{branch}}-{{sha}}
|
||||||
```
|
```
|
||||||
|
|
||||||
They can also be applied to `labels` and `annotations` inputs:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
labels: |
|
|
||||||
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `{{branch}}`
|
#### `{{branch}}`
|
||||||
|
|
||||||
Returns the branch name that triggered the workflow run. Will be empty if not
|
Returns the branch name that triggered the workflow run. Will be empty if not
|
||||||
@ -880,20 +808,6 @@ Default `tz` is UTC.
|
|||||||
| `{{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
|
| `{{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
|
||||||
| `{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
|
| `{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
|
||||||
|
|
||||||
#### `{{commit_date '<format>' tz='<timezone>'}}`
|
|
||||||
|
|
||||||
Returns the date when the current git commit is committed, rendered by its
|
|
||||||
[moment format](https://momentjs.com/docs/#/displaying/format/). It falls back
|
|
||||||
to the current date if the commit date is not available.
|
|
||||||
|
|
||||||
Default `tz` is UTC.
|
|
||||||
|
|
||||||
| Expression | Output example |
|
|
||||||
|-----------------------------------------------------|-----------------------------------------|
|
|
||||||
| `{{commit_date 'YYYYMMDD'}}` | `20200110` |
|
|
||||||
| `{{commit_date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
|
|
||||||
| `{{commit_date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
|
|
||||||
|
|
||||||
### Major version zero
|
### Major version zero
|
||||||
|
|
||||||
Major version zero (`0.y.z`) is for initial development and **may** change at
|
Major version zero (`0.y.z`) is for initial development and **may** change at
|
||||||
@ -921,13 +835,13 @@ that you can reuse them further in your workflow using the [`fromJSON` function]
|
|||||||
```yaml
|
```yaml
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v4
|
||||||
id: meta
|
id: meta
|
||||||
with:
|
with:
|
||||||
images: name/app
|
images: name/app
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
@ -937,17 +851,16 @@ that you can reuse them further in your workflow using the [`fromJSON` function]
|
|||||||
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
|
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Overwrite labels and annotations
|
### Overwrite labels
|
||||||
|
|
||||||
If some [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
|
If some [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
|
||||||
generated are not suitable as labels/annotations, you can overwrite them like
|
labels generated are not suitable, you can overwrite them like this:
|
||||||
this:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: name/app
|
images: name/app
|
||||||
labels: |
|
labels: |
|
||||||
@ -957,78 +870,6 @@ this:
|
|||||||
org.opencontainers.image.vendor=MyCompany
|
org.opencontainers.image.vendor=MyCompany
|
||||||
```
|
```
|
||||||
|
|
||||||
### Annotations
|
|
||||||
|
|
||||||
Since Buildx 0.12, it is possible to set annotations to your image through the
|
|
||||||
`--annotation` flag.
|
|
||||||
|
|
||||||
With the [`build-push-action`](https://github.com/docker/build-push-action/),
|
|
||||||
you can set the `annotations` input with the value of the `annotations` output
|
|
||||||
of the `metadata-action`:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: name/app
|
|
||||||
-
|
|
||||||
name: Build and push
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
|
||||||
```
|
|
||||||
|
|
||||||
The same can be done with the [`bake-action`](https://github.com/docker/bake-action/):
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: name/app
|
|
||||||
-
|
|
||||||
name: Build
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
./docker-bake.hcl
|
|
||||||
cwd://${{ steps.meta.outputs.bake-file-tags }}
|
|
||||||
cwd://${{ steps.meta.outputs.bake-file-annotations }}
|
|
||||||
targets: build
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that annotations can be attached at many different levels within a manifest.
|
|
||||||
By default, the generated annotations will be attached to image manifests,
|
|
||||||
but different registries may expect annotations at different places;
|
|
||||||
a common practice is to read annotations at _image indexes_ if present,
|
|
||||||
which are often used by multi-arch builds to index platform-specific images.
|
|
||||||
If you want to specify level(s) for your annotations, you can use the
|
|
||||||
[`DOCKER_METADATA_ANNOTATIONS_LEVELS` environment variable](#environment-variables)
|
|
||||||
with a comma separated list of all levels the annotations should be attached to (defaults to `manifest`).
|
|
||||||
The following configuration demonstrates the ability to attach annotations to both image manifests and image indexes,
|
|
||||||
though your registry may only need annotations at the index level. (That is, `index` alone may be enough.)
|
|
||||||
Please consult the documentation of your registry.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
-
|
|
||||||
name: Docker meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: name/app
|
|
||||||
env:
|
|
||||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
|
||||||
-
|
|
||||||
name: Build and push
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
|
||||||
```
|
|
||||||
|
|
||||||
More information about annotations in the [BuildKit documentation](https://github.com/moby/buildkit/blob/master/docs/annotations.md).
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Want to contribute? Awesome! You can find information about contributing to
|
Want to contribute? Awesome! You can find information about contributing to
|
||||||
|
300
UPGRADE.md
Normal file
300
UPGRADE.md
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
# Upgrade notes
|
||||||
|
|
||||||
|
## v2 to v3
|
||||||
|
|
||||||
|
* Repository has been moved to docker org. Replace `crazy-max/ghaction-docker-meta@v2`
|
||||||
|
with `docker/metadata-action@v4`
|
||||||
|
* The default bake target has been changed: `ghaction-docker-meta` > `docker-metadata-action`
|
||||||
|
|
||||||
|
## v1 to v2
|
||||||
|
|
||||||
|
* [inputs](#inputs)
|
||||||
|
* [`tag-sha`](#tag-sha)
|
||||||
|
* [`tag-edge` / `tag-edge-branch`](#tag-edge--tag-edge-branch)
|
||||||
|
* [`tag-semver`](#tag-semver)
|
||||||
|
* [`tag-match` / `tag-match-group`](#tag-match--tag-match-group)
|
||||||
|
* [`tag-latest`](#tag-latest)
|
||||||
|
* [`tag-schedule`](#tag-schedule)
|
||||||
|
* [`tag-custom` / `tag-custom-only`](#tag-custom--tag-custom-only)
|
||||||
|
* [`label-custom`](#label-custom)
|
||||||
|
* [Basic workflow](#basic-workflow)
|
||||||
|
* [Semver workflow](#semver-workflow)
|
||||||
|
|
||||||
|
### inputs
|
||||||
|
|
||||||
|
| New | Unchanged | Removed |
|
||||||
|
|------------|-----------------|--------------------|
|
||||||
|
| `tags` | `images` | `tag-sha` |
|
||||||
|
| `flavor` | `sep-tags` | `tag-edge` |
|
||||||
|
| `labels` | `sep-labels` | `tag-edge-branch` |
|
||||||
|
| | | `tag-semver` |
|
||||||
|
| | | `tag-match` |
|
||||||
|
| | | `tag-match-group` |
|
||||||
|
| | | `tag-latest` |
|
||||||
|
| | | `tag-schedule` |
|
||||||
|
| | | `tag-custom` |
|
||||||
|
| | | `tag-custom-only` |
|
||||||
|
| | | `label-custom` |
|
||||||
|
|
||||||
|
#### `tag-sha`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tags: |
|
||||||
|
type=sha
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `tag-edge` / `tag-edge-branch`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tags: |
|
||||||
|
# default branch
|
||||||
|
type=edge
|
||||||
|
# specify branch
|
||||||
|
type=edge,branch=main
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `tag-semver`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tags: |
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `tag-match` / `tag-match-group`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tags: |
|
||||||
|
type=match,pattern=v(.*),group=1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `tag-latest`
|
||||||
|
|
||||||
|
`tag-latest` is now handled through the [`flavor` input](README.md#flavor-input):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
flavor: |
|
||||||
|
latest=auto
|
||||||
|
```
|
||||||
|
|
||||||
|
See also the notes about ["latest tag" behavior](README.md#latest-tag)
|
||||||
|
|
||||||
|
#### `tag-schedule`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tags: |
|
||||||
|
# default tag (nightly)
|
||||||
|
type=schedule
|
||||||
|
# specific pattern
|
||||||
|
type=schedule,pattern={{date 'YYYYMMDD'}}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `tag-custom` / `tag-custom-only`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tags: |
|
||||||
|
type=raw,value=foo
|
||||||
|
type=raw,value=bar
|
||||||
|
# or
|
||||||
|
type=raw,foo
|
||||||
|
type=raw,bar
|
||||||
|
# or
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `label-custom`
|
||||||
|
|
||||||
|
Same behavior for `labels`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
labels: |
|
||||||
|
maintainer=CrazyMax
|
||||||
|
```
|
||||||
|
|
||||||
|
### Basic workflow
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# v1
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v1
|
||||||
|
with:
|
||||||
|
images: name/app
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# v2
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
images: name/app
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Semver workflow
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# v1
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v1
|
||||||
|
with:
|
||||||
|
images: name/app
|
||||||
|
tag-semver: |
|
||||||
|
{{version}}
|
||||||
|
{{major}}.{{minor}}
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# v2
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
images: name/app
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
```
|
@ -1,223 +0,0 @@
|
|||||||
import {jest} from '@jest/globals';
|
|
||||||
|
|
||||||
export const context = {
|
|
||||||
repo: {
|
|
||||||
owner: 'docker',
|
|
||||||
repo: 'actions-toolkit'
|
|
||||||
},
|
|
||||||
ref: 'refs/heads/master',
|
|
||||||
runId: 123,
|
|
||||||
payload: {
|
|
||||||
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
|
||||||
base_ref: null,
|
|
||||||
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
|
||||||
commits: [
|
|
||||||
{
|
|
||||||
author: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
committer: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
distinct: true,
|
|
||||||
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
|
||||||
message: 'hello dev',
|
|
||||||
timestamp: '2022-04-19T11:27:24+02:00',
|
|
||||||
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
|
||||||
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
compare: 'https://github.com/docker/test-docker-action/compare/5f3331d7f704...860c1904a1ce',
|
|
||||||
created: false,
|
|
||||||
deleted: false,
|
|
||||||
forced: false,
|
|
||||||
head_commit: {
|
|
||||||
author: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
committer: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
distinct: true,
|
|
||||||
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
|
||||||
message: 'hello dev',
|
|
||||||
timestamp: '2022-04-19T11:27:24+02:00',
|
|
||||||
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
|
||||||
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
|
||||||
},
|
|
||||||
organization: {
|
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
|
||||||
description: 'Docker helps developers bring their ideas to life by conquering the complexity of app development.',
|
|
||||||
events_url: 'https://api.github.com/orgs/docker/events',
|
|
||||||
hooks_url: 'https://api.github.com/orgs/docker/hooks',
|
|
||||||
id: 5429470,
|
|
||||||
issues_url: 'https://api.github.com/orgs/docker/issues',
|
|
||||||
login: 'docker',
|
|
||||||
members_url: 'https://api.github.com/orgs/docker/members{/member}',
|
|
||||||
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
|
||||||
public_members_url: 'https://api.github.com/orgs/docker/public_members{/member}',
|
|
||||||
repos_url: 'https://api.github.com/orgs/docker/repos',
|
|
||||||
url: 'https://api.github.com/orgs/docker'
|
|
||||||
},
|
|
||||||
pusher: {
|
|
||||||
email: 'github@crazymax.dev',
|
|
||||||
name: 'crazy-max'
|
|
||||||
},
|
|
||||||
ref: 'refs/heads/dev',
|
|
||||||
repository: {
|
|
||||||
allow_forking: true,
|
|
||||||
archive_url: 'https://api.github.com/repos/docker/test-docker-action/{archive_format}{/ref}',
|
|
||||||
archived: false,
|
|
||||||
assignees_url: 'https://api.github.com/repos/docker/test-docker-action/assignees{/user}',
|
|
||||||
blobs_url: 'https://api.github.com/repos/docker/test-docker-action/git/blobs{/sha}',
|
|
||||||
branches_url: 'https://api.github.com/repos/docker/test-docker-action/branches{/branch}',
|
|
||||||
clone_url: 'https://github.com/docker/test-docker-action.git',
|
|
||||||
collaborators_url: 'https://api.github.com/repos/docker/test-docker-action/collaborators{/collaborator}',
|
|
||||||
comments_url: 'https://api.github.com/repos/docker/test-docker-action/comments{/number}',
|
|
||||||
commits_url: 'https://api.github.com/repos/docker/test-docker-action/commits{/sha}',
|
|
||||||
compare_url: 'https://api.github.com/repos/docker/test-docker-action/compare/{base}...{head}',
|
|
||||||
contents_url: 'https://api.github.com/repos/docker/test-docker-action/contents/{+path}',
|
|
||||||
contributors_url: 'https://api.github.com/repos/docker/test-docker-action/contributors',
|
|
||||||
created_at: 1596792180,
|
|
||||||
default_branch: 'master',
|
|
||||||
deployments_url: 'https://api.github.com/repos/docker/test-docker-action/deployments',
|
|
||||||
description: 'Test "Docker" Actions',
|
|
||||||
disabled: false,
|
|
||||||
downloads_url: 'https://api.github.com/repos/docker/test-docker-action/downloads',
|
|
||||||
events_url: 'https://api.github.com/repos/docker/test-docker-action/events',
|
|
||||||
fork: false,
|
|
||||||
forks: 1,
|
|
||||||
forks_count: 1,
|
|
||||||
forks_url: 'https://api.github.com/repos/docker/test-docker-action/forks',
|
|
||||||
full_name: 'docker/test-docker-action',
|
|
||||||
git_commits_url: 'https://api.github.com/repos/docker/test-docker-action/git/commits{/sha}',
|
|
||||||
git_refs_url: 'https://api.github.com/repos/docker/test-docker-action/git/refs{/sha}',
|
|
||||||
git_tags_url: 'https://api.github.com/repos/docker/test-docker-action/git/tags{/sha}',
|
|
||||||
git_url: 'git://github.com/docker/test-docker-action.git',
|
|
||||||
has_downloads: true,
|
|
||||||
has_issues: true,
|
|
||||||
has_pages: false,
|
|
||||||
has_projects: true,
|
|
||||||
has_wiki: true,
|
|
||||||
homepage: '',
|
|
||||||
hooks_url: 'https://api.github.com/repos/docker/test-docker-action/hooks',
|
|
||||||
html_url: 'https://github.com/docker/test-docker-action',
|
|
||||||
id: 285789493,
|
|
||||||
is_template: false,
|
|
||||||
issue_comment_url: 'https://api.github.com/repos/docker/test-docker-action/issues/comments{/number}',
|
|
||||||
issue_events_url: 'https://api.github.com/repos/docker/test-docker-action/issues/events{/number}',
|
|
||||||
issues_url: 'https://api.github.com/repos/docker/test-docker-action/issues{/number}',
|
|
||||||
keys_url: 'https://api.github.com/repos/docker/test-docker-action/keys{/key_id}',
|
|
||||||
labels_url: 'https://api.github.com/repos/docker/test-docker-action/labels{/name}',
|
|
||||||
language: 'JavaScript',
|
|
||||||
languages_url: 'https://api.github.com/repos/docker/test-docker-action/languages',
|
|
||||||
license: {
|
|
||||||
key: 'mit',
|
|
||||||
name: 'MIT License',
|
|
||||||
node_id: 'MDc6TGljZW5zZTEz',
|
|
||||||
spdx_id: 'MIT',
|
|
||||||
url: 'https://api.github.com/licenses/mit'
|
|
||||||
},
|
|
||||||
master_branch: 'master',
|
|
||||||
merges_url: 'https://api.github.com/repos/docker/test-docker-action/merges',
|
|
||||||
milestones_url: 'https://api.github.com/repos/docker/test-docker-action/milestones{/number}',
|
|
||||||
mirror_url: null,
|
|
||||||
name: 'test-docker-action',
|
|
||||||
node_id: 'MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=',
|
|
||||||
notifications_url: 'https://api.github.com/repos/docker/test-docker-action/notifications{?since,all,participating}',
|
|
||||||
open_issues: 6,
|
|
||||||
open_issues_count: 6,
|
|
||||||
organization: 'docker',
|
|
||||||
owner: {
|
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
|
||||||
email: 'info@docker.com',
|
|
||||||
events_url: 'https://api.github.com/users/docker/events{/privacy}',
|
|
||||||
followers_url: 'https://api.github.com/users/docker/followers',
|
|
||||||
following_url: 'https://api.github.com/users/docker/following{/other_user}',
|
|
||||||
gists_url: 'https://api.github.com/users/docker/gists{/gist_id}',
|
|
||||||
gravatar_id: '',
|
|
||||||
html_url: 'https://github.com/docker',
|
|
||||||
id: 5429470,
|
|
||||||
login: 'docker',
|
|
||||||
name: 'docker',
|
|
||||||
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
|
||||||
organizations_url: 'https://api.github.com/users/docker/orgs',
|
|
||||||
received_events_url: 'https://api.github.com/users/docker/received_events',
|
|
||||||
repos_url: 'https://api.github.com/users/docker/repos',
|
|
||||||
site_admin: false,
|
|
||||||
starred_url: 'https://api.github.com/users/docker/starred{/owner}{/repo}',
|
|
||||||
subscriptions_url: 'https://api.github.com/users/docker/subscriptions',
|
|
||||||
type: 'Organization',
|
|
||||||
url: 'https://api.github.com/users/docker'
|
|
||||||
},
|
|
||||||
private: true,
|
|
||||||
pulls_url: 'https://api.github.com/repos/docker/test-docker-action/pulls{/number}',
|
|
||||||
pushed_at: 1650360446,
|
|
||||||
releases_url: 'https://api.github.com/repos/docker/test-docker-action/releases{/id}',
|
|
||||||
size: 796,
|
|
||||||
ssh_url: 'git@github.com:docker/test-docker-action.git',
|
|
||||||
stargazers: 0,
|
|
||||||
stargazers_count: 0,
|
|
||||||
stargazers_url: 'https://api.github.com/repos/docker/test-docker-action/stargazers',
|
|
||||||
statuses_url: 'https://api.github.com/repos/docker/test-docker-action/statuses/{sha}',
|
|
||||||
subscribers_url: 'https://api.github.com/repos/docker/test-docker-action/subscribers',
|
|
||||||
subscription_url: 'https://api.github.com/repos/docker/test-docker-action/subscription',
|
|
||||||
svn_url: 'https://github.com/docker/test-docker-action',
|
|
||||||
tags_url: 'https://api.github.com/repos/docker/test-docker-action/tags',
|
|
||||||
teams_url: 'https://api.github.com/repos/docker/test-docker-action/teams',
|
|
||||||
topics: [],
|
|
||||||
trees_url: 'https://api.github.com/repos/docker/test-docker-action/git/trees{/sha}',
|
|
||||||
updated_at: '2022-04-19T09:05:09Z',
|
|
||||||
url: 'https://github.com/docker/test-docker-action',
|
|
||||||
visibility: 'private',
|
|
||||||
watchers: 0,
|
|
||||||
watchers_count: 0
|
|
||||||
},
|
|
||||||
sender: {
|
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/1951866?v=4',
|
|
||||||
events_url: 'https://api.github.com/users/crazy-max/events{/privacy}',
|
|
||||||
followers_url: 'https://api.github.com/users/crazy-max/followers',
|
|
||||||
following_url: 'https://api.github.com/users/crazy-max/following{/other_user}',
|
|
||||||
gists_url: 'https://api.github.com/users/crazy-max/gists{/gist_id}',
|
|
||||||
gravatar_id: '',
|
|
||||||
html_url: 'https://github.com/crazy-max',
|
|
||||||
id: 1951866,
|
|
||||||
login: 'crazy-max',
|
|
||||||
node_id: 'MDQ6VXNlcjE5NTE4NjY=',
|
|
||||||
organizations_url: 'https://api.github.com/users/crazy-max/orgs',
|
|
||||||
received_events_url: 'https://api.github.com/users/crazy-max/received_events',
|
|
||||||
repos_url: 'https://api.github.com/users/crazy-max/repos',
|
|
||||||
site_admin: false,
|
|
||||||
starred_url: 'https://api.github.com/users/crazy-max/starred{/owner}{/repo}',
|
|
||||||
subscriptions_url: 'https://api.github.com/users/crazy-max/subscriptions',
|
|
||||||
type: 'User',
|
|
||||||
url: 'https://api.github.com/users/crazy-max'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getOctokit = jest.fn(() => ({
|
|
||||||
rest: {
|
|
||||||
repos: {
|
|
||||||
getCommit: jest.fn(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
data: {
|
|
||||||
commit: {
|
|
||||||
committer: {
|
|
||||||
date: '2024-11-13T13:42:28Z'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
@ -1,141 +1,167 @@
|
|||||||
import {afterEach, beforeEach, describe, expect, test, it, jest} from '@jest/globals';
|
import {describe, expect, it, jest} from '@jest/globals';
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {Context} from '@actions/github/lib/context';
|
|
||||||
import {Git} from '@docker/actions-toolkit/lib/git';
|
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
|
||||||
|
|
||||||
import {ContextSource, getContext, getInputs, Inputs} from '../src/context';
|
import * as context from '../src/context';
|
||||||
|
|
||||||
const toolkit = new Toolkit({githubToken: 'fake-github-token'});
|
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
|
||||||
|
const tmpDir = path.join('/tmp/.docker-metadata-action-jest').split(path.sep).join(path.posix.sep);
|
||||||
|
if (!fs.existsSync(tmpDir)) {
|
||||||
|
fs.mkdirSync(tmpDir, {recursive: true});
|
||||||
|
}
|
||||||
|
return tmpDir;
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
describe('getInputList', () => {
|
||||||
jest.clearAllMocks();
|
it('single line correctly', async () => {
|
||||||
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
await setInput('foo', 'bar');
|
||||||
return new Context();
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multiline correctly', async () => {
|
||||||
|
setInput('foo', 'bar\nbaz');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('empty lines correctly', async () => {
|
||||||
|
setInput('foo', 'bar\n\nbaz');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('comment correctly', async () => {
|
||||||
|
setInput('foo', 'bar\n#com\n"#taken"\nhello#comment\nbaz');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', '#taken', 'hello', 'baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('comma correctly', async () => {
|
||||||
|
setInput('foo', 'bar,baz');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('empty result correctly', async () => {
|
||||||
|
setInput('foo', 'bar,baz,');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('different new lines correctly', async () => {
|
||||||
|
setInput('foo', 'bar\r\nbaz');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('different new lines and comma correctly', async () => {
|
||||||
|
setInput('foo', 'bar\r\nbaz,bat');
|
||||||
|
const res = context.getInputList('foo');
|
||||||
|
expect(res).toEqual(['bar', 'baz', 'bat']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multiline and ignoring comma correctly', async () => {
|
||||||
|
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
||||||
|
const res = context.getInputList('cache-from', true);
|
||||||
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('different new lines and ignoring comma correctly', async () => {
|
||||||
|
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
||||||
|
const res = context.getInputList('cache-from', true);
|
||||||
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multiline values', async () => {
|
||||||
|
setInput(
|
||||||
|
'secrets',
|
||||||
|
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
||||||
|
"MYSECRET=aaaaaaaa
|
||||||
|
bbbbbbb
|
||||||
|
ccccccccc"
|
||||||
|
FOO=bar`
|
||||||
|
);
|
||||||
|
const res = context.getInputList('secrets', true);
|
||||||
|
expect(res).toEqual([
|
||||||
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
|
`MYSECRET=aaaaaaaa
|
||||||
|
bbbbbbb
|
||||||
|
ccccccccc`,
|
||||||
|
'FOO=bar'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multiline values with empty lines', async () => {
|
||||||
|
setInput(
|
||||||
|
'secrets',
|
||||||
|
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
||||||
|
"MYSECRET=aaaaaaaa
|
||||||
|
bbbbbbb
|
||||||
|
ccccccccc"
|
||||||
|
FOO=bar
|
||||||
|
"EMPTYLINE=aaaa
|
||||||
|
|
||||||
|
bbbb
|
||||||
|
ccc"`
|
||||||
|
);
|
||||||
|
const res = context.getInputList('secrets', true);
|
||||||
|
expect(res).toEqual([
|
||||||
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
|
`MYSECRET=aaaaaaaa
|
||||||
|
bbbbbbb
|
||||||
|
ccccccccc`,
|
||||||
|
'FOO=bar',
|
||||||
|
`EMPTYLINE=aaaa
|
||||||
|
|
||||||
|
bbbb
|
||||||
|
ccc`
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multiline values without quotes', async () => {
|
||||||
|
setInput(
|
||||||
|
'secrets',
|
||||||
|
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
||||||
|
MYSECRET=aaaaaaaa
|
||||||
|
bbbbbbb
|
||||||
|
ccccccccc
|
||||||
|
FOO=bar`
|
||||||
|
);
|
||||||
|
const res = context.getInputList('secrets', true);
|
||||||
|
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multiline values escape quotes', async () => {
|
||||||
|
setInput(
|
||||||
|
'secrets',
|
||||||
|
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
||||||
|
"MYSECRET=aaaaaaaa
|
||||||
|
bbbb""bbb
|
||||||
|
ccccccccc"
|
||||||
|
FOO=bar`
|
||||||
|
);
|
||||||
|
const res = context.getInputList('secrets', true);
|
||||||
|
expect(res).toEqual([
|
||||||
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
|
`MYSECRET=aaaaaaaa
|
||||||
|
bbbb"bbb
|
||||||
|
ccccccccc`,
|
||||||
|
'FOO=bar'
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getInputs', () => {
|
describe('asyncForEach', () => {
|
||||||
beforeEach(() => {
|
it('executes async tasks sequentially', async () => {
|
||||||
process.env = Object.keys(process.env).reduce((object, key) => {
|
const testValues = [1, 2, 3, 4, 5];
|
||||||
if (!key.startsWith('INPUT_')) {
|
const results: number[] = [];
|
||||||
object[key] = process.env[key];
|
|
||||||
}
|
|
||||||
return object;
|
|
||||||
}, {});
|
|
||||||
});
|
|
||||||
|
|
||||||
// prettier-ignore
|
await context.asyncForEach(testValues, async value => {
|
||||||
test.each([
|
results.push(value);
|
||||||
[
|
|
||||||
0,
|
|
||||||
new Map<string, string>([
|
|
||||||
['images', 'moby/buildkit\nghcr.io/moby/mbuildkit'],
|
|
||||||
]),
|
|
||||||
{
|
|
||||||
context: ContextSource.workflow,
|
|
||||||
bakeTarget: 'docker-metadata-action',
|
|
||||||
flavor: [],
|
|
||||||
githubToken: '',
|
|
||||||
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
|
|
||||||
labels: [],
|
|
||||||
annotations: [],
|
|
||||||
sepLabels: '\n',
|
|
||||||
sepTags: '\n',
|
|
||||||
sepAnnotations: '\n',
|
|
||||||
tags: [],
|
|
||||||
} as Inputs
|
|
||||||
],
|
|
||||||
[
|
|
||||||
1,
|
|
||||||
new Map<string, string>([
|
|
||||||
['bake-target', 'metadata'],
|
|
||||||
['images', 'moby/buildkit'],
|
|
||||||
['sep-labels', ','],
|
|
||||||
['sep-tags', ','],
|
|
||||||
['sep-annotations', ',']
|
|
||||||
]),
|
|
||||||
{
|
|
||||||
context: ContextSource.workflow,
|
|
||||||
bakeTarget: 'metadata',
|
|
||||||
flavor: [],
|
|
||||||
githubToken: '',
|
|
||||||
images: ['moby/buildkit'],
|
|
||||||
labels: [],
|
|
||||||
annotations: [],
|
|
||||||
sepLabels: ',',
|
|
||||||
sepTags: ',',
|
|
||||||
sepAnnotations: ',',
|
|
||||||
tags: [],
|
|
||||||
} as Inputs
|
|
||||||
],
|
|
||||||
[
|
|
||||||
2,
|
|
||||||
new Map<string, string>([
|
|
||||||
['images', 'moby/buildkit\n#comment\nghcr.io/moby/mbuildkit'],
|
|
||||||
]),
|
|
||||||
{
|
|
||||||
context: ContextSource.workflow,
|
|
||||||
bakeTarget: 'docker-metadata-action',
|
|
||||||
flavor: [],
|
|
||||||
githubToken: '',
|
|
||||||
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
|
|
||||||
labels: [],
|
|
||||||
annotations: [],
|
|
||||||
sepLabels: '\n',
|
|
||||||
sepTags: '\n',
|
|
||||||
sepAnnotations: '\n',
|
|
||||||
tags: [],
|
|
||||||
} as Inputs
|
|
||||||
],
|
|
||||||
])(
|
|
||||||
'[%d] given %p as inputs, returns %p',
|
|
||||||
async (num: number, inputs: Map<string, string>, expected: Inputs) => {
|
|
||||||
inputs.forEach((value: string, name: string) => {
|
|
||||||
setInput(name, value);
|
|
||||||
});
|
|
||||||
expect(await getInputs()).toEqual(expected);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getContext', () => {
|
|
||||||
const originalEnv = process.env;
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetModules();
|
|
||||||
process.env = {
|
|
||||||
...originalEnv,
|
|
||||||
...dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures/event_create_branch.env')))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
afterEach(() => {
|
|
||||||
process.env = originalEnv;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('workflow', async () => {
|
|
||||||
const context = await getContext(ContextSource.workflow, toolkit);
|
|
||||||
expect(context.ref).toEqual('refs/heads/dev');
|
|
||||||
expect(context.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a');
|
|
||||||
expect(context.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('git', async () => {
|
|
||||||
jest.spyOn(Git, 'context').mockImplementation((): Promise<Context> => {
|
|
||||||
return Promise.resolve({
|
|
||||||
ref: 'refs/heads/git-test',
|
|
||||||
sha: 'git-test-sha'
|
|
||||||
} as Context);
|
|
||||||
});
|
});
|
||||||
jest.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
|
|
||||||
return new Date('2023-01-01T13:42:28.000Z');
|
expect(results).toEqual(testValues);
|
||||||
});
|
|
||||||
const context = await getContext(ContextSource.git, toolkit);
|
|
||||||
expect(context.ref).toEqual('refs/heads/git-test');
|
|
||||||
expect(context.sha).toEqual('git-test-sha');
|
|
||||||
expect(context.commitDate).toEqual(new Date('2023-01-01T13:42:28.000Z'));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Flavor, Transform} from '../src/flavor';
|
import {Flavor, Transform} from '../src/flavor';
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
|
14
__tests__/github.test.ts
Normal file
14
__tests__/github.test.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import {describe, expect, jest, it} from '@jest/globals';
|
||||||
|
import * as github from '../src/github';
|
||||||
|
|
||||||
|
import * as repoFixture from './fixtures/repo.json';
|
||||||
|
jest.spyOn(github, 'repo').mockImplementation((): Promise<github.ReposGetResponseData> => {
|
||||||
|
return <Promise<github.ReposGetResponseData>>(repoFixture as unknown);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('repo', () => {
|
||||||
|
it('returns GitHub repository', async () => {
|
||||||
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
|
expect(repo.name).not.toBeNull();
|
||||||
|
});
|
||||||
|
});
|
@ -1,5 +1,4 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Transform, Image} from '../src/image';
|
import {Transform, Image} from '../src/image';
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
@ -87,7 +86,7 @@ describe('transform', () => {
|
|||||||
[
|
[
|
||||||
[`name/foo,name=name/bar,enable=true`], undefined, true
|
[`name/foo,name=name/bar,enable=true`], undefined, true
|
||||||
]
|
]
|
||||||
])('given %p', async (l: string[], expected: Image[] | undefined, invalid: boolean) => {
|
])('given %p', async (l: string[], expected: Image[], invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const images = Transform(l);
|
const images = Transform(l);
|
||||||
expect(images).toEqual(expected);
|
expect(images).toEqual(expected);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';
|
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
|
26
action.yml
26
action.yml
@ -7,13 +7,9 @@ branding:
|
|||||||
color: 'blue'
|
color: 'blue'
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
context:
|
|
||||||
description: 'Where to get context data. Allowed options are "workflow" (default), "git".'
|
|
||||||
default: "workflow"
|
|
||||||
required: true
|
|
||||||
images:
|
images:
|
||||||
description: 'List of Docker images to use as base name for tags'
|
description: 'List of Docker images to use as base name for tags'
|
||||||
required: false
|
required: true
|
||||||
tags:
|
tags:
|
||||||
description: 'List of tags as key-value pair attributes'
|
description: 'List of tags as key-value pair attributes'
|
||||||
required: false
|
required: false
|
||||||
@ -23,18 +19,12 @@ inputs:
|
|||||||
labels:
|
labels:
|
||||||
description: 'List of custom labels'
|
description: 'List of custom labels'
|
||||||
required: false
|
required: false
|
||||||
annotations:
|
|
||||||
description: 'List of custom annotations'
|
|
||||||
required: false
|
|
||||||
sep-tags:
|
sep-tags:
|
||||||
description: 'Separator to use for tags output (default \n)'
|
description: 'Separator to use for tags output (default \n)'
|
||||||
required: false
|
required: false
|
||||||
sep-labels:
|
sep-labels:
|
||||||
description: 'Separator to use for labels output (default \n)'
|
description: 'Separator to use for labels output (default \n)'
|
||||||
required: false
|
required: false
|
||||||
sep-annotations:
|
|
||||||
description: 'Separator to use for annotations output (default \n)'
|
|
||||||
required: false
|
|
||||||
bake-target:
|
bake-target:
|
||||||
description: 'Bake target name (default docker-metadata-action)'
|
description: 'Bake target name (default docker-metadata-action)'
|
||||||
required: false
|
required: false
|
||||||
@ -50,19 +40,11 @@ outputs:
|
|||||||
description: 'Generated Docker tags'
|
description: 'Generated Docker tags'
|
||||||
labels:
|
labels:
|
||||||
description: 'Generated Docker labels'
|
description: 'Generated Docker labels'
|
||||||
annotations:
|
bake-file:
|
||||||
description: 'Generated annotations'
|
description: 'Bake definiton file'
|
||||||
json:
|
json:
|
||||||
description: 'JSON output of tags and labels'
|
description: 'JSON output of tags and labels'
|
||||||
bake-file-tags:
|
|
||||||
description: 'Bake definition file with tags'
|
|
||||||
bake-file-labels:
|
|
||||||
description: 'Bake definition file with labels'
|
|
||||||
bake-file-annotations:
|
|
||||||
description: 'Bake definition file with annotations'
|
|
||||||
bake-file:
|
|
||||||
description: 'Bake definition file with tags and labels'
|
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node16'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
@ -1,20 +1,13 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
ARG NODE_VERSION=20
|
ARG NODE_VERSION=16
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine AS base
|
FROM node:${NODE_VERSION}-alpine AS base
|
||||||
RUN apk add --no-cache cpio findutils git
|
RUN apk add --no-cache cpio findutils git
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
RUN --mount=type=bind,target=.,rw \
|
|
||||||
--mount=type=cache,target=/src/.yarn/cache <<EOT
|
|
||||||
corepack enable
|
|
||||||
yarn --version
|
|
||||||
yarn config set --home enableTelemetry 0
|
|
||||||
EOT
|
|
||||||
|
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/.yarn/cache \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn install && mkdir /vendor && cp yarn.lock /vendor
|
yarn install && mkdir /vendor && cp yarn.lock /vendor
|
||||||
|
|
||||||
@ -23,19 +16,18 @@ COPY --from=deps /vendor /
|
|||||||
|
|
||||||
FROM deps AS vendor-validate
|
FROM deps AS vendor-validate
|
||||||
RUN --mount=type=bind,target=.,rw <<EOT
|
RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
set -e
|
set -e
|
||||||
git add -A
|
git add -A
|
||||||
cp -rf /vendor/* .
|
cp -rf /vendor/* .
|
||||||
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then
|
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then
|
||||||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"'
|
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'
|
||||||
git status --porcelain -- yarn.lock
|
git status --porcelain -- yarn.lock
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM deps AS build
|
FROM deps AS build
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/.yarn/cache \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run build && mkdir /out && cp -Rf dist /out/
|
yarn run build && mkdir /out && cp -Rf dist /out/
|
||||||
|
|
||||||
@ -44,37 +36,36 @@ COPY --from=build /out /
|
|||||||
|
|
||||||
FROM build AS build-validate
|
FROM build AS build-validate
|
||||||
RUN --mount=type=bind,target=.,rw <<EOT
|
RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
set -e
|
set -e
|
||||||
git add -A
|
git add -A
|
||||||
cp -rf /out/* .
|
cp -rf /out/* .
|
||||||
if [ -n "$(git status --porcelain -- dist)" ]; then
|
if [ -n "$(git status --porcelain -- dist)" ]; then
|
||||||
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
|
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
|
||||||
git status --porcelain -- dist
|
git status --porcelain -- dist
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM deps AS format
|
FROM deps AS format
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/.yarn/cache \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run format \
|
yarn run format \
|
||||||
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' -not -path './.yarn/*' | cpio -pdm /out
|
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out
|
||||||
|
|
||||||
FROM scratch AS format-update
|
FROM scratch AS format-update
|
||||||
COPY --from=format /out /
|
COPY --from=format /out /
|
||||||
|
|
||||||
FROM deps AS lint
|
FROM deps AS lint
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/.yarn/cache \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run lint
|
yarn run lint
|
||||||
|
|
||||||
FROM deps AS test
|
FROM deps AS test
|
||||||
|
ENV RUNNER_TEMP=/tmp/github_runner
|
||||||
|
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/.yarn/cache \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run test --coverage --coverageDirectory=/tmp/coverage
|
yarn run test --coverageDirectory=/tmp/coverage
|
||||||
|
|
||||||
FROM scratch AS test-coverage
|
FROM scratch AS test-coverage
|
||||||
COPY --from=test /tmp/coverage /
|
COPY --from=test /tmp/coverage /
|
||||||
|
125
dist/index.js
generated
vendored
125
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
3190
dist/licenses.txt
generated
vendored
3190
dist/licenses.txt
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/sourcemap-register.js
generated
vendored
2
dist/sourcemap-register.js
generated
vendored
File diff suppressed because one or more lines are too long
@ -1,15 +1,9 @@
|
|||||||
target "_common" {
|
|
||||||
args = {
|
|
||||||
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
group "default" {
|
group "default" {
|
||||||
targets = ["build"]
|
targets = ["build"]
|
||||||
}
|
}
|
||||||
|
|
||||||
group "pre-checkin" {
|
group "pre-checkin" {
|
||||||
targets = ["vendor", "format", "build"]
|
targets = ["vendor-update", "format", "build"]
|
||||||
}
|
}
|
||||||
|
|
||||||
group "validate" {
|
group "validate" {
|
||||||
@ -17,49 +11,42 @@ group "validate" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
target "build" {
|
target "build" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "build-update"
|
target = "build-update"
|
||||||
output = ["."]
|
output = ["."]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "build-validate" {
|
target "build-validate" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "build-validate"
|
target = "build-validate"
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "format" {
|
target "format" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "format-update"
|
target = "format-update"
|
||||||
output = ["."]
|
output = ["."]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "lint" {
|
target "lint" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "lint"
|
target = "lint"
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "vendor" {
|
target "vendor-update" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "vendor-update"
|
target = "vendor-update"
|
||||||
output = ["."]
|
output = ["."]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "vendor-validate" {
|
target "vendor-validate" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "vendor-validate"
|
target = "vendor-validate"
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "test" {
|
target "test" {
|
||||||
inherits = ["_common"]
|
|
||||||
dockerfile = "dev.Dockerfile"
|
dockerfile = "dev.Dockerfile"
|
||||||
target = "test-coverage"
|
target = "test-coverage"
|
||||||
output = ["./coverage"]
|
output = ["./coverage"]
|
||||||
|
@ -1,21 +1,5 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-'));
|
|
||||||
|
|
||||||
process.env = Object.assign({}, process.env, {
|
|
||||||
TEMP: tmpDir,
|
|
||||||
GITHUB_REPOSITORY: 'docker/metadata-action',
|
|
||||||
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
|
|
||||||
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
|
|
||||||
}) as {
|
|
||||||
[key: string]: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
testEnvironment: 'node',
|
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
setupFiles: ['dotenv/config'],
|
setupFiles: ['dotenv/config'],
|
||||||
testMatch: ['**/*.test.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
@ -25,7 +9,5 @@ module.exports = {
|
|||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
||||||
},
|
},
|
||||||
collectCoverageFrom: ['src/**/{!(main.ts),}.ts'],
|
|
||||||
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
|
||||||
verbose: true
|
verbose: true
|
||||||
};
|
};
|
||||||
|
69
package.json
69
package.json
@ -1,16 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "docker-metadata-action",
|
"name": "docker-metadata-action",
|
||||||
"description": "GitHub Action to extract metadata (tags, labels) for Docker",
|
"description": "GitHub Action to extract metadata (tags, labels) for Docker",
|
||||||
"main": "src/main.ts",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build --source-map --minify --license licenses.txt",
|
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
|
||||||
"lint": "yarn run prettier && yarn run eslint",
|
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
|
||||||
"format": "yarn run prettier:fix && yarn run eslint:fix",
|
"format": "eslint --fix src/**/*.ts __tests__/**/*.ts",
|
||||||
"eslint": "eslint --max-warnings=0 .",
|
"test": "jest --coverage",
|
||||||
"eslint:fix": "eslint --fix .",
|
"all": "yarn run build && yarn run format && yarn test"
|
||||||
"prettier": "prettier --check \"./**/*.ts\"",
|
|
||||||
"prettier:fix": "prettier --write \"./**/*.ts\"",
|
|
||||||
"test": "jest"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,36 +20,40 @@
|
|||||||
"tag",
|
"tag",
|
||||||
"label"
|
"label"
|
||||||
],
|
],
|
||||||
"author": "Docker Inc.",
|
"author": "Docker",
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "CrazyMax",
|
||||||
|
"url": "https://crazymax.dev"
|
||||||
|
}
|
||||||
|
],
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"packageManager": "yarn@3.6.3",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/github": "^6.0.0",
|
"@actions/github": "^5.1.1",
|
||||||
"@docker/actions-toolkit": "^0.56.0",
|
|
||||||
"@renovate/pep440": "^1.0.0",
|
"@renovate/pep440": "^1.0.0",
|
||||||
"csv-parse": "^5.6.0",
|
"csv-parse": "^5.3.3",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.7",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.29.4",
|
||||||
"moment-timezone": "^0.5.47",
|
"moment-timezone": "^0.5.40",
|
||||||
"semver": "^7.7.1"
|
"semver": "^7.3.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/csv-parse": "^1.2.2",
|
"@types/csv-parse": "^1.2.2",
|
||||||
"@types/node": "^20.12.12",
|
"@types/node": "^16.11.26",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.3.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
||||||
"@typescript-eslint/parser": "^7.9.0",
|
"@typescript-eslint/parser": "^5.14.0",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.33.3",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.0.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.11.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-plugin-jest": "^28.5.0",
|
"eslint-plugin-jest": "^26.1.1",
|
||||||
"eslint-plugin-prettier": "^5.1.3",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "^27.2.5",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^2.3.1",
|
||||||
"ts-jest": "^29.1.2",
|
"ts-jest": "^27.1.2",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.7.0",
|
||||||
"typescript": "^5.4.5"
|
"typescript": "^4.4.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
146
src/context.ts
146
src/context.ts
@ -1,136 +1,74 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
|
import * as os from 'os';
|
||||||
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {Context as GithubContext} from '@actions/github/lib/context';
|
import {parse} from 'csv-parse/sync';
|
||||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
|
||||||
import {Git} from '@docker/actions-toolkit/lib/git';
|
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
|
||||||
|
|
||||||
export interface Context extends GithubContext {
|
let _tmpDir: string;
|
||||||
commitDate: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
context: ContextSource;
|
|
||||||
images: string[];
|
images: string[];
|
||||||
tags: string[];
|
tags: string[];
|
||||||
flavor: string[];
|
flavor: string[];
|
||||||
labels: string[];
|
labels: string[];
|
||||||
annotations: string[];
|
|
||||||
sepTags: string;
|
sepTags: string;
|
||||||
sepLabels: string;
|
sepLabels: string;
|
||||||
sepAnnotations: string;
|
|
||||||
bakeTarget: string;
|
bakeTarget: string;
|
||||||
githubToken: string;
|
githubToken: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function tmpDir(): string {
|
||||||
|
if (!_tmpDir) {
|
||||||
|
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-')).split(path.sep).join(path.posix.sep);
|
||||||
|
}
|
||||||
|
return _tmpDir;
|
||||||
|
}
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
return {
|
return {
|
||||||
context: (core.getInput('context') || ContextSource.workflow) as ContextSource,
|
images: getInputList('images', true),
|
||||||
images: Util.getInputList('images', {ignoreComma: true, comment: '#'}),
|
tags: getInputList('tags', true),
|
||||||
tags: Util.getInputList('tags', {ignoreComma: true, comment: '#'}),
|
flavor: getInputList('flavor', true),
|
||||||
flavor: Util.getInputList('flavor', {ignoreComma: true, comment: '#'}),
|
labels: getInputList('labels', true),
|
||||||
labels: Util.getInputList('labels', {ignoreComma: true, comment: '#'}),
|
|
||||||
annotations: Util.getInputList('annotations', {ignoreComma: true, comment: '#'}),
|
|
||||||
sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`,
|
sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
||||||
sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`,
|
|
||||||
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
||||||
githubToken: core.getInput('github-token')
|
githubToken: core.getInput('github-token')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ContextSource {
|
export function getInputList(name: string, ignoreComma?: boolean): string[] {
|
||||||
workflow = 'workflow',
|
const res: Array<string> = [];
|
||||||
git = 'git'
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getContext(source: ContextSource, toolkit: Toolkit): Promise<Context> {
|
const items = core.getInput(name);
|
||||||
switch (source) {
|
if (items == '') {
|
||||||
case ContextSource.workflow:
|
return res;
|
||||||
return await getContextFromWorkflow(toolkit);
|
|
||||||
case ContextSource.git:
|
|
||||||
return await getContextFromGit();
|
|
||||||
default:
|
|
||||||
throw new Error(`Invalid context source: ${source}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getContextFromWorkflow(toolkit: Toolkit): Promise<Context> {
|
|
||||||
const context = GitHub.context;
|
|
||||||
|
|
||||||
// Needs to override Git reference with pr ref instead of upstream branch ref
|
|
||||||
// for pull_request_target event
|
|
||||||
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
|
|
||||||
if (/pull_request_target/.test(context.eventName)) {
|
|
||||||
context.ref = `refs/pull/${context.payload.number}/merge`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOCKER_METADATA_PR_HEAD_SHA env var can be used to set associated head
|
const records = parse(items, {
|
||||||
// SHA instead of commit SHA that triggered the workflow on pull request
|
columns: false,
|
||||||
// event.
|
relaxQuotes: true,
|
||||||
if (/true/i.test(process.env.DOCKER_METADATA_PR_HEAD_SHA || '')) {
|
comment: '#',
|
||||||
if ((/pull_request/.test(context.eventName) || /pull_request_target/.test(context.eventName)) && context.payload?.pull_request?.head?.sha != undefined) {
|
relaxColumnCount: true,
|
||||||
context.sha = context.payload.pull_request.head.sha;
|
skipEmptyLines: true
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const record of records as Array<string[]>) {
|
||||||
|
if (record.length == 1) {
|
||||||
|
res.push(record[0]);
|
||||||
|
continue;
|
||||||
|
} else if (!ignoreComma) {
|
||||||
|
res.push(...record);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
res.push(record.join(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return res.filter(item => item).map(pat => pat.trim());
|
||||||
commitDate: await getCommitDateFromWorkflow(context.sha, toolkit),
|
|
||||||
...context
|
|
||||||
} as Context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getContextFromGit(): Promise<Context> {
|
export const asyncForEach = async (array, callback) => {
|
||||||
const ctx = await Git.context();
|
for (let index = 0; index < array.length; index++) {
|
||||||
|
await callback(array[index], index, array);
|
||||||
return {
|
|
||||||
commitDate: await Git.commitDate(ctx.sha),
|
|
||||||
...ctx
|
|
||||||
} as Context;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getCommitDateFromWorkflow(sha: string, toolkit: Toolkit): Promise<Date> {
|
|
||||||
const event = GitHub.context.payload as unknown as {
|
|
||||||
// branch push
|
|
||||||
commits?: Array<{
|
|
||||||
timestamp: string;
|
|
||||||
// commit sha
|
|
||||||
id: string;
|
|
||||||
}>;
|
|
||||||
// tags
|
|
||||||
head_commit?: {
|
|
||||||
timestamp: string;
|
|
||||||
// commit sha
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if (event.commits) {
|
|
||||||
const commitDate = event.commits.find(x => x.id === sha)?.timestamp;
|
|
||||||
if (commitDate) {
|
|
||||||
return new Date(commitDate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if (event.head_commit) {
|
|
||||||
if (event.head_commit.id === sha) {
|
|
||||||
return new Date(event.head_commit.timestamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback to github api for commit date
|
|
||||||
try {
|
|
||||||
const commit = await toolkit.github.octokit.rest.repos.getCommit({
|
|
||||||
owner: GitHub.context.repo.owner,
|
|
||||||
repo: GitHub.context.repo.repo,
|
|
||||||
ref: sha
|
|
||||||
});
|
|
||||||
if (commit.data.commit.committer?.date) {
|
|
||||||
return new Date(commit.data.commit.committer.date);
|
|
||||||
}
|
|
||||||
throw new Error('Committer date not found');
|
|
||||||
} catch (error) {
|
|
||||||
core.debug(`Failed to get commit date from GitHub API: ${error.message}`);
|
|
||||||
return new Date();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
16
src/github.ts
Normal file
16
src/github.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as github from '@actions/github';
|
||||||
|
import {Context} from '@actions/github/lib/context';
|
||||||
|
import {components as OctoOpenApiTypes} from '@octokit/openapi-types';
|
||||||
|
|
||||||
|
export type ReposGetResponseData = OctoOpenApiTypes['schemas']['repository'];
|
||||||
|
|
||||||
|
export function context(): Context {
|
||||||
|
return github.context;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function repo(token: string): Promise<ReposGetResponseData> {
|
||||||
|
return github
|
||||||
|
.getOctokit(token)
|
||||||
|
.rest.repos.get({...github.context.repo})
|
||||||
|
.then(response => response.data as ReposGetResponseData);
|
||||||
|
}
|
139
src/main.ts
139
src/main.ts
@ -1,37 +1,34 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as core from '@actions/core';
|
import {getInputs, Inputs} from './context';
|
||||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
import * as github from './github';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
|
||||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
|
||||||
|
|
||||||
import {getContext, getInputs, Inputs} from './context';
|
|
||||||
import {Meta, Version} from './meta';
|
import {Meta, Version} from './meta';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
import {Context} from '@actions/github/lib/context';
|
||||||
|
|
||||||
actionsToolkit.run(
|
async function run() {
|
||||||
// main
|
try {
|
||||||
async () => {
|
const inputs: Inputs = await getInputs();
|
||||||
const inputs: Inputs = getInputs();
|
if (inputs.images.length == 0) {
|
||||||
const toolkit = new Toolkit({githubToken: inputs.githubToken});
|
throw new Error(`images input required`);
|
||||||
const context = await getContext(inputs.context, toolkit);
|
}
|
||||||
const repo = await toolkit.github.repoData();
|
|
||||||
const setOutput = outputEnvEnabled() ? setOutputAndEnv : core.setOutput;
|
|
||||||
|
|
||||||
await core.group(`Context info`, async () => {
|
const context: Context = github.context();
|
||||||
core.info(`eventName: ${context.eventName}`);
|
const repo: github.ReposGetResponseData = await github.repo(inputs.githubToken);
|
||||||
core.info(`sha: ${context.sha}`);
|
core.startGroup(`Context info`);
|
||||||
core.info(`ref: ${context.ref}`);
|
core.info(`eventName: ${context.eventName}`);
|
||||||
core.info(`workflow: ${context.workflow}`);
|
core.info(`sha: ${context.sha}`);
|
||||||
core.info(`action: ${context.action}`);
|
core.info(`ref: ${context.ref}`);
|
||||||
core.info(`actor: ${context.actor}`);
|
core.info(`workflow: ${context.workflow}`);
|
||||||
core.info(`runNumber: ${context.runNumber}`);
|
core.info(`action: ${context.action}`);
|
||||||
core.info(`runId: ${context.runId}`);
|
core.info(`actor: ${context.actor}`);
|
||||||
core.info(`commitDate: ${context.commitDate}`);
|
core.info(`runNumber: ${context.runNumber}`);
|
||||||
});
|
core.info(`runId: ${context.runId}`);
|
||||||
|
core.endGroup();
|
||||||
|
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
await core.group(`Webhook payload`, async () => {
|
core.startGroup(`Webhook payload`);
|
||||||
core.info(JSON.stringify(context.payload, null, 2));
|
core.info(JSON.stringify(context.payload, null, 2));
|
||||||
});
|
core.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta: Meta = new Meta(inputs, context, repo);
|
const meta: Meta = new Meta(inputs, context, repo);
|
||||||
@ -40,9 +37,9 @@ actionsToolkit.run(
|
|||||||
if (meta.version.main == undefined || meta.version.main.length == 0) {
|
if (meta.version.main == undefined || meta.version.main.length == 0) {
|
||||||
core.warning(`No Docker image version has been generated. Check tags input.`);
|
core.warning(`No Docker image version has been generated. Check tags input.`);
|
||||||
} else {
|
} else {
|
||||||
await core.group(`Docker image version`, async () => {
|
core.startGroup(`Docker image version`);
|
||||||
core.info(version.main || '');
|
core.info(version.main || '');
|
||||||
});
|
core.endGroup();
|
||||||
}
|
}
|
||||||
setOutput('version', version.main || '');
|
setOutput('version', version.main || '');
|
||||||
|
|
||||||
@ -51,70 +48,44 @@ actionsToolkit.run(
|
|||||||
if (tags.length == 0) {
|
if (tags.length == 0) {
|
||||||
core.warning('No Docker tag has been generated. Check tags input.');
|
core.warning('No Docker tag has been generated. Check tags input.');
|
||||||
} else {
|
} else {
|
||||||
await core.group(`Docker tags`, async () => {
|
core.startGroup(`Docker tags`);
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
core.info(tag);
|
core.info(tag);
|
||||||
}
|
}
|
||||||
});
|
core.endGroup();
|
||||||
}
|
}
|
||||||
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();
|
||||||
await core.group(`Docker labels`, async () => {
|
core.startGroup(`Docker labels`);
|
||||||
for (const label of labels) {
|
for (const label of labels) {
|
||||||
core.info(label);
|
core.info(label);
|
||||||
}
|
}
|
||||||
setOutput('labels', labels.join(inputs.sepLabels));
|
core.endGroup();
|
||||||
});
|
setOutput('labels', labels.join(inputs.sepLabels));
|
||||||
|
|
||||||
// Annotations
|
|
||||||
const annotationsRaw: Array<string> = meta.getAnnotations();
|
|
||||||
const annotationsLevels = process.env.DOCKER_METADATA_ANNOTATIONS_LEVELS || 'manifest';
|
|
||||||
await core.group(`Annotations`, async () => {
|
|
||||||
const annotations: Array<string> = [];
|
|
||||||
for (const level of annotationsLevels.split(',')) {
|
|
||||||
annotations.push(
|
|
||||||
...annotationsRaw.map(label => {
|
|
||||||
const v = `${level}:${label}`;
|
|
||||||
core.info(v);
|
|
||||||
return v;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setOutput(`annotations`, annotations.join(inputs.sepAnnotations));
|
|
||||||
});
|
|
||||||
|
|
||||||
// JSON
|
// JSON
|
||||||
const jsonOutput = meta.getJSON(annotationsLevels.split(','));
|
const jsonOutput = meta.getJSON();
|
||||||
await core.group(`JSON output`, async () => {
|
core.startGroup(`JSON output`);
|
||||||
core.info(JSON.stringify(jsonOutput, null, 2));
|
core.info(JSON.stringify(jsonOutput, null, 2));
|
||||||
setOutput('json', JSON.stringify(jsonOutput));
|
core.endGroup();
|
||||||
});
|
setOutput('json', JSON.stringify(jsonOutput));
|
||||||
|
|
||||||
// Bake files
|
// Bake file definition
|
||||||
for (const kind of ['tags', 'labels', 'annotations:' + annotationsLevels]) {
|
const bakeFile: string = meta.getBakeFile();
|
||||||
const outputName = kind.split(':')[0];
|
core.startGroup(`Bake file definition`);
|
||||||
const bakeFile: string = meta.getBakeFile(kind);
|
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||||
await core.group(`Bake file definition (${outputName})`, async () => {
|
core.endGroup();
|
||||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
setOutput('bake-file', bakeFile);
|
||||||
setOutput(`bake-file-${outputName}`, bakeFile);
|
} catch (error) {
|
||||||
});
|
core.setFailed(error.message);
|
||||||
}
|
|
||||||
|
|
||||||
// Bake file with tags and labels
|
|
||||||
setOutput(`bake-file`, `${meta.getBakeFileTagsLabels()}`);
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
|
||||||
function setOutputAndEnv(name: string, value: string) {
|
function setOutput(name: string, value: string) {
|
||||||
core.setOutput(name, value);
|
core.setOutput(name, value);
|
||||||
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
|
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputEnvEnabled(): boolean {
|
run();
|
||||||
if (process.env.DOCKER_METADATA_SET_OUTPUT_ENV) {
|
|
||||||
return Util.parseBool(process.env.DOCKER_METADATA_SET_OUTPUT_ENV);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
254
src/meta.ts
254
src/meta.ts
@ -4,16 +4,13 @@ import * as path from 'path';
|
|||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import * as pep440 from '@renovate/pep440';
|
import * as pep440 from '@renovate/pep440';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as core from '@actions/core';
|
import {Inputs, tmpDir} from './context';
|
||||||
import {Context as ToolkitContext} from '@docker/actions-toolkit/lib/context';
|
import {ReposGetResponseData} from './github';
|
||||||
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
|
|
||||||
|
|
||||||
import {Inputs, Context} from './context';
|
|
||||||
import * as icl from './image';
|
import * as icl from './image';
|
||||||
import * as tcl from './tag';
|
import * as tcl from './tag';
|
||||||
import * as fcl from './flavor';
|
import * as fcl from './flavor';
|
||||||
|
import * as core from '@actions/core';
|
||||||
const defaultShortShaLength = 7;
|
import {Context} from '@actions/github/lib/context';
|
||||||
|
|
||||||
export interface Version {
|
export interface Version {
|
||||||
main: string | undefined;
|
main: string | undefined;
|
||||||
@ -26,13 +23,29 @@ export class Meta {
|
|||||||
|
|
||||||
private readonly inputs: Inputs;
|
private readonly inputs: Inputs;
|
||||||
private readonly context: Context;
|
private readonly context: Context;
|
||||||
private readonly repo: GitHubRepo;
|
private readonly repo: ReposGetResponseData;
|
||||||
private readonly images: icl.Image[];
|
private readonly images: icl.Image[];
|
||||||
private readonly tags: tcl.Tag[];
|
private readonly tags: tcl.Tag[];
|
||||||
private readonly flavor: fcl.Flavor;
|
private readonly flavor: fcl.Flavor;
|
||||||
private readonly date: Date;
|
private readonly date: Date;
|
||||||
|
|
||||||
constructor(inputs: Inputs, context: Context, repo: GitHubRepo) {
|
constructor(inputs: Inputs, context: Context, repo: ReposGetResponseData) {
|
||||||
|
// Needs to override Git reference with pr ref instead of upstream branch ref
|
||||||
|
// for pull_request_target event
|
||||||
|
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
|
||||||
|
if (/pull_request_target/.test(context.eventName)) {
|
||||||
|
context.ref = `refs/pull/${context.payload.number}/merge`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DOCKER_METADATA_PR_HEAD_SHA env var can be used to set associated head
|
||||||
|
// SHA instead of commit SHA that triggered the workflow on pull request
|
||||||
|
// event.
|
||||||
|
if (/true/i.test(process.env.DOCKER_METADATA_PR_HEAD_SHA || '')) {
|
||||||
|
if ((/pull_request/.test(context.eventName) || /pull_request_target/.test(context.eventName)) && context.payload?.pull_request?.head?.sha != undefined) {
|
||||||
|
context.sha = context.payload.pull_request.head.sha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
@ -114,7 +127,6 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
const commitDate = this.context.commitDate;
|
|
||||||
const vraw = this.setValue(
|
const vraw = this.setValue(
|
||||||
handlebars.compile(tag.attrs['pattern'])({
|
handlebars.compile(tag.attrs['pattern'])({
|
||||||
date: function (format, options) {
|
date: function (format, options) {
|
||||||
@ -130,20 +142,6 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return m.tz(tz).format(format);
|
return m.tz(tz).format(format);
|
||||||
},
|
|
||||||
commit_date: function (format, options) {
|
|
||||||
const m = moment(commitDate);
|
|
||||||
let tz = 'UTC';
|
|
||||||
Object.keys(options.hash).forEach(key => {
|
|
||||||
switch (key) {
|
|
||||||
case 'tz':
|
|
||||||
tz = options.hash[key];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unknown ${key} attribute`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return m.tz(tz).format(format);
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
tag
|
tag
|
||||||
@ -170,7 +168,7 @@ export class Meta {
|
|||||||
|
|
||||||
let latest = false;
|
let latest = false;
|
||||||
const sver = semver.parse(vraw, {
|
const sver = semver.parse(vraw, {
|
||||||
loose: true
|
includePrerelease: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
if (semver.prerelease(vraw)) {
|
||||||
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
@ -323,7 +321,7 @@ export class Meta {
|
|||||||
|
|
||||||
let val = this.context.sha;
|
let val = this.context.sha;
|
||||||
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
|
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
|
||||||
val = Meta.shortSha(this.context.sha);
|
val = this.context.sha.substring(0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
const vraw = this.setValue(val, tag);
|
const vraw = this.setValue(val, tag);
|
||||||
@ -372,69 +370,54 @@ export class Meta {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
private setGlobalExp(val: string): string {
|
private setGlobalExp(val): string {
|
||||||
const context = this.context;
|
const ctx = this.context;
|
||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
const commitDate = this.context.commitDate;
|
|
||||||
return handlebars.compile(val)({
|
return handlebars.compile(val)({
|
||||||
branch: function () {
|
branch: function () {
|
||||||
if (!/^refs\/heads\//.test(context.ref)) {
|
if (!/^refs\/heads\//.test(ctx.ref)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return context.ref.replace(/^refs\/heads\//g, '');
|
return ctx.ref.replace(/^refs\/heads\//g, '');
|
||||||
},
|
},
|
||||||
tag: function () {
|
tag: function () {
|
||||||
if (!/^refs\/tags\//.test(context.ref)) {
|
if (!/^refs\/tags\//.test(ctx.ref)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return context.ref.replace(/^refs\/tags\//g, '');
|
return ctx.ref.replace(/^refs\/tags\//g, '');
|
||||||
},
|
},
|
||||||
sha: function () {
|
sha: function () {
|
||||||
return Meta.shortSha(context.sha);
|
return ctx.sha.substring(0, 7);
|
||||||
},
|
},
|
||||||
base_ref: function () {
|
base_ref: function () {
|
||||||
if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {
|
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
|
||||||
return context.payload.base_ref.replace(/^refs\/heads\//g, '');
|
return ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
|
||||||
}
|
}
|
||||||
// FIXME: keep this for backward compatibility even if doesn't always seem
|
// FIXME: keep this for backward compatibility even if doesn't always seem
|
||||||
// to return the expected branch. See the comment below.
|
// to return the expected branch. See the comment below.
|
||||||
if (/^refs\/pull\//.test(context.ref) && context.payload?.pull_request?.base?.ref != undefined) {
|
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
|
||||||
return context.payload.pull_request.base.ref;
|
return ctx.payload.pull_request.base.ref;
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
commit_date: function (format, options) {
|
|
||||||
const m = moment(commitDate);
|
|
||||||
let tz = 'UTC';
|
|
||||||
Object.keys(options.hash).forEach(key => {
|
|
||||||
switch (key) {
|
|
||||||
case 'tz':
|
|
||||||
tz = options.hash[key];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unknown ${key} attribute`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return m.tz(tz).format(format);
|
|
||||||
},
|
|
||||||
is_default_branch: function () {
|
is_default_branch: function () {
|
||||||
const branch = context.ref.replace(/^refs\/heads\//g, '');
|
const branch = ctx.ref.replace(/^refs\/heads\//g, '');
|
||||||
// TODO: "base_ref" is available in the push payload but doesn't always seem to
|
// TODO: "base_ref" is available in the push payload but doesn't always seem to
|
||||||
// return the expected branch when the push tag event occurs. It's also not
|
// return the expected branch when the push tag event occurs. It's also not
|
||||||
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
|
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
|
||||||
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
|
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
|
||||||
// if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {
|
// if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
|
||||||
// branch = context.payload.base_ref.replace(/^refs\/heads\//g, '');
|
// branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
|
||||||
// }
|
// }
|
||||||
if (branch == undefined || branch.length == 0) {
|
if (branch == undefined || branch.length == 0) {
|
||||||
return 'false';
|
return 'false';
|
||||||
}
|
}
|
||||||
if (context.payload?.repository?.default_branch == branch) {
|
if (ctx.payload?.repository?.default_branch == branch) {
|
||||||
return 'true';
|
return 'true';
|
||||||
}
|
}
|
||||||
// following events always trigger for last commit on default branch
|
// following events always trigger for last commit on default branch
|
||||||
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
|
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
|
||||||
if (/create/.test(context.eventName) || /discussion/.test(context.eventName) || /issues/.test(context.eventName) || /schedule/.test(context.eventName)) {
|
if (/create/.test(ctx.eventName) || /discussion/.test(ctx.eventName) || /issues/.test(ctx.eventName) || /schedule/.test(ctx.eventName)) {
|
||||||
return 'true';
|
return 'true';
|
||||||
}
|
}
|
||||||
return 'false';
|
return 'false';
|
||||||
@ -471,43 +454,22 @@ export class Meta {
|
|||||||
if (!this.version.main) {
|
if (!this.version.main) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
const tags: Array<string> = [];
|
||||||
const generateTags = (imageName: string, version: string): Array<string> => {
|
for (const imageName of this.getImageNames()) {
|
||||||
const tags: Array<string> = [];
|
tags.push(`${imageName}:${this.version.main}`);
|
||||||
const prefix = imageName !== '' ? `${imageName}:` : '';
|
|
||||||
tags.push(`${prefix}${version}`);
|
|
||||||
for (const partial of this.version.partial) {
|
for (const partial of this.version.partial) {
|
||||||
tags.push(`${prefix}${partial}`);
|
tags.push(`${imageName}:${partial}`);
|
||||||
}
|
}
|
||||||
if (this.version.latest) {
|
if (this.version.latest) {
|
||||||
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
|
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
|
||||||
tags.push(`${prefix}${Meta.sanitizeTag(latestTag)}`);
|
tags.push(`${imageName}:${Meta.sanitizeTag(latestTag)}`);
|
||||||
}
|
}
|
||||||
return tags;
|
|
||||||
};
|
|
||||||
|
|
||||||
const tags: Array<string> = [];
|
|
||||||
const images = this.getImageNames();
|
|
||||||
if (images.length > 0) {
|
|
||||||
for (const imageName of images) {
|
|
||||||
tags.push(...generateTags(imageName, this.version.main));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tags.push(...generateTags('', this.version.main));
|
|
||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLabels(): Array<string> {
|
public getLabels(): Array<string> {
|
||||||
return this.getOCIAnnotationsWithCustoms(this.inputs.labels);
|
const labels: Array<string> = [
|
||||||
}
|
|
||||||
|
|
||||||
public getAnnotations(): Array<string> {
|
|
||||||
return this.getOCIAnnotationsWithCustoms(this.inputs.annotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getOCIAnnotationsWithCustoms(extra: string[]): Array<string> {
|
|
||||||
const res: Array<string> = [
|
|
||||||
`org.opencontainers.image.title=${this.repo.name || ''}`,
|
`org.opencontainers.image.title=${this.repo.name || ''}`,
|
||||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||||
@ -517,28 +479,11 @@ export class Meta {
|
|||||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||||
];
|
];
|
||||||
extra.forEach(label => {
|
labels.push(...this.inputs.labels);
|
||||||
res.push(this.setGlobalExp(label));
|
return labels;
|
||||||
});
|
|
||||||
|
|
||||||
return Array.from(
|
|
||||||
new Map<string, string>(
|
|
||||||
res
|
|
||||||
.map(label => label.split('='))
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
.filter(([_key, ...values]) => values.length > 0)
|
|
||||||
.map(([key, ...values]) => [key, values.join('=')] as [string, string])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
||||||
.map(([key, value]) => `${key}=${value}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getJSON(alevels: string[]): unknown {
|
public getJSON(): unknown {
|
||||||
const annotations: Array<string> = [];
|
|
||||||
for (const level of alevels) {
|
|
||||||
annotations.push(...this.getAnnotations().map(label => `${level}:${label}`));
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
tags: this.getTags(),
|
tags: this.getTags(),
|
||||||
labels: this.getLabels().reduce((res, label) => {
|
labels: this.getLabels().reduce((res, label) => {
|
||||||
@ -548,74 +493,39 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
res[matches[1]] = matches[2];
|
res[matches[1]] = matches[2];
|
||||||
return res;
|
return res;
|
||||||
}, {}),
|
}, {})
|
||||||
annotations: annotations
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBakeFile(kind: string): string {
|
public getBakeFile(): string {
|
||||||
if (kind == 'tags') {
|
const bakeFile = path.join(tmpDir(), 'docker-metadata-action-bake.json').split(path.sep).join(path.posix.sep);
|
||||||
return this.generateBakeFile(
|
fs.writeFileSync(
|
||||||
|
bakeFile,
|
||||||
|
JSON.stringify(
|
||||||
{
|
{
|
||||||
tags: this.getTags(),
|
target: {
|
||||||
args: {
|
[this.inputs.bakeTarget]: {
|
||||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
tags: this.getTags(),
|
||||||
DOCKER_META_VERSION: this.version.main
|
labels: this.getLabels().reduce((res, label) => {
|
||||||
|
const matches = label.match(/([^=]*)=(.*)/);
|
||||||
|
if (!matches) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
res[matches[1]] = matches[2];
|
||||||
|
return res;
|
||||||
|
}, {}),
|
||||||
|
args: {
|
||||||
|
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||||
|
DOCKER_META_VERSION: this.version.main
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
kind
|
null,
|
||||||
);
|
2
|
||||||
} else if (kind == 'labels') {
|
)
|
||||||
return this.generateBakeFile(
|
);
|
||||||
{
|
|
||||||
labels: this.getLabels().reduce((res, label) => {
|
|
||||||
const matches = label.match(/([^=]*)=(.*)/);
|
|
||||||
if (!matches) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
res[matches[1]] = matches[2];
|
|
||||||
return res;
|
|
||||||
}, {})
|
|
||||||
},
|
|
||||||
kind
|
|
||||||
);
|
|
||||||
} else if (kind.startsWith('annotations:')) {
|
|
||||||
const name = kind.split(':')[0];
|
|
||||||
const annotations: Array<string> = [];
|
|
||||||
for (const level of kind.split(':')[1].split(',')) {
|
|
||||||
annotations.push(...this.getAnnotations().map(label => `${level}:${label}`));
|
|
||||||
}
|
|
||||||
return this.generateBakeFile(
|
|
||||||
{
|
|
||||||
annotations: annotations
|
|
||||||
},
|
|
||||||
name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw new Error(`Unknown bake file type: ${kind}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getBakeFileTagsLabels(): string {
|
|
||||||
return this.generateBakeFile({
|
|
||||||
tags: this.getTags(),
|
|
||||||
labels: this.getLabels().reduce((res, label) => {
|
|
||||||
const matches = label.match(/([^=]*)=(.*)/);
|
|
||||||
if (!matches) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
res[matches[1]] = matches[2];
|
|
||||||
return res;
|
|
||||||
}, {}),
|
|
||||||
args: {
|
|
||||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
|
||||||
DOCKER_META_VERSION: this.version.main
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateBakeFile(dt, suffix?: string): string {
|
|
||||||
const bakeFile = path.join(ToolkitContext.tmpDir(), `docker-metadata-action-bake${suffix ? `-${suffix}` : ''}.json`);
|
|
||||||
fs.writeFileSync(bakeFile, JSON.stringify({target: {[this.inputs.bakeTarget]: dt}}, null, 2));
|
|
||||||
return bakeFile;
|
return bakeFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,18 +536,4 @@ export class Meta {
|
|||||||
private static sanitizeTag(tag: string): string {
|
private static sanitizeTag(tag: string): string {
|
||||||
return tag.replace(/[^a-zA-Z0-9._-]+/g, '-');
|
return tag.replace(/[^a-zA-Z0-9._-]+/g, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static shortSha(sha: string): string {
|
|
||||||
let shortShaLength = defaultShortShaLength;
|
|
||||||
if (process.env.DOCKER_METADATA_SHORT_SHA_LENGTH) {
|
|
||||||
if (isNaN(Number(process.env.DOCKER_METADATA_SHORT_SHA_LENGTH))) {
|
|
||||||
throw new Error(`DOCKER_METADATA_SHORT_SHA_LENGTH is not a valid number: ${process.env.DOCKER_METADATA_SHORT_SHA_LENGTH}`);
|
|
||||||
}
|
|
||||||
shortShaLength = Number(process.env.DOCKER_METADATA_SHORT_SHA_LENGTH);
|
|
||||||
}
|
|
||||||
if (shortShaLength >= sha.length) {
|
|
||||||
return sha;
|
|
||||||
}
|
|
||||||
return sha.substring(0, shortShaLength);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
@ -4,11 +4,9 @@ RUN apk add --no-cache coreutils jq
|
|||||||
ARG DOCKER_METADATA_OUTPUT_VERSION
|
ARG DOCKER_METADATA_OUTPUT_VERSION
|
||||||
ARG DOCKER_METADATA_OUTPUT_TAGS
|
ARG DOCKER_METADATA_OUTPUT_TAGS
|
||||||
ARG DOCKER_METADATA_OUTPUT_LABELS
|
ARG DOCKER_METADATA_OUTPUT_LABELS
|
||||||
ARG DOCKER_METADATA_OUTPUT_ANNOTATIONS
|
|
||||||
ARG DOCKER_METADATA_OUTPUT_JSON
|
ARG DOCKER_METADATA_OUTPUT_JSON
|
||||||
RUN printenv DOCKER_METADATA_OUTPUT_VERSION
|
RUN printenv DOCKER_METADATA_OUTPUT_VERSION
|
||||||
RUN printenv DOCKER_METADATA_OUTPUT_TAGS
|
RUN printenv DOCKER_METADATA_OUTPUT_TAGS
|
||||||
RUN printenv DOCKER_METADATA_OUTPUT_LABELS
|
RUN printenv DOCKER_METADATA_OUTPUT_LABELS
|
||||||
RUN printenv DOCKER_METADATA_OUTPUT_ANNOTATIONS
|
|
||||||
RUN printenv DOCKER_METADATA_OUTPUT_JSON
|
RUN printenv DOCKER_METADATA_OUTPUT_JSON
|
||||||
RUN echo $DOCKER_METADATA_OUTPUT_JSON | jq
|
RUN echo $DOCKER_METADATA_OUTPUT_JSON | jq
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"esModuleInterop": true,
|
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"strict": true,
|
|
||||||
"newLine": "lf",
|
"newLine": "lf",
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
|
"esModuleInterop": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"useUnknownInCatchVariables": false,
|
"useUnknownInCatchVariables": false,
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"./__mocks__/**/*",
|
|
||||||
"./__tests__/**/*",
|
|
||||||
"./lib/**/*",
|
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
"**/*.test.ts",
|
||||||
"jest.config.ts"
|
"jest.config.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user