sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.59k stars 439 forks source link

Need help to run custom entrypoint script #1493

Open telemat opened 2 years ago

telemat commented 2 years ago

I have a service with two main classes, one for migrations and the other for the actual service. The two bash/bat files are generated, but I need a custom entrypoint script to call both scripts (to perform migrations first and then to run the service).

My docker settings are as follows:

Docker / organizationName := organization.value
Docker / packageName      := s"${organization.value}/${name.value}"
Docker / maintainer       := "Yours truly"
Docker / version          := version.value
Docker / daemonUserUid    := None
Docker / daemonUser       := "daemon"

// https://hub.docker.com/_/eclipse-temurin/
dockerBaseImage := "eclipse-temurin:11-jre-focal"
dockerExposedPorts ++= Seq(8888)

Docker / dockerPackageMappings += (baseDirectory.value / "docker" / "docker-entrypoint.sh" -> "docker-entrypoint.sh")

This is the generated Dockerfile

FROM eclipse-temurin:11-jre-focal@sha256:e46fac3005d08732931de9671864683f6adf3a3eb0f8a7e8ac27d1bff1955a5c as stage0
LABEL snp-multi-stage="intermediate"
LABEL snp-multi-stage-id="d4ace394-8637-4624-a351-9d3a478c36cd"
WORKDIR /opt/docker
COPY 1/opt /1/opt
COPY 2/opt /2/opt
COPY 4/opt /4/opt
COPY opt /opt
USER root
RUN ["chmod", "-R", "u=rX,g=rX", "/1/opt/docker"]
RUN ["chmod", "-R", "u=rX,g=rX", "/2/opt/docker"]
RUN ["chmod", "-R", "u=rX,g=rX", "/4/opt/docker"]
RUN ["chmod", "-R", "u=rX,g=rX", "/opt/docker"]
RUN ["chmod", "u+x,g+x", "/4/opt/docker/bin/scala-refi-service"]
RUN ["chmod", "u+x,g+x", "/4/opt/docker/bin/migrations"]
RUN ["chmod", "u+x,g+x", "docker-entrypoint.sh"]

FROM eclipse-temurin:11-jre-focal@sha256:e46fac3005d08732931de9671864683f6adf3a3eb0f8a7e8ac27d1bff1955a5c as mainstage
LABEL MAINTAINER="Yours truly"
WORKDIR /opt/docker
COPY --from=stage0 --chown=daemon:root /1/opt/docker /opt/docker
COPY --from=stage0 --chown=daemon:root /2/opt/docker /opt/docker
COPY --from=stage0 --chown=daemon:root /4/opt/docker /opt/docker
COPY --from=stage0 --chown=daemon:root /opt/docker /opt/docker
EXPOSE 8888
USER daemon
ENTRYPOINT ["/opt/docker/bin/scala-refi-service"]
CMD []

The contents of the docker/stage folder are:

1 - folder
2 - folder
4 - folder
docker-entrypoint.sh - file
Dockerfile - file

I'm getting the following error upon doing docker:publishLocal

[error] #10 ERROR: "/opt" not found: not found
[error] ------
[error]  > [stage0  6/13] COPY opt /opt:
[error] ------

Without the setting Docker / dockerPackageMappings += (baseDirectory.value / "docker" / "docker-entrypoint.sh" -> "docker-entrypoint.sh") everything works fine but I can't override the entrypoint.

Is there any example that I can refer to for using a custom script as entrypoint?

muuki88 commented 1 year ago

I would recommend putting the stuff in src/universal, where it's being picked up automatically. Hope this helps.