Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use docker/metadata-action to gather tags/labels #3998

Merged
merged 4 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,27 @@ jobs:
with:
subject-path: "${{ github.workspace }}/build/aws/elastic-apm-node-lambda-layer-*.zip"

- id: docker-vars
name: Set up docker variables
run: |-
if [ "${{ startsWith(github.ref, 'refs/tags') }}" == "false" ] ; then
# for testing purposes
echo "tag=test" >> "${GITHUB_OUTPUT}"
echo "latest=test-latest" >> "${GITHUB_OUTPUT}"
else
# version without v prefix (e.g. 1.2.3)
echo "tag=${GITHUB_REF_NAME/v/}" >> "${GITHUB_OUTPUT}"
echo "latest=latest" >> "${GITHUB_OUTPUT}"
fi
- name: Extract metadata (tags, labels)
id: docker-meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
flavor: |
latest=auto
tags: |
# "1.2.3" and "latest" Docker tags on push of git tag "v1.2.3"
type=semver,pattern={{version}}
# "edge" Docker tag on git push to default branch
type=edge

- name: Build and Push Docker Image
id: docker-push
uses: docker/build-push-action@v5.3.0
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMAGE_NAME }}:${{ steps.docker-vars.outputs.tag }}
${{ env.DOCKER_IMAGE_NAME }}:${{ steps.docker-vars.outputs.latest }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record this results in adding a number of labels that we never had before:

Before:

/usr/bin/docker buildx build --build-arg AGENT_DIR=/build/dist/nodejs --iidfile /home/runner/work/_temp/docker-actions-toolkit-fyNsIK/iidfile --tag docker.elastic.co/observability/apm-agent-nodejs:test --tag docker.elastic.co/observability/apm-agent-nodejs:test-latest --metadata-file /home/runner/work/_temp/docker-actions-toolkit-fyNsIK/metadata-file --push .

after:

/usr/bin/docker buildx build --build-arg AGENT_DIR=/build/dist/nodejs --iidfile /home/runner/work/_temp/docker-actions-toolkit-zpfy5E/iidfile --label org.opencontainers.image.created=2024-04-29T12:16:23.000Z --label org.opencontainers.image.description=Elastic APM Node.js Agent --label org.opencontainers.image.licenses=BSD-2-Clause --label org.opencontainers.image.revision=f9f28681ae69736728d15aaa93880fffba5f2e6d --label org.opencontainers.image.source=https://github.com/elastic/apm-agent-nodejs --label org.opencontainers.image.title=apm-agent-nodejs --label org.opencontainers.image.url=https://github.com/elastic/apm-agent-nodejs --label org.opencontainers.image.version=test-latest --tag docker.elastic.co/observability/apm-agent-nodejs:test-latest --metadata-file /home/runner/work/_temp/docker-actions-toolkit-zpfy5E/metadata-file .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the opencontainer default labels:

We can remove them, sorry if I was not clear about this change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong argument either way. If we add these, then they somewhat become a promise that we will always define them in the future. I don't think it likely that that will be an issue.

On balance, I would be inclined to not add these labels unless there is a known use case to have them. I am fine either way however.

build-args: |
AGENT_DIR=/build/dist/nodejs

Expand Down