mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-18 13:24:25 +01:00
Sbt docker multi platform (#3649)
* Add docker x building for multiple platform support * Working now * Move config into CommonSettings, make code a bit more readable Co-authored-by: Ivan <erickson.ivan@gmail.com>
This commit is contained in:
parent
d53f164478
commit
8e39b2bbb8
2
.github/workflows/docker-publish.yml
vendored
2
.github/workflows/docker-publish.yml
vendored
@ -2,7 +2,7 @@
|
||||
name: CI to Docker Hub
|
||||
on:
|
||||
push:
|
||||
branches: [master, main, adaptor-dlc]
|
||||
branches: [master, main]
|
||||
tags: ["*"]
|
||||
jobs:
|
||||
build:
|
||||
|
@ -1,4 +1,5 @@
|
||||
import com.typesafe.sbt.SbtGit.GitKeys._
|
||||
import sbt.Keys.{publish, publishLocal}
|
||||
|
||||
import scala.util.Properties
|
||||
|
||||
@ -354,6 +355,7 @@ lazy val oracleServer = project
|
||||
.in(file("app/oracle-server"))
|
||||
.settings(CommonSettings.appSettings: _*)
|
||||
.settings(CommonSettings.dockerSettings: _*)
|
||||
.settings(CommonSettings.dockerBuildxSettings: _*)
|
||||
.dependsOn(
|
||||
dlcOracle,
|
||||
serverRoutes
|
||||
@ -380,6 +382,7 @@ lazy val appServer = project
|
||||
.in(file("app/server"))
|
||||
.settings(CommonSettings.appSettings: _*)
|
||||
.settings(CommonSettings.dockerSettings: _*)
|
||||
.settings(CommonSettings.dockerBuildxSettings: _*)
|
||||
.dependsOn(
|
||||
serverRoutes,
|
||||
appCommons,
|
||||
|
@ -17,6 +17,8 @@ import sbt._
|
||||
import sbt.Keys._
|
||||
import sbtprotoc.ProtocPlugin.autoImport.PB
|
||||
import sbtassembly.AssemblyKeys._
|
||||
|
||||
import scala.sys.process.Process
|
||||
import scala.util.Properties
|
||||
|
||||
object CommonSettings {
|
||||
@ -187,6 +189,50 @@ object CommonSettings {
|
||||
)
|
||||
}
|
||||
|
||||
// See https://softwaremill.com/how-to-build-multi-platform-docker-image-with-sbt-and-docker-buildx/
|
||||
lazy val ensureDockerBuildx =
|
||||
taskKey[Unit]("Ensure that docker buildx configuration exists")
|
||||
|
||||
lazy val dockerBuildWithBuildx =
|
||||
taskKey[Unit]("Build docker images using buildx")
|
||||
|
||||
/** These settings are needed to produce docker images across different chip architectures
|
||||
* such as amd64 and arm64
|
||||
* @see https://softwaremill.com/how-to-build-multi-platform-docker-image-with-sbt-and-docker-buildx/
|
||||
*/
|
||||
lazy val dockerBuildxSettings = {
|
||||
Seq(
|
||||
ensureDockerBuildx := {
|
||||
if (Process("docker buildx inspect multi-arch-builder").! == 1) {
|
||||
Process("docker buildx create --use --name multi-arch-builder",
|
||||
baseDirectory.value).!
|
||||
}
|
||||
},
|
||||
dockerBuildWithBuildx := {
|
||||
streams.value.log("Building and pushing image with Buildx")
|
||||
dockerAliases.value.foreach { alias =>
|
||||
//issue the command below in to the terminal in the same directory that
|
||||
//our sbt plugin generates the docker file.
|
||||
//if you want to reproduce the docker file, run docker:stage
|
||||
//in your sbt terminal and you should find it in target/docker/stage/
|
||||
val cmd =
|
||||
"docker buildx build --platform=linux/amd64,linux/arm64 --push -t " +
|
||||
alias + " ."
|
||||
val dockerFileDir =
|
||||
baseDirectory.value / "target" / "docker" / "stage"
|
||||
Process(cmd, dockerFileDir).!
|
||||
}
|
||||
},
|
||||
Docker / publish := Def
|
||||
.sequential(
|
||||
Docker / publishLocal,
|
||||
ensureDockerBuildx,
|
||||
dockerBuildWithBuildx
|
||||
)
|
||||
.value
|
||||
)
|
||||
}
|
||||
|
||||
lazy val binariesPath =
|
||||
Paths.get(Properties.userHome, ".bitcoin-s", "binaries")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user