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

🚀 Add Dockerhub publish during release #347

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

giom-l
Copy link

@giom-l giom-l commented May 3, 2024

What changes did you make? (Give an overview)
Add login to dockerhub and push image to it in main workflow
Fixes #237

Is there anything you'd like reviewers to focus on?
Secrets names may need to be changed based on what is currently available (no visibility on it)

How Has This Been Tested? (put an "x" (case-sensitive!) next to an item)

  • Yes, on my forked project with own credentials

Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)

  • I have performed a self-review of my own code

Check out Contributing and Code of Conduct

image

@giom-l giom-l requested a review from a team as a code owner May 3, 2024 11:00
@kapybro kapybro bot added status/triage Issues pending maintainers triage status/triage/manual Manual triage in progress status/triage/completed Automatic triage completed and removed status/triage Issues pending maintainers triage labels May 3, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hi giom-l! 👋

Welcome, and thank you for opening your first PR in the repo!

Please wait for triaging by our maintainers.

Please take a look at our contributing guide.

Copy link
Member

@Haarolean Haarolean left a comment

Choose a reason for hiding this comment

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

Hi, could you make this a separate job (within the same workflow) please? So we don't have to rebuild (or re-push) everything if one of the things fail.
Ideally:

  • build
  • ghcr push
  • dockerhub push
  • aws ecr push

You'd need to transfer artifacts between the jobs, feel free to use .github/workflows/e2e-*.yml workflows as reference.

@giom-l
Copy link
Author

giom-l commented May 7, 2024

Hi,
I spent some time last days to on that and mostly struggled with my own station to have quicker local builds...
Anyway I also took into account #349 to go with a solution that would support it.

So here are 2 versions that work the same, let me know which one your prefer.
In both, I had to activate containerd as builder, for some different reasons (being able to load multi platforms images & preserve provenance attestations)

With docker save / docker load mechanism :
https://github.com/giom-l/kafka-ui/blob/feat/improve_docker_publish/.github/workflows/save_load.yml

With containerd all along (using oci output & ctr to reuse the produced image)
https://github.com/giom-l/kafka-ui/blob/feat/improve_docker_publish/.github/workflows/with_ctr.yml

All produced images can be found in all 3 repositories :

For ECR, my workflow uses OIDC provider .
It would be the same with classic credentials (I saw some in your other workflows) and even be less verbose by using this action that would allow something like

- name: Push to ECR
  id: ecr
  uses: jwalton/gh-ecr-push@v2
  with:
    access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    region: us-east-1
    local-image: kafka-ui:temp
    image: <repo>/kafka-ui:main, <repo>/kafka-ui:<sha>

@Haarolean Haarolean self-assigned this May 7, 2024
@Haarolean Haarolean added type/enhancement En enhancement/improvement to an already existing feature scope/infra CI, CD, dev. env, etc. and removed status/triage/manual Manual triage in progress labels May 7, 2024
@Haarolean
Copy link
Member

Hi, I spent some time last days to on that and mostly struggled with my own station to have quicker local builds... Anyway I also took into account #349 to go with a solution that would support it.

So here are 2 versions that work the same, let me know which one your prefer. In both, I had to activate containerd as builder, for some different reasons (being able to load multi platforms images & preserve provenance attestations)

With docker save / docker load mechanism : https://github.com/giom-l/kafka-ui/blob/feat/improve_docker_publish/.github/workflows/save_load.yml

With containerd all along (using oci output & ctr to reuse the produced image) https://github.com/giom-l/kafka-ui/blob/feat/improve_docker_publish/.github/workflows/with_ctr.yml

All produced images can be found in all 3 repositories :

For ECR, my workflow uses OIDC provider . It would be the same with classic credentials (I saw some in your other workflows) and even be less verbose by using this action that would allow something like

- name: Push to ECR
  id: ecr
  uses: jwalton/gh-ecr-push@v2
  with:
    access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    region: us-east-1
    local-image: kafka-ui:temp
    image: <repo>/kafka-ui:main, <repo>/kafka-ui:<sha>

@giom-l thank you for the analysis. I'd prefer using docker save/load mechanism to have the same approach between different workflows (for example, e2e-run.yml, already uses this approach).

Can you update the PR branch with this approach so we can proceed with the review? Thank you

@Haarolean Haarolean assigned giom-l and unassigned Haarolean May 19, 2024
@giom-l
Copy link
Author

giom-l commented May 20, 2024

Sorry for the delay !
I updated the PR using the save/load mechanism as requested.
I also impacted the release workflow that I forgot initially.

For the ECR publish, it's still "WIP" as I would need some informations about how you want to authenticate and where (ecr public ?)

@giom-l giom-l requested a review from Haarolean May 22, 2024 10:07
@Haarolean
Copy link
Member

Haarolean commented May 22, 2024

I updated the PR using the save/load mechanism as requested.

Thank you.

about how you want to authenticate

I guess, we could auth the same way we do here (unless you have a better suggestion?)

and where (ecr public ?)

Yes, as we (accidentally) had one before (source).

Can I also ask you to refactor the workflows to use reusable workflows to reduce the copypaste in these workflows? I can take a look myself later as an alternative.

@giom-l
Copy link
Author

giom-l commented May 23, 2024

Sure.
Just a question about how you see that :)
One reusable action per target registry (ecr, github, ecr) ?
Or one reusable action (something like image-publish) that push to all registries (but I'm not sure how it behave if one of them fails. Can we still rerun just a part of it ?) ?

I thought about one generic reusable action that will take parameters (like registry, credentials) but since ECR login is not the same as the other, I'm not sure it's doable.

Let me know what you think

@Haarolean
Copy link
Member

Haarolean commented May 23, 2024

I see that as follows:

  1. A workflow to run on a push to main
  2. A workflow to run on a release
  3. Both 1) and 2) call another workflow to build an image (docker-build.yml) and a workflow to publish one (docker-publish.yml)
  4. docker-publish.yml contains 3 jobs for each registry (gh, ecr, dockerhub)
    In this case we can extract common parts for each workflow and keep publishing as separate jobs within a separate calling workflow.

Feel free to use e2e-*.yml workflows as templates, we have the basic required stuff there (calling other workflows, passing arguments through, transferring artifacts between jobs, etc.)

Can we still rerun just a part of it

Yes, we would be able to rerun separate jobs within a workflow like this:
image

@giom-l giom-l force-pushed the feat/add_dockerhub_publish branch from 4d38eb9 to f3f57d8 Compare May 27, 2024 10:49
@giom-l
Copy link
Author

giom-l commented May 27, 2024

Hello

I gave this some time yesterday and made it work as follows (PR udpated) :

  • 1 docker_build.yml workflow
  • 1 docker_publish.yml workflow, which itself calls 3 differents workflows :
    • 1 publish_ecr.yml
    • 1 publish_dockerhub.yml
    • 1 publish_ghcr.yml

About extracting common parts for the three publish jobs :
It seems not really useful to me since it's only a matter of downloading artifacts & configuring docker daemon, which can't be shared between jobs.

However, I also experienced another solution that can be found in this branch :
The main & release job will call the docker_publish and this one is more generic (only the logging part isn't) and uses matrix instead of calling others workflows.
I find this solution to be more elegant (less duplicated code, no intermediary workflow)

Let me know what you think and I'll finalize the PR with the solution that is preferred on your side.

@giom-l giom-l force-pushed the feat/add_dockerhub_publish branch from 48df758 to b02611a Compare May 27, 2024 13:53
${{ runner.os }}-buildx-
name: kafbat-ui-${{ steps.build.outputs.version }}
path: api/target/api-${{ steps.build.outputs.version }}.jar
retention-days: 7
Copy link
Member

Choose a reason for hiding this comment

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

let's do 1, the jars are pretty fat to hold in the cache for too long

runs-on: ubuntu-latest

permissions:
contents: read
packages: write
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 think we need packages here anymore as we're building image in a separate job

daemon-config: |
{
"features": {
"containerd-snapshotter": true
Copy link
Member

Choose a reason for hiding this comment

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

why is this containerd-snapshotter thing required?

@Haarolean
Copy link
Member

Hey, sorry for the delay.

One more thing, can we get separate workflows like publish_x.yml to be separate jobs within one workflow instead? I don't see any point in making them separate workflows rather than jobs, it just adds additional overhead. Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope/infra CI, CD, dev. env, etc. status/triage/completed Automatic triage completed type/enhancement En enhancement/improvement to an already existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upload docker image to DockerHub as well
2 participants