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

Migrate docker-ci-tools workflow to Github Actions #4454

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/docker-ci-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: docker-ci-tools
on:
push:
branches:
- 'main'
paths:
- 'tools/**'

env:
IMAGE_NAME: grafana/tempo-ci-tools

# Needed to login to DockerHub
permissions:
contents: read
id-token: write

jobs:

get-image-tag:
runs-on: ubuntu-24.04
outputs:
tag: ${{ steps.get-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4

- id: get-tag
run: |
echo "tag=$(./tools/image-tag)" >> "$GITHUB_OUTPUT"
docker-ci-tools:
needs: get-image-tag
strategy:
matrix:
runner_arch: [ { runner: ubuntu-24.04, arch: amd64 }, { runner: github-hosted-ubuntu-arm64, arch: arm64 } ]
runs-on: ${{ matrix.runner_arch.runner }}
env:
TAG: ${{ needs.get-image-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to DockerHub
uses: grafana/shared-workflows/actions/[email protected]

- name: docker-build-and-push
Copy link
Contributor

Choose a reason for hiding this comment

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

have you tried this action?

docker/build-push-action@v6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had seen that but I prefer to do it this way because it is more explicit and we can build each platform natively, while the other action relies on QEMU which is probably slower.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not opposed to it but other teams are using it:

https://github.com/grafana/loki/blob/e6d82b9253a46a08120dccf4317fd1d25c1d4ca3/.github/workflows/images.yml#L48

I think it simplifies the process

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I say we review this once we have migrated everything, I'm sure there's room for optimization in our CI but I don't want to change things too much during the migration to make sure I don't break any process.

run: |
TAG_ARCH="$TAG-${{ matrix.runner_arch.arch }}"
docker build -f tools/Dockerfile -t $IMAGE_NAME:$TAG_ARCH .
docker push $IMAGE_NAME:$TAG_ARCH
manifest:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not needed since we are not pushing a multi-architecture image yet

Copy link
Contributor

Choose a reason for hiding this comment

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

And it can be achieved as well with docker build-push-action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Drone we do something very similar to what I'm doing here, that is, build each platform natively and then create a multi-platform manifest -- only that in Drone we use some opaque plugins.

To clarify, this workflow is a combination of these Drone pipelines:

needs: ['get-image-tag', 'docker-ci-tools']
runs-on: ubuntu-latest
env:
TAG: ${{ needs.get-image-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to DockerHub
uses: grafana/shared-workflows/actions/[email protected]

- name: docker-manifest-create-and-push
run: |
docker manifest create \
$IMAGE_NAME:$TAG \
--amend $IMAGE_NAME:$TAG-amd64 \
--amend $IMAGE_NAME:$TAG-arm64
docker manifest push $IMAGE_NAME:$TAG
docker manifest create \
$IMAGE_NAME:latest \
--amend $IMAGE_NAME:$TAG-amd64 \
--amend $IMAGE_NAME:$TAG-arm64
docker manifest push $IMAGE_NAME:latest