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

Add docker packaging using directives #1753

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ class PackagingUsingDirectiveTests extends munit.FunSuite {
}
}

test("docker options") {
val inputs = TestInputs(
os.rel / "p.sc" ->
"""//> using packaging.dockerFrom "openjdk:11"
|//> using packaging.dockerImageTag "1.0.0"
|//> using packaging.dockerImageRegistry "virtuslab"
|//> using packaging.dockerImageRepository "scala-cli"
|
|def foo() = println("hello foo")
|""".stripMargin
)
inputs.withLoadedBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
val dockerOpt = maybeBuild.options.notForBloopOptions.packageOptions.dockerOptions
expect(dockerOpt.from == Some("openjdk:11"))
expect(dockerOpt.imageTag == Some("1.0.0"))
expect(dockerOpt.imageRegistry == Some("virtuslab"))
expect(dockerOpt.imageRepository == Some("scala-cli"))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.build.errors.{
MalformedInputError,
ModuleFormatError
}
import scala.build.options.packaging.DockerOptions
import scala.build.options.{
BuildOptions,
JavaOpt,
Expand All @@ -27,10 +28,15 @@ import scala.cli.commands.SpecificationLevel
@DirectiveExamples("//> using packaging.packageType \"assembly\"")
@DirectiveExamples("//> using packaging.output \"foo\"")
@DirectiveExamples("//> using packaging.provided \"org.apache.spark::spark-sql\"")
@DirectiveExamples("//> using packaging.dockerFrom \"openjdk:11\"")
@DirectiveUsage(
"""using packaging.packageType [package type]
|using packaging.output [destination path]
|using packaging.provided [module]
|using packaging.dockerFrom [base docker image]
|using packaging.dockerImageTag [image tag]
|using packaging.dockerImageRegistry [image registry]
|using packaging.dockerImageRepository [image repository]
|""".stripMargin,
"""`//> using packaging.packageType `"package type"
|
Expand All @@ -44,7 +50,11 @@ import scala.cli.commands.SpecificationLevel
final case class Packaging(
packageType: Option[Positioned[String]] = None,
output: Option[String] = None,
provided: List[Positioned[String]] = Nil
provided: List[Positioned[String]] = Nil,
dockerFrom: Option[String] = None,
dockerImageTag: Option[String] = None,
dockerImageRegistry: Option[String] = None,
dockerImageRepository: Option[String] = None
) extends HasBuildOptions {
// format: on
def buildOptions: Either[BuildException, BuildOptions] = either {
Expand Down Expand Up @@ -90,7 +100,13 @@ final case class Packaging(
packageOptions = PackageOptions(
packageTypeOpt = packageTypeOpt,
output = output0.map(_.toString),
provided = provided0
provided = provided0,
dockerOptions = DockerOptions(
from = dockerFrom,
imageRegistry = dockerImageRegistry,
imageRepository = dockerImageRepository,
imageTag = dockerImageTag
)
)
)
)
Expand Down
35 changes: 35 additions & 0 deletions website/docs/commands/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,38 @@ This using directive makes it possible to define the destination path of the pac
```

The using directive above makes it possible to create a package named `foo` inside the current directory.

### Docker

#### packaging.dockerFrom

The using directive allows you to define the base Docker image that is used to run your application.

```scala compile
//> using packaging.dockerFrom "openjdk:11"
```

#### packaging.dockerFrom

The using directive allows you to define the generated Docker image tag.

```scala compile
//> using packaging.dockerImageTag "1.0.0"
```

#### packaging.dockerImageRegistry

The using directive allows you to define the image registry.

```scala compile
//> using packaging.dockerImageRegistry "virtuslab"
```

#### packaging.dockerImageRegistry

The using directive allows you to define the image repository.

```scala compile
//> using packaging.dockerImageRepository "scala-cli"
```

2 changes: 2 additions & 0 deletions website/docs/reference/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Set parameters for packaging

`//> using packaging.provided "org.apache.spark::spark-sql"`

`//> using packaging.dockerFrom "openjdk:11"`

### Platform

Set the default platform to Scala.js or Scala Native
Expand Down