Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Added Scala (Community) definition. #1396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions containers/scala/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
37 changes: 37 additions & 0 deletions containers/scala/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions containers/scala/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-project
README.md
.npmignore
104 changes: 104 additions & 0 deletions containers/scala/README.md
Original file line number Diff line number Diff line change
@@ -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 <kbd>F1</kbd> 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 <kbd>F1</kbd> 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 <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**

4. Select the `containers/scala` folder.

5. After the folder has opened in the container, press <kbd>Ctrl-Shift-`</kbd>
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).
4 changes: 4 additions & 0 deletions containers/scala/test-project/Hello.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//> using scala "3"

@main def run =
println("Hello world!")