play-swagger
play-swagger copied to clipboard
sbtPlugin does not run when when using docker plugin
When I use the docker sbt plugin to create a docker image, it does not create the output swagger.json file.
>docker:stage
[info] Loading project definition from D:\workspace\myProject\project
[info] Set current project to myProject (in build file:/D:/workspace/myProject/)
[info] Packaging D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0-sources.jar ...
[info] Wrote D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0.pom
[info] Updating {file:/D:/workspace/myProject/}myProject...
[info] Resolving com.typesafe.play#play-netty-utils;2.5.4 ...
[info] Done packaging.
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 7 Scala sources and 2 Java sources to D:\workspace\myProject\target\scala-2.11\classes...
[info] Packaging D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0.jar ...
[info] Done packaging.
[info] Packaging D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0-sans-externalized.jar ...
[info] Done packaging.
[success] Total time: 28 s, completed Aug 31, 2016 5:18:15 PM
If I use the regular stage command, I see the line reporting it is generating the output:
>stage
[info] Loading project definition from D:\workspace\myProject\project
[info] Set current project to myProject (in build file:/D:/workspace/myProject/)
[info] Compiling 4 Scala sources and 1 Java source to D:\workspace\myProject\target\scala-2.11\classes...
[info] Running com.iheart.playSwagger.SwaggerSpecRunner D:\workspace\myProject\target\swagger\swagger.json routes mynamespace
[info] Packaging D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0-web-assets.jar ...
[info] Done packaging.
[info] Packaging D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0.jar ...
[info] Wrote D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0.pom
[info] Done packaging.
[info] Packaging D:\workspace\myProject\target\scala-2.11\myProject_2.11-1.0-sans-externalized.jar ...
[info] Done packaging.
[success] Total time: 12 s, completed Aug 31, 2016 5:18:42 PM
I wonder if change the attaching task from stage
to package
would solve this problem?
Here: https://github.com/iheartradio/play-swagger/blob/master/sbtPlugin/src/main/scala/com/iheart/sbtPlaySwagger/SwaggerPlugin.scala#L45
I'm not very familiar with sbt plugins, but looking at the source of the sbt-native-packager docker plugin, I don't think it will. It looks like this directly stages the files without using any of the basic tasks:
https://github.com/sbt/sbt-native-packager/blob/master/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala#L131
Hey guys, it's a bit unfortunate the way the docker plugin redefines stage. However, the solution is pretty simple. Just add:
(stage in Docker) <<= (stage in Docker).dependsOn(swagger)
This could be added into the plugin, but that would make it dependent on the DockerPlugin ... Cheers, M
Hi guys,
I've just had the same problem with activator universal:packageZipTarball
. Since only packageBin
is referenced in the plugin configuration it does not generate the swagger.json
.
Fixed it by adding :
(packageZipTarball in Universal) <<= (packageZipTarball in Universal).dependsOn(swagger)
to my build.sbt
(thanks @mosche for having put me on the right way).
Maybe there is a way to handle all universal
tasks in the plugin configuration ?
Hi, if feels clumsy, but I don't know a better way than just adding all of the universal packagers to the projectSettings in the plugin.
Seq(packageBin, packageOsxDmg, packageZipTarball, packageXzTarball).map( universalPackage ⇒
universalPackage in Universal <<= (universalPackage in Universal).dependsOn(swagger)
)
Unfortunately, I don't really have the time to test properly at the moment :/
@mosche Thanks Moritz. '<<=' is removed in sbt 1.x and unfortunately the suggested replacement does not work for me
Seq(packageBin, packageOsxDmg, packageZipTarball, packageXzTarball).map( universalPackage ⇒
universalPackage in Universal := (universalPackage in Universal).dependsOn(swagger).value
)
@longliveenduro Hey Chris, how are you trying to package your app?
@mosche I do use sbt universal:packageZipTarball
with sbt version 1.1.1 and play swagger 0.7.4
Sorry @longliveenduro, I currently don't have such an example handy. Do you get an error, or does it just not trigger the swagger task?
If the latter is the case, are you defining the settings in a plugin or in your build.sbt? If it's a plugin, you might just need to depend on UniversalPlugin to force the right initialization order of your settings.
Otherwise happy to have a look if you push some code.
@mosche Hi Moritz. The swagger task gets executed, so the swagger.json is created and is in target/swagger. The only thing that does not work is that it ends up in the final tarball. Seems there is somehow the attachment of the resource missing. As I package it in a docker image I could easily make a workaround by copying it to the image manually. So that works for me with that workaround. Thanks, Moritz!
@longliveenduro This is the line that should do the job, but apparently not in your case :/ https://github.com/iheartradio/play-swagger/blob/master/sbtPlugin/src/main/scala/com/iheart/sbtPlaySwagger/SwaggerPlugin.scala#L51
You could give it a try using mappings in Universal
instead to add the same mapping as linked above.
@mosche Thanks Moritz. Adding
mappings in Universal += (swaggerTarget.value / swaggerFileName.value) → s"public/${swaggerFileName.value}" //include it in the unmanagedResourceDirectories in Assets doesn't automatically include it package
to my build.sbt fixes the problem. The current mapping in the plugin only works for the zip file and not the tarball. Thanks mate!
For anybody trying to use the docker:stage
command in the Play Framework. We had this same issue and solved it by adding
stage in Docker := (stage in Docker).dependsOn(swagger).value
to our build.sbt
. Maybe someone finds this useful :)