diff --git a/.github/actions/jib-uploader/action.yaml b/.github/actions/jib-uploader/action.yaml new file mode 100644 index 0000000..fc7eec7 --- /dev/null +++ b/.github/actions/jib-uploader/action.yaml @@ -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 }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..6a419ed --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,126 @@ +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 + if: false + steps: + - name: Build + uses: bakdata/ci-templates/actions/java-gradle-build@v1.7.0 + with: + java-distribution: "microsoft" + java-version: "17" + gradle-version: "wrapper" + working-directory: ${{env.WORKING_DIRECTORY_APP}} + + test: + if: false + name: Test + runs-on: ubuntu-22.04 + needs: build + + steps: + - name: Test + uses: bakdata/ci-templates/actions/java-gradle-test@v1.7.0 + 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/checkout@1.32.0 + + - name: Set up Gradle + uses: bakdata/ci-templates/actions/java-gradle-setup@v1.16.0 + 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: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + tags: | + event=push,type=raw,enable=true,priority=200,prefix=,suffix=,value=pipeline-${{ github.run_id }}-git-{{sha}} + event=pr,type=raw,enable=true,priority=200,prefix=,suffix=,value=pipeline-${{ github.run_id }}-git-{{sha}} + event=tag,type=semver,pattern={{version}} + + + - 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: ${{ steps.meta.outputs.tags }} + 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: ${{ steps.meta.outputs.tags }} + 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/java-gradle-release-github@v1.4.0 + with: + github-username: ${{ secrets.USERNAME }} + github-token: ${{ secrets.GH_TOKEN }} + java-distribution: "microsoft" + java-version: "17" + working-directory: ${{env.WORKING_DIRECTORY_APP}} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..35c430a --- /dev/null +++ b/.github/workflows/release.yaml @@ -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/java-gradle-build@v1.7.0 + 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/java-gradle-test@v1.7.0 + 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/checkout@1.32.0 + 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/java-gradle-release@1.27.0 + 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 }} diff --git a/word-count/.gitignore b/word-count/.gitignore index 6870056..53766de 100644 --- a/word-count/.gitignore +++ b/word-count/.gitignore @@ -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/ diff --git a/word-count/gradle/wrapper/gradle-wrapper.jar b/word-count/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..943f0cb Binary files /dev/null and b/word-count/gradle/wrapper/gradle-wrapper.jar differ