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

Create CI for building word-count applications #19

Closed
wants to merge 25 commits into from
Closed

Conversation

irux
Copy link

@irux irux commented Sep 19, 2023

closes #16

shell: bash
working-directory: ${{env.WORKING_DIRECTORY_APP}}

- name: Upload ${{env.SENTENCE_PRODUCER_IMAGE_NAME}} image artifact
Copy link
Member

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

@disrupted disrupted changed the title Add CI to the word-count pipeline Create CI for building word-count applications Sep 20, 2023
Comment on lines 87 to 141
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}}
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member

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

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

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

That should work

Copy link
Contributor

@raminqaf raminqaf Sep 22, 2023

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.

Copy link
Author

Choose a reason for hiding this comment

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

like this @raminqaf

Comment on lines 68 to 91
./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
Copy link
Contributor

@raminqaf raminqaf Sep 25, 2023

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

Copy link
Contributor

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

Comment on lines 14 to 16
working-directory:
description: "working directory to run the commands"
required: true
Copy link
Contributor

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 "
Copy link
Contributor

@raminqaf raminqaf Oct 4, 2023

Choose a reason for hiding this comment

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

WDYT?

Suggested change
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"
Copy link
Contributor

@raminqaf raminqaf Oct 4, 2023

Choose a reason for hiding this comment

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

Suggested change
description: "Build the Jib image and upload it to the image repository"
description: "Build the Jib image and push it to the image repository."

Copy link
Contributor

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! ❤️

Copy link
Author

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 ?

Copy link
Member

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 :)

Copy link
Contributor

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.

Copy link
Author

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

@raminqaf
Copy link
Contributor

Closing due to inactivity and solved in #29

@raminqaf raminqaf closed this Dec 12, 2024
@disrupted disrupted deleted the feature/ci branch December 12, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create CI for building and publishing word-count apps
4 participants