From b34256bf0c6e824290cd6c821f634447de8d2e4b Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sat, 11 May 2024 19:45:04 +0700 Subject: [PATCH 1/3] Support building local docker image --- build.sbt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index ea401731..0fadaf86 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,9 @@ inThisBuild( scalaVersion := "3.4.2", versionScheme := Some("early-semver"), version := "3.2", - semanticdbEnabled := true // for scalafix + semanticdbEnabled := true, // for scalafix + dockerBaseImage := "openjdk:21", + dockerUpdateLatest := true ) ) @@ -18,7 +20,7 @@ val chessVersion = "16.0.3" lazy val `lila-ws` = project .in(file(".")) - .enablePlugins(JavaAppPackaging) + .enablePlugins(JavaAppPackaging, DockerPlugin) .settings( name := "lila-ws", organization := "org.lichess", @@ -63,7 +65,13 @@ lazy val `lila-ws` = project "-Xtarget:21", "-Wunused:all" ), - javaOptions ++= Seq("-Xms32m", "-Xmx256m") + javaOptions ++= Seq("-Xms32m", "-Xmx256m"), + Docker / packageName := "lichess-org/lila-ws", + Docker / maintainer := "lichess.org", + Docker / dockerRepository := Some("ghcr.io"), + Universal / javaOptions := Seq( + "-J-Dconfig.override_with_env_vars=true" + ) ) addCommandAlias("prepare", "scalafixAll; scalafmtAll") From 0c9b61b478b40de521e5735d9aaab1d47ec80a2c Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Tue, 21 May 2024 09:58:48 +0700 Subject: [PATCH 2/3] Add docker workflows --- .github/workflows/docker.yml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..5934e62b --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +name: Create and publish a Docker image +on: + push: + branches: ['**'] +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup JVM + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + cache: sbt + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + run: sbt app/Docker/publish From b71a334cd9817447c1d2445700d16be1531ebf83 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Tue, 21 May 2024 10:05:18 +0700 Subject: [PATCH 3/3] Try publish docker on pr --- .github/workflows/docker.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5934e62b..8793ecd9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,7 +1,10 @@ name: Create and publish a Docker image on: push: - branches: ['**'] + branches: [ "master" ] + pull_request: + branches: [ "master" ] + env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -40,4 +43,4 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Build and push Docker image - run: sbt app/Docker/publish + run: sbt Docker/publish