by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Rui Morais
    @rmorais

    Hello all,
    I am using sbt-native-packager to bundle my scala application into a docker image. And I am trying to install a dependency into my base docker image. For that I am appending my command to dockerCommands like

    dockerCommands += Cmd("RUN", "apk --no-cache --update add eudev")

    The problem with this is that this is run as the last step of the docker file, and at this stage, it doesn't have enough permissions as we are already changed the user from root to demiourgos728.
    One possible solution is to change user before and after my command, like this:

    dockerCommands ++= Seq(
            Cmd("USER", "root"),
            Cmd("RUN", "apk --no-cache --update add eudev"),
            Cmd("USER", "1001:0")
          )

    The other option is to inspect dockerCommands and split/filter/insert the command at the right stage.
    The right solution for my problem is probably to add the dependency to the base image before even using sbt-native-packager but I cannot do it at this time.

    These solutions works but it doesn't feel right.
    I couldn't find a way but I was wondering if sbt native packager provides a way of adding a Cmd to a specific stage, ie, add Cmd("RUN", "apk --no-cache --update add eudev") at stage0, for example.

    hagaiy
    @hagaiy
    Hello all, what do i have to in order to be able to use my resoures when run as a container. from some reason everything is ok when i run the code from intelij but when run as a container i get java.nio.file.FileSystemNotFoundException: null
    nigredo-tori
    @nigredo-tori
    @hagaiy, are you doing something like Paths.get(getClass.getResource("foo").toURI)? In SBT (and probably in Idea) resources are represented as files on the disk, so that works - but with packaging resources are entries in JARs, so that breaks.
    I might be remembering it wrong, though.
    Alessandro Vermeulen
    @spockz
    Is there a way to let graalvm-native-image:packageBinoutput the output from native-image immediately instead of buffering it?
    Nepomuk Seiler
    @muuki88
    @hagaiy loading resources in java land is quite tricky. @nigredo-tori is right that there are issues when not using a clasloader to load the resources. You should also make sure that the resources are in the resulting jar of your application
    @spockz I guess this is the default behaviour of the sbt logger. Maybe the bufferring is configurable
    hagaiy
    @hagaiy
    @nigredo-tori @muuki88 thanks guys i it help me to find the solution - i had to upload them as stream
    Alessandro Vermeulen
    @spockz
    @muuki88 in other native package plugins the output isn’t buffered. I’ll look into which code paths are used
    CodingPenguin
    @TheCodingPenguin
    Hello everyone, I am trying to create an RPM package using rpm:packageBin however when I try to run the package I get an error regarding the user. How is it possible to create the user before running the RPM ?
    Robby Kiskanyan
    @robbyki
    Anyone know what the meaning of this is from my docker:publishLocal run which is not removing my <none>:<none> intermediate images? Not removing multi-stage intermediate image(s) because id is missing in Dockerfile (Comment: "# id=...")
    Evgenii
    @ibanezn04

    Hello! I'm trying to run a scala app using sbt-native-packager and i would be really grateful if someone could help me - i can't figure out where is my files which were in resources folder. For example, i'm trying so serve a static file from http4s and it fails to find one:

     case request @ GET -> path if path.startsWith(swaggerUiPath) =>
              def getListOfFiles(dir: String): List[File] = {
                val d = new File(dir)
                if (d.exists && d.isDirectory) {
                  d.listFiles..toList
                } else {
                  List[File]()
                }
              }
              val file = "/" + path.toList.drop(swaggerUiPath.toList.size).mkString("/")
              (if (file == "/index.html") {
                 println(getClass.getClassLoader.getResource("."))  // null
                 println(getClass.getClassLoader.getResource("/swagger-ui/index.html")) //null
                println(getClass.getClassLoader.getResource("./swagger-ui/index.html")) //null
                 println(getClass.getClassLoader.getResource("swagger-ui/index.html")) //null
                 println(getClass.getClassLoader.getResource("/swagger.yaml")) //null
                 println(getListOfFiles(".")) // List(./lib, ./version, ./conf, ./bin)
                 StaticFile
                   .fromString("./swagger-ui/index.html", io, Some(request)) // also null
               } else {
                 StaticFile.fromResource(swaggerUiResources + file, io, Some(request))
               }).getOrElseF(Ok(Json.obj("Not found" -> Json.fromString(s"index.html"))))

    In conf folder there are files that i added in mappings:

     mappings in Universal ++= {
          val resources = (resourceDirectory in Compile).value
          Seq(
            resources / "dev.conf"              -> "conf/dev.conf",
            resources / "prod.conf"             -> "conf/prod.conf",
            resources / "logback.xml"           -> "conf/logback.xml",
            resources / "secret.key"            -> "conf/secret.key",
            resources / "swagger-ui/index.html" -> "conf/swagger-ui/index.html"
          )
        }

    But where all the other resource files? And also why println(getClass.getClassLoader.getResource(".")) returns null? isn't classpath dir?
    Thanks:)

    Nepomuk Seiler
    @muuki88
    Resource handling in java is a mess 😁 first I would look at the resulting jar by unzipping it. Figure out the path in this structure. Classloader returning null means there's no resource. AFAIK directories are no valid resources
    Evgenii
    @ibanezn04
    @muuki88 thanks, i've unzipped jar in lib folder with my project and it turns out -its just manifest and and no resource files, is there a way to add it some how?
    nigredo-tori
    @nigredo-tori
    @ibanezn04, whatever is in src/main/resources of your (sub)project should make it to the resulting JAR, as per standard SBT behavior. Does that not happen?
    Evgenii
    @ibanezn04
    @nigredo-tori well, i it depends on what you mean by resulting JAR, if i just write "sbt package", then yes, i can find resources inside jar, located in targer/scala2...., but if i use universal packaging - i'm getting zip,with 3 folders: bin, lib and conf(this one i defined in mappings myself). If i open jar with my project name in lib folder then -no, there aren't any resource files
    am i looking somewhere wrong?
    Nepomuk Seiler
    @muuki88
    The jar that is generated by sbt package is placed in the lib folder. And in this jar you'll need to take a look 😁
    And as @nigredo-tori mentioned correctly. Everything in compile resources will end up in the jar. No need to define extra mappings.
    Evgenii
    @ibanezn04
    @muuki88 , as i mentioned already:"If i open jar with my project name in lib folder then -no, there aren't any resource files" :c
    Evgenii
    @ibanezn04
    may be i'm doing something wrong, here is my build:
    Evgenii
    @ibanezn04
    lazy val gateway = project
      .in(file("gateway"))
      .enablePlugins(JavaAppPackaging)
      .dependsOn(sd, repository, `models-common`, common, protocol)
      .settings(commonSettings)
      .settings(
        Settings.compilerPlugins.map(addCompilerPlugin): _*
      )
      .settings(libraryDependencies ++= gwDeps)
      .settings(
        version                           := gw_version,
        mappings in (Compile, packageDoc) := Seq(),
        maintainer                        := "",
        mappings in Universal ++= {
          val resources = (resourceDirectory in Compile).value
          Seq(
            resources / "dev.conf"              -> "conf/dev.conf",
            resources / "prod.conf"             -> "conf/prod.conf",
            resources / "logback.xml"           -> "conf/logback.xml",
            resources / "secret.key"            -> "conf/secret.key",
            resources / "swagger-ui/index.html" -> "conf/swagger-ui/index.html",
            resources / "swagger.yaml"          -> "conf/swagger.yaml"
          )
        }
      )
      .settings(bashScriptExtraDefines ++= Settings.GWExtraSettings)
      .settings(bashScriptExtraDefines ++= Settings.appVersion(version.value))
    build task:
    lazy val makeGateway = taskKey[Unit]("make gateway")
    makeGateway := {
      (gateway / clean).value
      val file      = (packageBin in (gateway, Universal)).value
      val base      = baseDirectory.value
      val artifacts = base / "deployment" / "artifacts" / "gateway"
    
      val destination    = base / "dist" / file.name
      val relative       = base.relativize(Paths.get(file.getAbsolutePath).toFile).get
      val fullName       = s"gateway-${(version in gateway).value}"
      val currentVersion = (version in gateway).value
      val dest           = base / "deployment" / "gateway" / "source"
      println(destination.toPath.toFile)
      IO.copyFile(relative, destination.toPath.toFile)
      IO.unzip(destination.toPath.toFile, artifacts)
      IO.move(artifacts / fullName, dest)
      IO.write(dest / "version", currentVersion)
    }
    Evgenii
    @ibanezn04
    unzipped jar:
    tree -L 3
    .
    β”œβ”€β”€ META-INF
    β”‚   └── MANIFEST.MF
    └── ru
        └── tinkoff
            └── tss
    nigredo-tori
    @nigredo-tori
    @ibanezn04, does removing the (gateway / clean).value line change this?
    Evgenii
    @ibanezn04
    @nigredo-tori yes, it does! wow, thank you! why (gateway / clean).value removes resources? i thought it's just sbt clean, am i wrong?
    nigredo-tori
    @nigredo-tori
    clean in any project is a task that removes transient files in that project. gateway / clean removes them in gateway. sbt clean calls clean in the root project, as well as in all the projects the root aggregates (that's just how aggregation behaves in the SBT console).
    BTW, running clean as a dependency of another task is usually a bad idea. SBT has a lot of freedom in scheduling tasks, so you can wind up with clean running in the middle of your build, botching anything that has been done until that moment. There are ways to work around that, but it's easier to just avoid this antipattern.
    Evgenii
    @ibanezn04
    @nigredo-tori so instead of having clean inside task, i should call sbt "; clean; taskName"?
    Nepomuk Seiler
    @muuki88
    Yes
    Evgenii
    @ibanezn04
    @nigredo-tori @muuki88 thank you a lot!
    Matthew de Detrich
    @mdedetrich
    Does anyone have issues using Linux unzip with .zip files being created by sbt-native-packager and causing a zip bomb error?
    With the error: invalid zip file with overlapped components (possible zip bomb)error
    Note that I am using the -o flag on unzip as well
    I think it may have to do with the fact that sbt-native-packager is creating duplicate entries in the .jar archive that is triggering the zip bomb (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=931895#73)
    Nepomuk Seiler
    @muuki88
    @mdedetrich yeiks! That sounds horrible. Do you have a small reproducible test case?
    Matthew de Detrich
    @mdedetrich
    Well its company code so it may take a while. Funny thing is that I had this problem before and I fixed it by adding the -o flag to unzip, now when I updated the dependencies of this project it came back again
    nigredo-tori
    @nigredo-tori
    @mdedetrich, does that happen on 32-bit or 64-bit system?
    Matthew de Detrich
    @mdedetrich
    64
    Its also a server + client application (scala + scala.js) that uses webjars if that is helpful
    The generated package is probably non trivial
    nigredo-tori
    @nigredo-tori
    OK, I've just seen some recently fixed issue on 32-bit systems. That can't be it, then.
    Just to be sure, please try doing show Universal / mappings in the SBT console. Are there any duplicates?
    Matthew de Detrich
    @mdedetrich
    Okay, the 64 bit may not be entirely correct because the error is happening in CDP. In which version of sbt-native-packager did you fix this?
    nigredo-tori
    @nigredo-tori
    Matthew de Detrich
    @mdedetrich
    @nigredo-tori I will message you the mappings via Gitter PM if thats okay?
    nigredo-tori
    @nigredo-tori
    Sure.
    nigredo-tori
    @nigredo-tori
    Results: duplicate conf/application.ini from bat and bash script plugins. There's a fix for it now, but the SNP in question was slightly older. We still should check mappings for duplicates before zipping just to be sure - don't know if this is already happening, and I don't really have time to check.
    Matthew de Detrich
    @mdedetrich
    I can confirm that updating to 1.3.2 fixed the problem
    Nepomuk Seiler
    @muuki88
    Thanks for the results @nigredo-tori β™₯️
    Alix BAGGIO
    @AlixBa
    This message was deleted