Skip to content

Commit

Permalink
Publish docker images for microservices
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Jan 30, 2024
1 parent a1c8167 commit 7679716
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 11 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ '[email protected]' ]
java: [ 17 ]
steps:
- uses: actions/[email protected]
with:
Expand All @@ -24,13 +24,13 @@ jobs:
# uses: coursier/cache-action@v6
- name: sbt ci ${{ github.ref }}
run: sbt -mem 2048 ci
# - name: Log in to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.RENKU_DOCKER_USERNAME }}
# password: ${{ secrets.RENKU_DOCKER_PASSWORD }}
# - name: sbt docker:publishLocal
# run: sbt -mem 2048 cli/Docker/publishLocal
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.RENKU_DOCKER_USERNAME }}
password: ${{ secrets.RENKU_DOCKER_PASSWORD }}
- name: sbt docker:publishLocal
run: sbt -mem 2048 search-provision/Docker/publishLocal search-api/Docker/publishLocal
ci:
runs-on: ubuntu-latest
needs: [ci-matrix]
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Release
on:
push:
branches: [ main ]
release:
types: [ published ]

jobs:
release:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
java: [ 17 ]
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- uses: olafurpg/setup-scala@v14
with:
java-version: ${{ matrix.java }}

- name: Set current version
id: version
shell: bash
run: |
sbt 'renku-search/writeVersion'
RS_VERSION=$(cat target/version.txt)
echo "RS_VERSION=${RS_VERSION}" >> $GITHUB_ENV
if [ -z "${RS_VERSION}" ]; then
echo "Version not set!"
exit 1
fi
- name: Create zip packages
run: sbt -mem 2048 search-provision/Universal/packageBin search-api/Universal/packageBin

- name: Publish Release (${{ env.RS_VERSION }})
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
files: |
modules/search-provision/target/universal/search-provision-${{ env.RS_VERSION }}.zip
modules/search-api/target/universal/search-api-${{ env.RS_VERSION }}.zip
- name: Publish Pre-Release
uses: ncipollo/release-action@v1
if: ${{ github.ref }} == 'refs/heads/main'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: true
allowUpdates: true
tag: "nightly"
commit: "main"
body: "Floating tag associating the latest build from the main branch"
name: "renku search nightly"
replacesArtifacts: true
removeArtifacts: true
artifacts: |
modules/search-provision/target/universal/search-provision-${{ env.RS_VERSION }}.zip,
modules/search-api/target/universal/search-api-${{ env.RS_VERSION }}.zip
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.RENKU_DOCKER_USERNAME }}
password: ${{ secrets.RENKU_DOCKER_PASSWORD }}
- name: sbt Docker/publish
run: sbt -mem 2048 search-provision/Docker/publish search-api/Docker/publish
13 changes: 10 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ addCommandAlias(
)
addCommandAlias("fix", "; scalafmtSbt; scalafmtAll") // ; Compile/scalafix; Test/scalafix

val writeVersion = taskKey[Unit]("Write version into a file for CI to pick up")

lazy val root = project
.in(file("."))
.withId("renku-search")
Expand All @@ -42,7 +44,12 @@ lazy val root = project
publish / skip := true,
publishTo := Some(
Resolver.file("Unused transient repository", file("target/unusedrepo"))
)
),
writeVersion := {
val out = (LocalRootProject / target).value / "version.txt"
val versionStr = version.value
IO.write(out, versionStr)
}
)
.aggregate(
commons,
Expand Down Expand Up @@ -222,7 +229,7 @@ lazy val searchProvision = project
redisClient % "compile->compile;test->test",
searchSolrClient % "compile->compile;test->test"
)
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(AutomateHeaderPlugin, DockerImagePlugin)

lazy val searchApi = project
.in(file("modules/search-api"))
Expand All @@ -240,7 +247,7 @@ lazy val searchApi = project
http4sAvro % "compile->compile;test->test",
searchSolrClient % "compile->compile;test->test"
)
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(AutomateHeaderPlugin, DockerImagePlugin)

lazy val commonSettings = Seq(
organization := "io.renku",
Expand Down
42 changes: 42 additions & 0 deletions project/DockerImagePlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import com.typesafe.sbt.packager.docker._
import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging
import sbt._
import sbt.Keys._
import com.github.sbt.git.SbtGit.git
import sbtdynver._
import sbtdynver.DynVerPlugin.autoImport._

/** Sets default docker image settings for sbt-native-packager's `DockerPlugin`. */
object DockerImagePlugin extends AutoPlugin {

// Load DockerPlugin and JavaServerAppPackaging whenever this plugin is enabled
override def requires = DockerPlugin && JavaServerAppPackaging && DynVerPlugin
override def trigger = allRequirements

import DockerPlugin.autoImport._

val dockerSettings = Seq(
dockerUpdateLatest := true,
// dockerEntrypoint := Seq(s"bin/${executableScriptName.value}", "-Duser.timezone=UTC", "$JAVA_OPTS"),
dockerBaseImage := s"eclipse-temurin:21-jre",
// derive a package name
Docker / packageName := (Compile / name).value,
dockerRepository := Some("docker.io"),
dockerUsername := Some("renku"),

// temporarily use git hash as image tag
Docker / version := git.gitHeadCommit.value
.map(_.take(12))
.getOrElse((Compile / version).value)
)

private def imageTag(out: Option[GitDescribeOutput], headCommit: Option[String]) =
out match {
case Some(d) if d.isCleanAfterTag => Some(d.ref.dropPrefix)
case _ => headCommit.map(_.take(12))
}

override def projectSettings =
dockerSettings
}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.3.0")
addSbtPlugin("com.julianpeeters" % "sbt-avrohugger" % "2.8.2")
Expand Down

0 comments on commit 7679716

Please sign in to comment.