-
-
Notifications
You must be signed in to change notification settings - Fork 145
Infra: Add actions to publish to ECR & Docker Hub #347
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
65e665b
:rocket: Add Dockerhub publish during release
giom-l 21ce33b
:wrench: Stick with save/load mechanism and also add ecr publish
giom-l 3452d9b
Feat/test split (#1)
giom-l 8758ebc
remove useless comments & steps
giom-l 5a14050
remove uneeded permissions and lower jar artifact retention
giom-l f071912
Switch to matrix workflow
giom-l f2a6504
Clean unneeded workflows
giom-l aa6a8e9
Fix permissions set on docker build/publish and align with main & rel…
giom-l 2c9fad6
Merge branch 'main' into feat/add_dockerhub_publish
Haarolean e4b3f55
Lint
Haarolean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: "Docker build" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
sha: | ||
required: true | ||
type: string | ||
version: | ||
required: true | ||
type: string | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
token: ${{ github.token }} | ||
|
||
- name: Download maven artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: kafbat-ui-${{ inputs.version }} | ||
path: api/target | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ inputs.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
|
||
# Build multi platform images and loading them at the same time is not possible with default container runtime : https://github.com/docker/buildx/issues/59 | ||
# So let's use containerd instead as it supports this option | ||
# Also containerd is one of the option to allow preserving provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations | ||
- name: Setup docker with containerd | ||
uses: crazy-max/ghaction-setup-docker@v3 | ||
with: | ||
daemon-config: | | ||
{ | ||
"features": { | ||
"containerd-snapshotter": true | ||
} | ||
} | ||
|
||
- name: Build docker image | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
context: api | ||
platforms: linux/amd64,linux/arm64 | ||
provenance: mode=min | ||
sbom: true | ||
push: false | ||
load: true | ||
tags: | | ||
kafka-ui:temp | ||
build-args: | | ||
JAR_FILE=api-${{ inputs.version }}.jar | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
|
||
- name: Dump docker image | ||
run: | | ||
docker image save kafka-ui:temp > /tmp/image.tar | ||
|
||
- name: Upload docker image | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: image | ||
path: /tmp/image.tar | ||
retention-days: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
|
||
name: "Docker publish" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
version: | ||
required: true | ||
type: string | ||
generic_tag: | ||
required: true | ||
type: string | ||
|
||
permissions: | ||
packages: write | ||
id-token: write # Required to authenticate with OIDC for AWS | ||
|
||
jobs: | ||
deploy: | ||
continue-on-error: true | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
registry: ['docker.io', 'ghcr.io', 'ecr'] | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Download docker image | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: image | ||
path: /tmp | ||
|
||
# setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations | ||
- name: Setup docker with containerd | ||
uses: crazy-max/ghaction-setup-docker@v3 | ||
with: | ||
daemon-config: | | ||
{ | ||
"features": { | ||
"containerd-snapshotter": true | ||
} | ||
} | ||
|
||
- name: Load docker image into daemon | ||
run: | | ||
docker load --input /tmp/image.tar | ||
|
||
- name: Login to docker.io | ||
if: matrix.registry == 'docker.io' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ matrix.registry }} | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Login to ghcr.io | ||
if: matrix.registry == 'ghcr.io' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ matrix.registry }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Configure AWS credentials | ||
if: matrix.registry == 'ecr' | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-region: us-east-1 # This region only for public ECR | ||
role-to-assume: ${{ secrets.AWS_ROLE }} | ||
|
||
- name: Login to public ECR | ||
if: matrix.registry == 'ecr' | ||
id: login-ecr-public | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
with: | ||
registry-type: public | ||
|
||
- name: define env vars | ||
run: | | ||
if [ ${{matrix.registry }} == 'docker.io' ]; then | ||
echo "REGISTRY=${{ matrix.registry }}" >> $GITHUB_ENV | ||
echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV | ||
elif [ ${{ matrix.registry }} == 'ghcr.io' ]; then | ||
echo "REGISTRY=${{ matrix.registry }}" >> $GITHUB_ENV | ||
echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV | ||
elif [ ${{ matrix.registry }} == 'ecr' ]; then | ||
echo "REGISTRY=${{ steps.login-ecr-public.outputs.registry }}" >> $GITHUB_ENV | ||
echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV | ||
else | ||
echo "REGISTRY=" >> $GITHUB_ENV | ||
echo "REPOSITORY=notworking" >> $GITHUB_ENV | ||
fi | ||
|
||
- name: Push images to ${{ matrix.registry }} | ||
run: | | ||
docker tag kafka-ui:temp ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.generic_tag }} | ||
docker tag kafka-ui:temp ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.version }} | ||
docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.generic_tag }} | ||
docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.version }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.