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
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/actions/jib-uploader/action.yaml
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Build and upload Jib "
description: "Build the Jib image and upload it to the image repository"

inputs:
image:
description: "The image name with its repository name"
required: true
tags:
description: "The tags to use to release the image"
required: true
class:
description: "The entrypoint class to be used for the image"
required: true
working-directory:
description: "working directory to run the commands"
required: true

runs:
using: "composite"
steps:
- name: Build Docker image
run: |
./gradlew jib \
--info --stacktrace \
--image=${{ inputs.image }} \
-Djib.container.mainClass=${{ inputs.class }} \
-Djib.to.tags=${{ inputs.tags }}
shell: bash
working-directory: ${{ inputs.working-directory }}
112 changes: 112 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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-and-publish-jib:
name: Build and publish 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: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build SentenceProducer image for tag release
if: startsWith(github.ref, 'refs/tags/')
uses: ./.github/actions/jib-uploader
with:
image: $DOCKER_REGISTRY/$SENTENCE_PRODUCER_IMAGE_NAME
class: com.bakdata.kpops.examples.SentenceProducer
tags: latest,${GITHUB_REF/refs\/tags\//}
working-directory: ${{env.WORKING_DIRECTORY_APP}}

- name: Build WordCountApplication image for tag release
if: startsWith(github.ref, 'refs/tags/')
uses: ./.github/actions/jib-uploader
with:
image: $DOCKER_REGISTRY/$WORD_COUNT_APPLICATION_IMAGE_NAME
class: com.bakdata.kpops.examples.WordCountApplication
tags: latest,${GITHUB_REF/refs\/tags\//}
working-directory: ${{env.WORKING_DIRECTORY_APP}}

- name: Build SentenceProducer image
uses: ./.github/actions/jib-uploader
with:
image: $DOCKER_REGISTRY/$SENTENCE_PRODUCER_IMAGE_NAME
class: com.bakdata.kpops.examples.SentenceProducer
tags: ${{ github.run_id }}
working-directory: ${{env.WORKING_DIRECTORY_APP}}

- name: Build WordCountApplication image
uses: ./.github/actions/jib-uploader
with:
image: $DOCKER_REGISTRY/$WORD_COUNT_APPLICATION_IMAGE_NAME
class: com.bakdata.kpops.examples.WordCountApplication
tags: ${{ github.run_id }}
working-directory: ${{env.WORKING_DIRECTORY_APP}}

release:
name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: build-and-publish-jib

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}}
70 changes: 70 additions & 0 deletions .github/workflows/release.yaml
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 }}
37 changes: 7 additions & 30 deletions word-count/.gitignore
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/
Binary file added word-count/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.