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 18 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
110 changes: 110 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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 Docker images
run: |
if [[ "$GITHUB_REF" =~ ^refs/tags/.* ]]; then
./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


shell: bash
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.