1
1
import java .nio .file .Paths
2
2
3
- import sbt .*
4
- import sbt .Keys . *
3
+ import sbt .Keys . _
4
+ import sbt ._
5
5
6
6
import com .typesafe .sbt .packager .docker .{Cmd , LayeredMapping }
7
7
@@ -19,6 +19,7 @@ lazy val commonSettings = Seq(
19
19
// Use cached resolution of dependencies
20
20
// http://www.scala-sbt.org/0.13/docs/Cached-Resolution.html
21
21
updateOptions := updateOptions.in(Global ).value.withCachedResolution(true ),
22
+ resolvers ++= Seq (Resolver .mavenLocal),
22
23
resolvers += " RAW Labs GitHub Packages" at " https://maven.pkg.github.com/raw-labs/_" )
23
24
24
25
lazy val buildSettings = Seq (
@@ -42,7 +43,9 @@ lazy val compileSettings = Seq(
42
43
Compile / packageBin / packageOptions += Package .ManifestAttributes (
43
44
" Automatic-Module-Name" -> name.value.replace('-' , '.' )),
44
45
// Ensure Java annotations get compiled first, so that they are accessible from Scala.
45
- compileOrder := CompileOrder .JavaThenScala )
46
+ compileOrder := CompileOrder .JavaThenScala ,
47
+ Compile / mainClass := Some (" com.rawlabs.das.server.DASServer" )
48
+ )
46
49
47
50
lazy val testSettings = Seq (
48
51
// Ensuring tests are run in a forked JVM for isolation.
@@ -51,7 +54,7 @@ lazy val testSettings = Seq(
51
54
// Test / parallelExecution := false,
52
55
// Pass system properties starting with "raw." to the forked JVMs.
53
56
Test / javaOptions ++= {
54
- import scala .collection .JavaConverters .*
57
+ import scala .collection .JavaConverters ._
55
58
val props = System .getProperties
56
59
props
57
60
.stringPropertyNames()
@@ -79,6 +82,7 @@ lazy val strictBuildSettings =
79
82
commonSettings ++ compileSettings ++ buildSettings ++ testSettings ++ Seq (scalacOptions ++= Seq (" -Xfatal-warnings" ))
80
83
81
84
lazy val root = (project in file(" ." ))
85
+ .enablePlugins(JavaAppPackaging , DockerPlugin )
82
86
.settings(
83
87
name := " das-salesforce" ,
84
88
strictBuildSettings,
@@ -94,56 +98,36 @@ lazy val root = (project in file("."))
94
98
" com.fasterxml.jackson.datatype" % " jackson-datatype-jsr310" % " 2.18.2" ,
95
99
" com.fasterxml.jackson.datatype" % " jackson-datatype-jdk8" % " 2.18.2" ,
96
100
" com.fasterxml.jackson.datatype" % " jackson-datatype-joda" % " 2.18.2" ,
97
- " com.fasterxml.jackson.module" %% " jackson-module-scala" % " 2.18.2" ))
98
-
99
- val amzn_jdk_version = " 21.0.4.7-1 "
100
- val amzn_corretto_bin = s " java-21-amazon-corretto-jdk_ ${amzn_jdk_version} _amd64.deb "
101
- val amzn_corretto_bin_dl_url = s " https://corretto.aws/downloads/resources/ ${amzn_jdk_version.replace( '-' , '.' )} "
101
+ " com.fasterxml.jackson.module" %% " jackson-module-scala" % " 2.18.2"
102
+ )
103
+ ,
104
+ dockerSettings
105
+ )
102
106
103
- lazy val dockerSettings = strictBuildSettings ++ Seq (
104
- name := " das-salesforce-server" ,
105
- dockerBaseImage := s " --platform=amd64 debian:bookworm-slim " ,
107
+ lazy val dockerSettings = Seq (
108
+ Docker / packageName := " das-salesforce-server" ,
109
+ dockerBaseImage := " eclipse-temurin:21-jre " ,
106
110
dockerLabels ++= Map (
107
111
" vendor" -> " RAW Labs SA" ,
108
112
" product" -> " das-salesforce-server" ,
109
113
" image-type" -> " final" ,
110
114
" org.opencontainers.image.source" -> " https://github.com/raw-labs/das-salesforce" ),
111
115
Docker / daemonUser := " raw" ,
116
+ Docker / daemonUserUid := Some (" 1001" ),
117
+ Docker / daemonGroup := " raw" ,
118
+ Docker / daemonGroupGid := Some (" 1001" ),
112
119
dockerExposedVolumes := Seq (" /var/log/raw" ),
113
120
dockerExposedPorts := Seq (50051 ),
114
121
dockerEnvVars := Map (" PATH" -> s " ${(Docker / defaultLinuxInstallLocation).value}/bin: $$ PATH " ),
115
- // We remove the automatic switch to USER 1001:0.
116
- // We we want to run as root to install the JDK, also later we will switch to a non-root user.
117
- dockerCommands := dockerCommands.value.filterNot {
118
- case Cmd (" USER" , args @ _* ) => args.contains(" 1001:0" )
119
- case cmd => false
120
- },
121
- dockerCommands ++= Seq (
122
- Cmd (
123
- " RUN" ,
124
- s """ set -eux \\
125
- && apt-get update \\
126
- && apt-get install -y --no-install-recommends \\
127
- curl wget ca-certificates gnupg software-properties-common fontconfig java-common \\
128
- && wget $amzn_corretto_bin_dl_url/ $amzn_corretto_bin \\
129
- && dpkg --install $amzn_corretto_bin \\
130
- && rm -f $amzn_corretto_bin \\
131
- && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \\
132
- wget gnupg software-properties-common """ ),
133
- Cmd (" USER" , " raw" )),
134
122
dockerEnvVars += " LANG" -> " C.UTF-8" ,
135
- dockerEnvVars += " JAVA_HOME" -> " /usr/lib/jvm/java-21-amazon-corretto" ,
136
- Compile / doc / sources := Seq .empty, // Do not generate scaladocs
137
- // Skip docs to speed up build
138
- Compile / packageDoc / mappings := Seq (),
139
123
updateOptions := updateOptions.value.withLatestSnapshots(true ),
140
124
Linux / linuxPackageMappings += packageTemplateMapping(s " /var/lib/ ${packageName.value}" )(),
141
125
bashScriptDefines := {
142
126
val ClasspathPattern = " declare -r app_classpath=\" (.*)\"\n " .r
143
127
bashScriptDefines.value.map {
144
128
case ClasspathPattern (classpath) => s """
145
- |declare -r app_classpath=" $$ {app_home}/../conf: $classpath"
146
- | """ .stripMargin
129
+ |declare -r app_classpath=" $$ {app_home}/../conf: $classpath"
130
+ | """ .stripMargin
147
131
case _ @ entry => entry
148
132
}
149
133
},
@@ -163,8 +147,6 @@ lazy val dockerSettings = strictBuildSettings ++ Seq(
163
147
}
164
148
case lm @ _ => lm
165
149
},
166
- Compile / mainClass := Some (" com.rawlabs.das.server.DASServer" ),
167
- Docker / dockerAutoremoveMultiStageIntermediateImages := false ,
168
150
dockerAlias := dockerAlias.value.withTag(Option (version.value.replace(" +" , " -" ))),
169
151
dockerAliases := {
170
152
val devRegistry = sys.env.getOrElse(" DEV_REGISTRY" , " ghcr.io/raw-labs/das-salesforce" )
@@ -177,10 +159,11 @@ lazy val dockerSettings = strictBuildSettings ++ Seq(
177
159
}
178
160
})
179
161
180
- lazy val docker = (project in file(" docker" ))
181
- .dependsOn(root % " compile->compile;test->test" )
182
- .enablePlugins(JavaAppPackaging , DockerPlugin )
183
- .settings(
184
- strictBuildSettings,
185
- dockerSettings,
186
- libraryDependencies += " com.raw-labs" %% " das-server-scala" % " 0.4.1" % " compile->compile;test->test" )
162
+ lazy val printDockerImageName = taskKey[Unit ](" Prints the full Docker image name that will be produced" )
163
+
164
+ printDockerImageName := {
165
+ // Get the main Docker alias (the first one in the sequence)
166
+ val alias = (Docker / dockerAliases).value.head
167
+ // The toString method already returns the full image name with registry and tag
168
+ println(s " DOCKER_IMAGE= ${alias}" )
169
+ }
0 commit comments