-
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
Changes from 13 commits
40a80d4
003348c
b087abe
743b209
39028bd
279cc44
9cfd202
5206c21
04ff945
3b1152a
ee27b9c
3ade98f
014e89d
b8f55da
15e851e
b0ee4b8
142e87a
6aeb0e7
b324bc5
87c1e73
d8a817b
2ea08b4
2543294
de985e9
c190681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
name: Build, Test and Publish | ||
|
||
on: | ||
push: | ||
tags: [ '**' ] | ||
branches: [ '**' ] | ||
|
||
env: | ||
DOCKER_REGISTRY: bakdata | ||
SENTENCE_PRODUCER_IMAGE_NAME: kpops-demo-sentence-producer | ||
WORD_COUNT_APPLICATION_IMAGE_NAME: kpops-demo-word-count-app | ||
WORKING_DIRECTORY_APP: "./word-count" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Build | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
gradle-version: "wrapper" | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-22.04 | ||
needs: build | ||
|
||
steps: | ||
- name: Test | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
gradle-version: "wrapper" | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} | ||
|
||
build-jib: | ||
name: Build tarball images | ||
runs-on: ubuntu-22.04 | ||
needs: test | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
|
||
- name: Set up Gradle | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
gradle-version: "wrapper" | ||
|
||
- name: Build Docker images | ||
run: | | ||
./gradlew jibBuildTar \ | ||
--info --stacktrace \ | ||
--image=$SENTENCE_PRODUCER_IMAGE_NAME:${{ github.run_id }} \ | ||
-Djib.outputPaths.tar=build/$SENTENCE_PRODUCER_IMAGE_NAME.tar -Djib.container.mainClass=com.bakdata.kpops.examples.SentenceProducer | ||
|
||
./gradlew jibBuildTar \ | ||
--info --stacktrace \ | ||
--image=$WORD_COUNT_APPLICATION_IMAGE_NAME:${{ github.run_id }} \ | ||
-Djib.outputPaths.tar=build/$WORD_COUNT_APPLICATION_IMAGE_NAME.tar -Djib.container.mainClass=com.bakdata.kpops.examples.WordCountApplication | ||
shell: bash | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} | ||
|
||
- name: Upload ${{env.SENTENCE_PRODUCER_IMAGE_NAME}} image artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{env.SENTENCE_PRODUCER_IMAGE_NAME}} | ||
path: ${{env.WORKING_DIRECTORY_APP}}/build/${{env.SENTENCE_PRODUCER_IMAGE_NAME}}.tar | ||
retention-days: 1 | ||
|
||
- name: Upload ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}} image artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}} | ||
path: ${{env.WORKING_DIRECTORY_APP}}/build/${{env.WORD_COUNT_APPLICATION_IMAGE_NAME}}.tar | ||
retention-days: 1 | ||
|
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. why not just
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Why not?
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. But I don't understand why we can't use the flag
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @irux Then please remove all the docker commands and directly use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like this @raminqaf |
||
|
||
release: | ||
name: Create GitHub release | ||
if: startsWith(github.ref, 'refs/tags/') | ||
runs-on: ubuntu-22.04 | ||
needs: publish-jib-image | ||
|
||
steps: | ||
- name: Release on Github | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
github-username: ${{ secrets.USERNAME }} | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Release | ||
|
||
env: | ||
WORKING_DIRECTORY_APP: "./word-count" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release-type: | ||
type: choice | ||
required: true | ||
default: patch | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Build | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
gradle-version: "wrapper" | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-22.04 | ||
needs: build | ||
|
||
steps: | ||
- name: Test | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
gradle-version: "wrapper" | ||
working-directory: ${{env.WORKING_DIRECTORY_APP}} | ||
|
||
release: | ||
name: Release | ||
runs-on: ubuntu-22.04 | ||
needs: test | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
ref: ${{ github.event.repository.default_branch }} | ||
persist-credentials: false # required for pushing to protected branch later | ||
fetch-depth: 0 # required to build the changelog | ||
|
||
|
||
- name: Release on Github | ||
id: release | ||
uses: bakdata/ci-templates/actions/[email protected] | ||
with: | ||
release-type: ${{ inputs.release-type }} | ||
github-email: ${{ secrets.GH_EMAIL }} | ||
github-username: ${{ secrets.GH_USERNAME }} | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
java-distribution: "microsoft" | ||
java-version: "17" | ||
working-directory: ${{ inputs.working-directory }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,7 @@ | ||
### Java | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
build | ||
bin | ||
.idea | ||
.vscode | ||
.DS_Store | ||
|
||
*.bin | ||
*.lock | ||
.gradle | ||
.* | ||
!.github | ||
!.gitignore | ||
!.gitmodules | ||
word-count/build/ | ||
word-count/out/ | ||
word-count/bin/ |
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