Skip to content

Commit

Permalink
flex templates - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuthan committed Oct 23, 2023
1 parent 8a36bf2 commit cfc1118
Show file tree
Hide file tree
Showing 24 changed files with 364 additions and 139 deletions.
35 changes: 35 additions & 0 deletions .github/actions/build-flex-template/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build flex template
description: Build flex template using gcloud

inputs:
template_file:
description: Google Cloud Storage location of the flex template file
required: true
image_gcr:
description: Google Artifact Registry location to store the flex template image to be built
required: true
artifact_name:
description: Artifact name
required: true
main_class:
description: Main class
required: true

runs:
using: composite
steps:
- uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact_name }}

- uses: "google-github-actions/setup-gcloud@v1"

- name: Flex template build
shell: bash
run: |
gcloud dataflow flex-template build ${{ inputs.template_file }} \
--image-gcr-path "${{ image_gcr }}" \
--sdk-language "JAVA" \
--flex-template-base-image JAVA17 \
--jar "${{ inputs.artifact_name }}" \
--env FLEX_TEMPLATE_JAVA_MAIN_CLASS="${{ inputs.main_class }}" \
11 changes: 5 additions & 6 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: 'Setup'
description: 'Setup build'
name: Setup
description: Setup java

runs:
using: "composite"
using: composite
steps:
- name: Setup JDK
uses: actions/setup-java@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: sbt
cache: sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Scala Steward auto-merge
name: Auto-merge

on: pull_request

Expand All @@ -10,10 +10,10 @@ jobs:
automerge:
runs-on: ubuntu-latest

if: ${{ github.actor == 'mkuthan-scala-steward[bot]' }}
if: ${{ github.actor == 'mkuthan-scala-steward[bot]' || github.actor == 'dependabot[bot]' }}

steps:
- name: Enable auto-merge for Scala Steward PRs
- name: Enable auto-merge
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
Expand Down
22 changes: 4 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI

on: [push, workflow_dispatch]
on:
workflow_dispatch: ~
pull_request: ~

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -32,25 +34,9 @@ jobs:
- uses: ./.github/actions/setup
- run: sbt "scalafixAll --check"

tf-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dflook/terraform-validate@v1
with:
path: toll-infrastructure

tf-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dflook/terraform-fmt-check@v1
with:
path: toll-infrastructure

test:
runs-on: ubuntu-latest
needs: [scalafmt, scapegoat, scalafix, tf-validate, tf-fmt]
needs: [scalafmt, scapegoat, scalafix]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/deploy.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/flex-templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build flex templates

on:
workflow_dispatch: ~
push:
branches:
- main

jobs:
assembly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: sbt tollApplication/assembly
- uses: actions/upload-artifact@v3
with:
name: toll-application
path: toll-application/target/scala-2.13/toll-application.jar"

build-batch:
runs-on: ubuntu-latest
needs: [assembly]
steps:
- uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- uses: ./.github/actions/build-flex-template
with:
template_file: gs://playground-272019-toll-application/templates/toll-application-batch.json
image_gcr: europe-west1-docker.pkg.dev/playground-272019/toll-application/toll-application-batch:latest
artifact_name: toll-application
main_class: org.mkuthan.streamprocessing.toll.application.batch.TollBatchJob

build-streaming:
runs-on: ubuntu-latest
needs: [assembly]
steps:
- uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- uses: ./.github/actions/build-flex-template
with:
template_file: gs://playground-272019-toll-application/templates/toll-application-streaming.json
image_gcr: europe-west1-docker.pkg.dev/playground-272019/toll-application/toll-application-streaming:latest
artifact_name: toll-application
main_class: org.mkuthan.streamprocessing.toll.application.streaming.TollStreamingJob
2 changes: 1 addition & 1 deletion .github/workflows/scala-steward.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Scala Steward

on:
workflow_dispatch: ~
schedule:
- cron: "0 0 * * 0" # 00:00 every Sunday
workflow_dispatch:

jobs:
scala-steward:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/tf-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Terraform apply

on:
workflow_dispatch: ~
push:
branches:
- main

permissions:
contents: read
pull-requests: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
apply:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- uses: dflook/terraform-apply@v1
with:
path: toll-infrastructure
28 changes: 22 additions & 6 deletions .github/workflows/tf-plan.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
name: Terraform plan

on: [pull_request]
on:
workflow_dispatch: ~
pull_request: ~

permissions:
contents: read
pull-requests: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
plan:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dflook/terraform-validate@v1
with:
path: toll-infrastructure

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dflook/terraform-fmt-check@v1
with:
path: toll-infrastructure

plan:
runs-on: ubuntu-latest
needs: [validate, fmt]
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"

- uses: dflook/terraform-plan@v1
with:
path: toll-infrastructure
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ Shared modules:

Use cases:

* `toll-application`, `toll-domain` - sample application for toll data processing,
* `toll-application`, `toll-domain`, `toll-infrastructure` - sample application for toll data processing,
see [blog post](https://mkuthan.github.io/blog/2023/09/27/unified-batch-streaming/)
* `toll-infrastructure` - GCP infrastructure as a code for sample application
* `word-count` - fixed window example,
see [blog post](https://mkuthan.github.io/blog/2022/01/28/stream-processing-part1/)
* `session-window` - session window example,
Expand Down
11 changes: 0 additions & 11 deletions toll-application/deploy-batch.sh

This file was deleted.

11 changes: 0 additions & 11 deletions toll-application/deploy-streaming.sh

This file was deleted.

12 changes: 7 additions & 5 deletions toll-application/run-batch.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash

DATE=`date +%Y-%m-%d`

PROJECT=playground-272019
REGION=europe-west1
DATE=`date +%Y-%m-%d`

gcloud dataflow flex-template run "toll-application-`date +%Y%m%d-%H%M%S`" \
--template-file-gcs-location "gs://$PROJECT-toll-application/templates/toll-application-batch.json" \
--region "$REGION" \
--staging-location="gs://$PROJECT-toll-application/staging/" \
--additional-experiments="use_runner_v2" \
--max-workers=1 \
--staging-location "gs://$PROJECT-toll-application/staging/" \
--additional-experiments "use_runner_v2" \
--max-workers 1 \
--worker-machine-type "t2d-standard-1" \
--parameters effectiveDate="$DATE" \
--parameters entryTable="$PROJECT.toll_application.toll-booth-entry" \
--parameters exitTable="$PROJECT.toll_application.toll-booth-exit" \
Expand All @@ -18,5 +20,5 @@ gcloud dataflow flex-template run "toll-application-`date +%Y%m%d-%H%M%S`" \
--parameters entryStatsDailyTable="$PROJECT.toll_application.toll-booth-entry-stats-daily" \
--parameters totalVehicleTimesOneHourGapTable="$PROJECT.toll_application.total-vehicle-times-one-hour-gap" \
--parameters totalVehicleTimesOneHourGapDiagnosticTable="$PROJECT.toll_application.total-vehicle-times-one-hour-gap-diagnostic" \
--parameters vehiclesWithExpiredRegistrationDailyTable="$PROJECT.toll_application.vehicles-with-expired-registration-diagnostic-daily" \
--parameters vehiclesWithExpiredRegistrationDailyTable="$PROJECT.toll_application.vehicles-with-expired-registration-daily" \
--parameters vehiclesWithExpiredRegistrationDailyDiagnosticTable="$PROJECT.toll_application.vehicles-with-expired-registration-daily-diagnostic" \
7 changes: 4 additions & 3 deletions toll-application/run-streaming.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ REGION=europe-west1
gcloud dataflow flex-template run "toll-application-`date +%Y%m%d-%H%M%S`" \
--template-file-gcs-location "gs://$PROJECT-toll-application/templates/toll-application-streaming.json" \
--region "$REGION" \
--staging-location="gs://$PROJECT-toll-application/staging/" \
--staging-location "gs://$PROJECT-toll-application/staging/" \
--enable-streaming-engine \
--additional-experiments="use_runner_v2" \
--max-workers=1 \
--additional-experiments "use_runner_v2" \
--max-workers 1 \
--worker-machine-type "t2d-standard-1" \
--parameters entrySubscription="projects/$PROJECT/subscriptions/toll-booth-entry" \
--parameters entryDlq="gs://$PROJECT-toll-application/dlq/entry" \
--parameters exitSubscription="projects/$PROJECT/subscriptions/toll-booth-exit" \
Expand Down
Loading

0 comments on commit cfc1118

Please sign in to comment.