Skip to content

Commit

Permalink
Small corrections for gcp cloudrun example (#405)
Browse files Browse the repository at this point in the history
* small corrections for gcp cloudrun example
* fix stupid scala-cli & bloop behaviour
  • Loading branch information
lbialy authored Aug 22, 2024
1 parent fbd6ca5 commit e296d7f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ clean-test-templates:
test-example example-name:
@echo "----------------------------------------"
@echo "Testing example {{example-name}}"
scala-cli bloop exit # allow different examples use different jvms
scala-cli compile -v -v -v {{no-bloop-ci}} examples/{{example-name}} {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning

# Cleans after an example test
Expand Down
3 changes: 2 additions & 1 deletion examples/gcp-cloudrun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ These values are indicated with `***`.
pulumi -C infra config set gcp:region us-west1 # any valid GCP region here
```

3. Authenticate to GCR with Docker:
3. Authenticate to GCR with application-default credentials and Docker:

```bash
gcloud auth application-default login # this is required for pulumi to reach GCP
gcloud auth configure-docker # this is required to push the container
```

Expand Down
2 changes: 2 additions & 0 deletions examples/gcp-cloudrun/app/.scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "3.7.15"
runner.dialect = scala3
7 changes: 4 additions & 3 deletions examples/gcp-cloudrun/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ WORKDIR /src
# Copy local code to the container image
COPY . .
# Build a native binary with Scala CLI
ARG GRAALVM_VERSION=22
ARG GRAALVM_VERSION=21.0.2
RUN \
--mount=type=cache,target=/root/.cache/coursier \
/usr/local/bin/scala-cli --power package . \
--suppress-experimental-feature-warning \
--server=false \
--jvm=graalvm-java17 \
--jvm=graalvm-java21:21.0.2 \
--native-image \
--graalvm-jvm-id=graalvm-java17:${GRAALVM_VERSION} \
--graalvm-jvm-id=graalvm-java21:${GRAALVM_VERSION} \
--graalvm-args="--static" \
--graalvm-args="--install-exit-handlers" \
--main-class org.virtuslab.besom.example.main -o app -f

FROM --platform=linux/amd64 gcr.io/distroless/static
Expand Down
3 changes: 2 additions & 1 deletion examples/gcp-cloudrun/app/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.virtuslab.besom.example

import sttp.tapir.*
import sttp.tapir.server.jdkhttp.*
import java.util.concurrent.Executors

@main def main(): Unit =
// required by Cloud Run Container runtime contract https://cloud.google.com/run/docs/reference/container-contract
Expand All @@ -13,8 +14,8 @@ import sttp.tapir.server.jdkhttp.*

println(s"Starting server on $host:$port")
val _ = JdkHttpServer()
.executor(Executors.newVirtualThreadPerTaskExecutor())
.host(host)
.port(port)
.addEndpoint(handler)
.start()
end main
7 changes: 4 additions & 3 deletions examples/gcp-cloudrun/app/project.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//> using scala 3.3.1
//> using options -java-output-version:17 -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
//> using jvm "graalvm-java21:21.0.2"

//> using dep com.softwaremill.sttp.tapir::tapir-jdkhttp-server:1.9.9
//> using dep com.softwaremill.sttp.tapir::tapir-jdkhttp-server:1.9.10

//> using publish.organization org.virtuslab.besom.example
//> using publish.name app
//> using publish.name app
3 changes: 2 additions & 1 deletion examples/gcp-cloudrun/infra/project.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//> using scala "3.3.1"
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
///> using plugin "org.virtuslab::besom-compiler-plugin:0.3.2"

//> using dep "org.virtuslab::besom-core:0.4.0-SNAPSHOT"
//> using dep "org.virtuslab::besom-gcp:7.26.0-core.0.3"
//> using dep "org.virtuslab::besom-docker:4.5.4-core.0.3"


//> using exclude "app/*"
//> using repository sonatype:snapshots

0 comments on commit e296d7f

Please sign in to comment.