From 75475fff8854524da72c83226689eabb90f83e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunnar=20Andr=C3=A9=20Saxvik-Lilleaasen?= Date: Wed, 6 Apr 2022 17:28:30 +0200 Subject: [PATCH] Added Scala (Community) definition. --- containers/scala/.devcontainer/Dockerfile | 46 ++++++++ .../scala/.devcontainer/devcontainer.json | 37 +++++++ containers/scala/.npmignore | 3 + containers/scala/README.md | 104 ++++++++++++++++++ containers/scala/test-project/Hello.scala | 4 + 5 files changed, 194 insertions(+) create mode 100644 containers/scala/.devcontainer/Dockerfile create mode 100644 containers/scala/.devcontainer/devcontainer.json create mode 100644 containers/scala/.npmignore create mode 100644 containers/scala/README.md create mode 100644 containers/scala/test-project/Hello.scala diff --git a/containers/scala/.devcontainer/Dockerfile b/containers/scala/.devcontainer/Dockerfile new file mode 100644 index 0000000000..35bf3a6733 --- /dev/null +++ b/containers/scala/.devcontainer/Dockerfile @@ -0,0 +1,46 @@ +# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster +ARG VARIANT="17" +FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} + +# [Optional] Scala version (leave blank for latest) +ARG SCALA_VERSION="" + +# [Option] Install Mill +ARG INSTALL_MILL="false" + +# [Option] Install SBT +ARG INSTALL_SBT="false" + +# [Option] Install Clang (required for Scala Native) +ARG INSTALL_CLANG="false" + +RUN curl -fLJ -o /usr/local/bin/scala-cli https://github.com/Virtuslab/scala-cli/releases/latest/download/scala-cli && \ + chmod +x /usr/local/bin/scala-cli && \ + su vscode -c "scala-cli compile . --scala=${SCALA_VERSION}" + +RUN if [ "${INSTALL_MILL}" = "true" ]; then \ + curl -o /usr/local/bin/mill https://raw.githubusercontent.com/lefou/millw/main/millw && \ + chmod +x /usr/local/bin/mill && \ + (cd /tmp; su vscode -c "mill resolve _"); fi + +RUN if [ "${INSTALL_SBT}" = "true" ]; then \ + echo "deb [signed-by=/usr/share/keyrings/sbt-archive-keyring.gpg] https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list && \ + echo "deb [signed-by=/usr/share/keyrings/sbt-archive-keyring.gpg] https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list && \ + curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | gpg --dearmor | sudo tee /usr/share/keyrings/sbt-archive-keyring.gpg > /dev/null && \ + sudo apt-get update && \ + sudo apt-get install sbt && \ + (cd /tmp; su vscode -c "sbt --version") && \ + rm -rf /var/lib/apt/lists/*; fi + +RUN if [ "${INSTALL_CLANG}" = "true" ]; then apt-get update && apt-get -y install clang && su vscode -c "scala-cli compile . --native" && rm -rf /var/lib/apt/lists/*; fi + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/containers/scala/.devcontainer/devcontainer.json b/containers/scala/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..8e44c7561b --- /dev/null +++ b/containers/scala/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/java +{ + "name": "Scala (Community)", + "build": { + "dockerfile": "Dockerfile", + "args": { + // Update the VARIANT arg to pick a Java version: 11, 17 + // Append -bullseye or -buster to pin to an OS version. + // Use the -bullseye variants on local arm64/Apple Silicon. + "VARIANT": "17", + // Options + "INSTALL_MILL": "false", + "INSTALL_SBT": "false", + "NODE_VERSION": "lts/*" + } + }, + + "settings": { + "java.jdt.ls.java.home": "/docker-java-home" + }, + + "extensions": [ + "vscjava.vscode-java-pack", + "scala-lang.scala", + "scalameta.metals" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "scala-cli --version", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} \ No newline at end of file diff --git a/containers/scala/.npmignore b/containers/scala/.npmignore new file mode 100644 index 0000000000..007bd26e19 --- /dev/null +++ b/containers/scala/.npmignore @@ -0,0 +1,3 @@ +test-project +README.md +.npmignore \ No newline at end of file diff --git a/containers/scala/README.md b/containers/scala/README.md new file mode 100644 index 0000000000..2edc42e0bb --- /dev/null +++ b/containers/scala/README.md @@ -0,0 +1,104 @@ +# Scala (Community) + +## Summary + +*Develop Scala applications. Includes the Metals and Scala Syntax extensions.* + +| Metadata | Value | +|-----------------------------|-----------------------| +| *Contributors* | @heksesang | +| *Categories* | Community, Languages | +| *Definition Type* | Dockerfile | +| *Works in Codespaces* | Yes | +| *Container host OS support* | Linux, MacOS, Windows | +| *Container OS* | Debian | +| *Languages, platforms* | Scala | + +## Using this definition + +While this definition should work unmodified, you can select the version of Java the container uses by updating the `VARIANT` arg in the included `devcontainer.json` (and rebuilding if you've already created the container). + +```json +// Or you can use 17-bullseye or 17-buster if you want to pin to an OS version +"args": { "VARIANT": "17" } +``` + +### Installing a specific Scala Version + +You can set the default Scala version that is pre-loaded with Scala CLI by adding the `"SCALA_VERSION"` to the build arguments in `.devcontainer/devcontainer.json`. + +```json +"args": { + "SCALA_VERSION": "2.13.5" +} +``` + +### Installing Mill + +Mill can be installed by setting the `"INSTALL_MILL"` build argument to true in `.devcontainer/devcontainer.json`. + +```json +"args": { + "INSTALL_MILL": "true" +} +``` + +### Installing SBT + +SBT can be installed by setting the `"INSTALL_SBT"` build argument to true in `.devcontainer/devcontainer.json`. + +```json +"args": { + "INSTALL_SBT": "true" +} +``` + +### Installing Clang + +Scala Native is a compiler for Scala that targets native code, and depends on the Clang compiler frontend. You can enable support for this by setting the `"INSTALL_CLANG"` build argument to true in `.devcontainer/devcontainer.json`. + +```json +"args": { + "INSTALL_CLANG": "true" +} +``` + +### Adding the definition to your folder + +1. If this is your first time using a development container, please see getting started information on [setting up](https://aka.ms/vscode-remote/containers/getting-started) Remote-Containers or [creating a codespace](https://aka.ms/ghcs-open-codespace) using GitHub Codespaces. + +2. Start VS Code and open your project folder or connect to a codespace. + +3. Press F1 select and **Add Development Container Configuration Files...** command for **Remote-Containers** or **Codespaces**. + +4. Select this definition. You may also need to select **Show All Definitions...** for it to appear. + +5. Finally, press F1 and run **Remote-Containers: Reopen Folder in Container** or **Codespaces: Rebuild Container** to start using the definition. + +## Testing the definition + +This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps: + +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. + +2. Clone this repository. + +3. Start VS Code, press F1, and select **Remote-Containers: Open Folder in Container...** + +4. Select the `containers/scala` folder. + +5. After the folder has opened in the container, press Ctrl-Shift-` + to open a new terminal. + +6. Run the following command to execute a simple application. + ```bash + scala-cli run test-project + ``` + +7. You should see "Hello world!" in the terminal after the program executes. + +8. From here, you can add breakpoints or edit the contents of the `test-project` folder to do further testing. + +## License + +Licensed under the MIT License. See [LICENSE](https://github.com/microsoft/vscode-dev-containers/blob/main/LICENSE). diff --git a/containers/scala/test-project/Hello.scala b/containers/scala/test-project/Hello.scala new file mode 100644 index 0000000000..5f069a2875 --- /dev/null +++ b/containers/scala/test-project/Hello.scala @@ -0,0 +1,4 @@ +//> using scala "3" + +@main def run = + println("Hello world!") \ No newline at end of file