-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create CI for building word-count applications #19
Conversation
.github/workflows/ci.yaml
Outdated
shell: bash | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} | ||
|
||
- name: Upload ${{env.SENTENCE_PRODUCER_IMAGE_NAME}} image artifact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid using artifacts as it is slow. Just have another step next that directly pushes the images
.github/workflows/ci.yaml
Outdated
publish-jib-image: | ||
name: Publish tarball images | ||
runs-on: ubuntu-22.04 | ||
needs: build-jib | ||
|
||
steps: | ||
- name: Download Docker ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}} tar artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}} | ||
path: ${{env.WORKING_DIRECTORY_APP}}/build | ||
|
||
- name: Download Docker ${{env.SENTENCE_PRODUCER_IMAGE_NAME}} tar artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ${{env.SENTENCE_PRODUCER_IMAGE_NAME}} | ||
path: ${{env.WORKING_DIRECTORY_APP}}/build | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Publish Docker image | ||
run: | | ||
if [[ $(ls -1 build/*.tar 2>/dev/null | wc -l) != 2 ]]; then | ||
>&2 echo "Error: images tar files are needed in the downloaded artifact. You can upload them before using this action: https://github.com/actions/upload-artifact." | ||
exit 1 | ||
fi | ||
docker load --input build/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}.tar | ||
docker load --input build/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}.tar | ||
if [[ "$GITHUB_REF" =~ ^refs/tags/.* ]]; then | ||
# SENTENCE_PRODUCER | ||
docker tag ${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${{ github.run_id }} ${{ env.DOCKER_REGISTRY }}/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:latest | ||
docker tag ${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${{ github.run_id }} ${{ env.DOCKER_REGISTRY }}/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${GITHUB_REF/refs\/tags\//} | ||
docker push ${{ env.DOCKER_REGISTRY }}/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:latest | ||
docker push ${{ env.DOCKER_REGISTRY }}/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${GITHUB_REF/refs\/tags\//} | ||
|
||
# WORD_COUNT_APP | ||
docker tag ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${{ github.run_id }} ${{ env.DOCKER_REGISTRY }}/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:latest | ||
docker tag ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${{ github.run_id }} ${{ env.DOCKER_REGISTRY }}/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${GITHUB_REF/refs\/tags\//} | ||
docker push ${{ env.DOCKER_REGISTRY }}/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:latest | ||
docker push ${{ env.DOCKER_REGISTRY }}/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${GITHUB_REF/refs\/tags\//} | ||
else | ||
# SENTENCE_PRODUCER | ||
docker tag ${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${{ github.run_id }} ${{ env.DOCKER_REGISTRY }}/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${{ github.run_id }} | ||
docker push ${{ env.DOCKER_REGISTRY }}/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}:${{ github.run_id }} | ||
|
||
# WORD_COUNT_APP | ||
docker tag ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${{ github.run_id }} ${{ env.DOCKER_REGISTRY }}/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${{ github.run_id }} | ||
docker push ${{ env.DOCKER_REGISTRY }}/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}:${{ github.run_id }} | ||
fi | ||
shell: bash | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just
# deploy producer app
gradle jib -Djib.to.image=bakdata/kpops-demo-sentence-producer -Djib.container.mainClass=com.bakdata.kpops.examples.SentenceProducer
# deploy streams-app
gradle jib -Djib.to.image=bakdata/kpops-demo-word-count-app-Djib.container.mainClass=com.bakdata.kpops.examples.WordCountApplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It builds and pushes the image, and IMO it is completely sufficient for this simple example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you cannot control the tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
# deploy producer app
gradle jib -Djib.to.image=bakdata/kpops-demo-sentence-producer:tag1 -Djib.container.mainClass=com.bakdata.kpops.examples.SentenceProducer
# deploy streams-app
gradle jib -Djib.to.image=bakdata/kpops-demo-word-count-app:tag2 -Djib.container.mainClass=com.bakdata.kpops.examples.WordCountApplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to set multiple tags. latest and version for tag builds e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I don't understand why we can't use the flag -Djib.to.tags=a,b,c
gradle jib -Djib.to.image=bakdata/kpops-demo-word-count-app -Djib.container.mainClass=com.bakdata.kpops.examples.WordCountApplication
-Djib.to.tags=latest,version-tag,bla
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@irux Then please remove all the docker commands and directly use the jib
command above to build, tag, and push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this @raminqaf
.github/workflows/ci.yaml
Outdated
./gradlew jib \ | ||
--info --stacktrace \ | ||
--image=$DOCKER_REGISTRY/$SENTENCE_PRODUCER_IMAGE_NAME \ | ||
-Djib.container.mainClass=com.bakdata.kpops.examples.SentenceProducer \ | ||
-Djib.to.tags=latest,${GITHUB_REF/refs\/tags\//} | ||
|
||
./gradlew jib \ | ||
--info --stacktrace \ | ||
--image=$DOCKER_REGISTRY/$WORD_COUNT_APPLICATION_IMAGE_NAME \ | ||
-Djib.container.mainClass=com.bakdata.kpops.examples.WordCountApplication \ | ||
-Djib.to.tags=latest,${GITHUB_REF/refs\/tags\//} | ||
else | ||
./gradlew jib \ | ||
--info --stacktrace \ | ||
--image=$DOCKER_REGISTRY/$SENTENCE_PRODUCER_IMAGE_NAME \ | ||
-Djib.container.mainClass=com.bakdata.kpops.examples.SentenceProducer \ | ||
-Djib.to.tags=${{ github.run_id }} | ||
|
||
./gradlew jib \ | ||
--info --stacktrace \ | ||
--image=$DOCKER_REGISTRY/$WORD_COUNT_APPLICATION_IMAGE_NAME \ | ||
-Djib.container.mainClass=com.bakdata.kpops.examples.WordCountApplication \ | ||
-Djib.to.tags=${{ github.run_id }} | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move these to its own reusable action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it takes the image, main class, and the tags as the input parameter
working-directory: | ||
description: "working directory to run the commands" | ||
required: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be optional. With the default of ./
@@ -0,0 +1,29 @@ | |||
name: "Build and upload Jib " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT?
name: "Build and upload Jib " | |
name: "Jib: build and push image" |
@@ -0,0 +1,29 @@ | |||
name: "Build and upload Jib " | |||
description: "Build the Jib image and upload it to the image repository" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: "Build the Jib image and upload it to the image repository" | |
description: "Build the Jib image and push it to the image repository." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A PR in https://github.com/bakdata/ci-templates would be appreciated! ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it makes sense to add this as an action ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, definitely! we would also need it for https://github.com/bakdata/pipeline-word-count :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the name of this action to jib
only? The -uploader
is a bit misleading. I thought it would use the upload action of GitHub to upload the tarball.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we don't want to use the artifacts uploader anymore (#19 (comment)) this action already push to the docker repository
Closing due to inactivity and solved in #29 |
closes #16