From d4b24dc665840101aadc25cc996ea158cd698150 Mon Sep 17 00:00:00 2001 From: Grzegorz Kocur Date: Wed, 16 Jun 2021 11:44:07 +0200 Subject: [PATCH 1/4] Deploy on GH release event --- .github/workflows/bootzooka-helm-ci.yaml | 6 ++- .github/workflows/bootzooka-scala-ts-ci.yml | 48 ++++++++++++++++++--- build.sbt | 28 +++++------- scripts/docker-entrypoint.sh | 27 ------------ version.sbt | 2 +- 5 files changed, 59 insertions(+), 52 deletions(-) delete mode 100755 scripts/docker-entrypoint.sh diff --git a/.github/workflows/bootzooka-helm-ci.yaml b/.github/workflows/bootzooka-helm-ci.yaml index 0ff317bd9..d3afad250 100644 --- a/.github/workflows/bootzooka-helm-ci.yaml +++ b/.github/workflows/bootzooka-helm-ci.yaml @@ -5,6 +5,8 @@ on: paths: - "helm/**" - ".github/**" + branches: + - master pull_request: paths: - "helm/**" @@ -12,8 +14,6 @@ on: jobs: lint-chart: - # run on external PRs, but not on internal PRs since those will be run by push to branch - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository name: Lint Helm Chart runs-on: ubuntu-18.04 steps: @@ -86,6 +86,8 @@ jobs: run: git diff --exit-code publish-chart: + # run only on push to master + if: github.event_name == 'push' needs: - lint-chart - install-test-chart diff --git a/.github/workflows/bootzooka-scala-ts-ci.yml b/.github/workflows/bootzooka-scala-ts-ci.yml index d49bf7a38..e546ac464 100644 --- a/.github/workflows/bootzooka-scala-ts-ci.yml +++ b/.github/workflows/bootzooka-scala-ts-ci.yml @@ -1,18 +1,21 @@ name: Bootzooka CI on: + pull_request: push: + branches: + - master paths-ignore: - "helm/**" - pull_request: + release: + types: + - released paths-ignore: - "helm/**" jobs: - scala-ts-tests: - # run on external PRs, but not on internal PRs since those will be run by push to branch - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - name: CI + test: + name: Test runs-on: ubuntu-18.04 steps: @@ -39,3 +42,38 @@ jobs: - name: Run tests id: run-tests run: sbt test + + deploy: + if: startsWith(github.ref, 'refs/tags/v') + needs: [ test ] + runs-on: ubuntu-latest + + steps: + - name: Check-out repository + id: repo-checkout + uses: actions/checkout@v2 + + - name: Set up JDK 11 + id: jdk-setup + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Cache SBT + id: cache-sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier + key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Publish docker image + run: sbt docker:publish diff --git a/build.sbt b/build.sbt index c66355f60..935d6d841 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,6 @@ import sbtbuildinfo.BuildInfoKey.action import sbtbuildinfo.BuildInfoKeys.{buildInfoKeys, buildInfoOptions, buildInfoPackage} import sbtbuildinfo.{BuildInfoKey, BuildInfoOption} -import com.typesafe.sbt.packager.docker.ExecCmd import sbt._ import Keys._ @@ -156,29 +155,24 @@ lazy val fatJarSettings = Seq( } ) +git.uncommittedSignifier := Some("dirty") +git.formattedShaVersion in ThisBuild := { + val base = git.baseVersion.?.value + val suffix = + git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, git.uncommittedSignifier.value) + git.gitHeadCommit.value.map { sha => + git.defaultFormatShaVersion(base, sha.take(7), suffix) + } +} + lazy val dockerSettings = Seq( dockerExposedPorts := Seq(8080), dockerBaseImage := "adoptopenjdk:11.0.5_10-jdk-hotspot", Docker / packageName := "bootzooka", dockerUsername := Some("softwaremill"), - dockerCommands := { - dockerCommands.value.flatMap { - case ep @ ExecCmd("ENTRYPOINT", _*) => - Seq( - ExecCmd("ENTRYPOINT", "/opt/docker/docker-entrypoint.sh" :: ep.args.toList: _*) - ) - case other => Seq(other) - } - }, - Docker / mappings ++= { - val scriptDir = baseDirectory.value / ".." / "scripts" - val entrypointScript = scriptDir / "docker-entrypoint.sh" - val entrypointScriptTargetPath = "/opt/docker/docker-entrypoint.sh" - Seq(entrypointScript -> entrypointScriptTargetPath) - }, dockerUpdateLatest := true, Docker / publishLocal := (Docker / publishLocal).dependsOn(copyWebapp).value, - Docker / version := git.gitHeadCommit.value.map(head => now() + "-" + head.take(8)).getOrElse("latest") + Docker / version := git.gitDescribedVersion.value.getOrElse(git.formattedShaVersion.value.getOrElse("latest")), ) def haltOnCmdResultError(result: Int) { diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh deleted file mode 100755 index 5db81e7fd..000000000 --- a/scripts/docker-entrypoint.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -set -x - -CGROUP_MEMORY_LIMIT_FILE="/sys/fs/cgroup/memory/memory.limit_in_bytes" -if [ -f $CGROUP_MEMORY_LIMIT_FILE ]; then - MAXRAM=$(cat ${CGROUP_MEMORY_LIMIT_FILE}) -else - echo "This script is designed to run inside docker only, exiting..." - exit 1 -fi - -TOTAL_MEMORY=$(($(cat /proc/meminfo |head -n 1 |awk '{print $2}')*1024)) - -if [ "${MAXRAM}" -lt "${TOTAL_MEMORY}" ]; then - XMXPERCENT="${XMXPERCENT:-80}" - XMX=$(($MAXRAM-$MAXRAM/100*(100-$XMXPERCENT))) - XMX_CONFIG="-J-Xmx${XMX} -J-Xms${XMX}" -fi - -LOG_LEVEL="${LOG_LEVEL:-INFO}" - -[ "${LOG_HOST}" -a "${LOG_PORT}" ] && LOGGING_CONFIG="-DLOG_HOST=${LOG_HOST} -DLOG_PORT=${LOG_PORT} -DAPP_ENV=${APP_ENV} -DAPP_NAME=${APP_NAME} -DSERVICE_INSTANCE_ID=${SERVICE_INSTANCE_ID} -DHOST_ID=${HOST_ID} -DLOG_LEVEL=${LOG_LEVEL}" - -echo "Starting the JVM process" -command="$@" -exec $command ${LOGGING_CONFIG} ${XMX_CONFIG} diff --git a/version.sbt b/version.sbt index de734f78f..a3a28d6cf 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.0.1-SNAPSHOT" +ThisBuild / version := "0.0.1-SNAPSHOT" From e692a0079df36450f2d2e7b93741d91502d5850a Mon Sep 17 00:00:00 2001 From: Grzegorz Kocur Date: Tue, 22 Jun 2021 11:53:42 +0200 Subject: [PATCH 2/4] Move docker image tag computation to docker settings --- build.sbt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/build.sbt b/build.sbt index 935d6d841..464e998d9 100644 --- a/build.sbt +++ b/build.sbt @@ -155,15 +155,6 @@ lazy val fatJarSettings = Seq( } ) -git.uncommittedSignifier := Some("dirty") -git.formattedShaVersion in ThisBuild := { - val base = git.baseVersion.?.value - val suffix = - git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, git.uncommittedSignifier.value) - git.gitHeadCommit.value.map { sha => - git.defaultFormatShaVersion(base, sha.take(7), suffix) - } -} lazy val dockerSettings = Seq( dockerExposedPorts := Seq(8080), @@ -173,6 +164,14 @@ lazy val dockerSettings = Seq( dockerUpdateLatest := true, Docker / publishLocal := (Docker / publishLocal).dependsOn(copyWebapp).value, Docker / version := git.gitDescribedVersion.value.getOrElse(git.formattedShaVersion.value.getOrElse("latest")), + git.uncommittedSignifier := Some("dirty"), + ThisBuild / git.formattedShaVersion := { + val base = git.baseVersion.?.value + val suffix = git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, git.uncommittedSignifier.value) + git.gitHeadCommit.value.map { sha => + git.defaultFormatShaVersion(base, sha.take(7), suffix) + } + } ) def haltOnCmdResultError(result: Int) { From 623c81d0b68aef7a9ab128ac1eec567837ea45de Mon Sep 17 00:00:00 2001 From: Grzegorz Kocur Date: Tue, 22 Jun 2021 14:11:34 +0200 Subject: [PATCH 3/4] Add release drafter action --- .github/release-drafter.yaml | 4 ++++ .github/workflows/bootzooka-scala-ts-ci.yml | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .github/release-drafter.yaml diff --git a/.github/release-drafter.yaml b/.github/release-drafter.yaml new file mode 100644 index 000000000..27bcee3fb --- /dev/null +++ b/.github/release-drafter.yaml @@ -0,0 +1,4 @@ +template: | + ## What’s Changed + + $CHANGES diff --git a/.github/workflows/bootzooka-scala-ts-ci.yml b/.github/workflows/bootzooka-scala-ts-ci.yml index e546ac464..41bdce35c 100644 --- a/.github/workflows/bootzooka-scala-ts-ci.yml +++ b/.github/workflows/bootzooka-scala-ts-ci.yml @@ -3,6 +3,7 @@ name: Bootzooka CI on: pull_request: push: + tags: [v*] branches: - master paths-ignore: @@ -74,6 +75,19 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - + - name: Extract version + run: | + version=${GITHUB_REF/refs\/tags\/v/} + echo "VERSION=$version" >> $GITHUB_ENV + - name: Publish release notes + uses: release-drafter/release-drafter@v5 + with: + config-name: release-drafter.yml + publish: true + name: "v${{ env.VERSION }}" + tag: "v${{ env.VERSION }}" + version: "v${{ env.VERSION }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Publish docker image run: sbt docker:publish From 2f268a0becd9e74c1a8fbfad4d27de7832f2708e Mon Sep 17 00:00:00 2001 From: Grzegorz Kocur Date: Tue, 22 Jun 2021 14:16:25 +0200 Subject: [PATCH 4/4] Don't deploy if tag is added to commit in PR --- .github/workflows/bootzooka-scala-ts-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bootzooka-scala-ts-ci.yml b/.github/workflows/bootzooka-scala-ts-ci.yml index 41bdce35c..9e59f28f2 100644 --- a/.github/workflows/bootzooka-scala-ts-ci.yml +++ b/.github/workflows/bootzooka-scala-ts-ci.yml @@ -45,7 +45,7 @@ jobs: run: sbt test deploy: - if: startsWith(github.ref, 'refs/tags/v') + if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/v') needs: [ test ] runs-on: ubuntu-latest