Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine based image for sbt-scala #277

Merged
merged 10 commits into from
Mar 28, 2024
Merged

Alpine based image for sbt-scala #277

merged 10 commits into from
Mar 28, 2024

Conversation

Carbrex
Copy link
Contributor

@Carbrex Carbrex commented Mar 27, 2024

Comparison:
docker images
image

The image eclipse-temurin-jammy-21.0.2_13 with base image eclipse-temurin:21.0.2_13-jdk is 977MB
The new image is 792MB
But moving

# Prepare sbt (warm cache)
RUN \
  sbt sbtVersion && \
  mkdir -p project && \
  echo "scalaVersion := \"${SCALA_VERSION}\"" > build.sbt && \
  echo "sbt.version=${SBT_VERSION}" > project/build.properties && \
  echo "// force sbt compiler-bridge download" > project/Dependencies.scala && \
  echo "case object Temp" > Temp.scala && \
  sbt compile && \
  rm -r project && rm build.sbt && rm Temp.scala && rm -r target

this code to build stage reduces the image size to 552MB (That still works good though I am not sure what will be the downside of moving this to build stage).
Currently this pr has it outside of build stage I will move it to build stage to reduce size if you say so. The link to that branch is https://github.com/Carbrex/docker-sbt/blob/warm-stage-in-build/eclipse-temurin/alpine.Dockerfile

I have also not been able to check for the build.yml changes as I dont know how to run them. Your help would be appreciated.
Thanks for your time!
Closes #276

@francisdb
Copy link
Collaborator

The purpose of that step is to make sure sbt preloads the scala version. Should improve sbt project load time. On the other hand if you have a proper ci build cache in place it does not matter so much as it only happens on the first build.
To create a minimal image we could also remove the scala install unless ppl want to use the scalac command.

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

So, what are the changes you want?
Also, I have tried fixing build.yml, though I am still not sure if it will work.

@francisdb
Copy link
Collaborator

Looks like the build is still failing

So, what are the changes you want? Also, I have tried fixing build.yml, though I am still not sure if it will work.

What will you be using the image for? Do you want it to be as small as possible and will you only be using sbt?

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

In my specific use case, I am running https://github.com/lichess-org/lila-docker which has atleast 4 images that rely on your sbt-scala images ( namely lila, lila-ws, lila-search and lila-engine). This is the dockerfile for lila-ws. We would still need scala. Since we use four different images, this reduction in size becomes significant.

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

The tests have passed I am now removing carbrex from repository name.

@francisdb
Copy link
Collaborator

francisdb commented Mar 28, 2024

In my specific use case, I am running https://github.com/lichess-org/lila-docker which has atleast 4 images that rely on your sbt-scala images ( namely lila, lila-ws, lila-search and lila-engine). This is the dockerfile for lila-ws. We would still need scala. Since we use four different images, this reduction in size becomes significant.

Since that docker file only interacts with sbt you don't need the separate scala install.

Looking at lila-ws, this seems to be a runtime container so it would even be better to not use sbt at all and make sure your app can run on a plain jdk docker image. That will avoid sbt loading and code compilation on startup.

Have you considered https://www.scala-sbt.org/sbt-native-packager/formats/docker.html ?

Ok never mind, this seems to be a dev container.

@francisdb
Copy link
Collaborator

So you care more about size than startup time?

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

So you care more about size than startup time?

No, I guess the startup time is essential too. I just didn't know by then what the warming stage do.
You don't have to merge it if you dont like the idea of this alpine image.

@francisdb
Copy link
Collaborator

I you consider this done I'm OK to merge.

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

Its done on my end.👍

@francisdb
Copy link
Collaborator

One more thing, can you remove the JDK 11 build? I plan to remove all those builds as jdk 11 primary support period has ended.

By the way, Lichess is amazing.

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

Ok, I will remove it we don't use it anyway. (Just the alpine one or the other ones too?)

By the way, Lichess is amazing.

I agree, but I am not a maintainer just a contributor.

@francisdb
Copy link
Collaborator

francisdb commented Mar 28, 2024

Ok, I will remove it we don't use it anyway. (Just the alpine one or the other ones too?)

Just the alpine one

@Carbrex
Copy link
Contributor Author

Carbrex commented Mar 28, 2024

Done👍

@francisdb francisdb merged commit f79e23d into sbt:master Mar 28, 2024
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image based on alpine
2 participants