PEZ / pirate-lang

Zero Install Calva + Gitpod + VNC + deps.edn demo project
9 stars 2 forks source link

Gitpod magic but locally with VSCode devcontainers #2

Open Arkweid opened 2 years ago

Arkweid commented 2 years ago

Gitpod is good, but require internet connection and works on external machines(performance and security issues).

VSCode could do the same magic, but locally. Documentation: https://code.visualstudio.com/docs/remote/create-dev-container

.gitpod.dockerfile the same thing as .devcontainer/Dockerfile .gitpod.yml the same thing as .devcontainer/devcontainer.json

Microsoft have official repos for try some popular languages right out-of-the-box: https://github.com/microsoft?utf8=%E2%9C%93&q=vscode-remote-try- I have found similar solution for Clojure: https://github.com/1and1/vscode-remote-try-clojure But the problem is a lot of Calva features and nrepl doens't work properly in that repository(obviously too outdated).

So, could we have some vscode-remote-try-clojure with all Calva shiny things for local development?

PEZ commented 2 years ago

Thanks for this information! I'll have a look and see what I can do about it.

willmruzek commented 2 years ago

Saw your chat in Slack.

I recently setup a .devcontainer env with Clojure and Calva.

I took the "try Java" devcontainer and just installed Clojure, clojure-lsp, and added Calva to the settings. (You also need to explicitly point to the clojure-lsp bin in the container.)

I'm also on an M1 Mac so I'm using bullseye images, but I assume this would work with x86 images as well.

Not sure if it checks all the boxes. But thought I would offer.

.devcontainer/devcontainer.json

// 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.224.2/containers/java
{
    "name": "Java",
    "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": "11-bullseye",
            // Options
            "INSTALL_MAVEN": "true",
            "INSTALL_GRADLE": "false",
            "NODE_VERSION": "lts/*"
        }
    },
    // Set *default* container specific settings.json values on container create.
    "settings": {
        "java.jdt.ls.java.home": "/docker-java-home",
        "calva.clojureLspPath": "/usr/local/bin/clojure-lsp",
    },
    // Add the IDs of extensions you want installed when the container is created.
    "extensions": [
        "vscjava.vscode-java-pack",
        "betterthantomorrow.calva"
    ],
    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    "forwardPorts": [
        8088,
        52162
    ], // example: your webapp, your nREPL
    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "java -version",
    // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode",
    "features": {
        "git": "os-provided"
    }
}

.devcontainer/Dockerfile

# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/java/.devcontainer/base.Dockerfile

# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster
ARG VARIANT="17-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}

# [Option] Install Maven
ARG INSTALL_MAVEN="false"
ARG MAVEN_VERSION=""
# [Option] Install Gradle
ARG INSTALL_GRADLE="false"
ARG GRADLE_VERSION=""
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; 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 <packages>

# [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

# Install Clojure (make sure to match base image OS/arch)
COPY --from=clojure:openjdk-11-tools-deps-bullseye /usr/local/bin/clj /usr/local/bin/clojure /usr/local/bin/rlwrap /usr/local/bin/
COPY --from=clojure:openjdk-11-tools-deps-bullseye /usr/local/lib/clojure /usr/local/lib/clojure
COPY --from=clojure:openjdk-11-tools-deps-bullseye /usr/bin/rlwrap /usr/bin/rlwrap

# Install clojure-lsp
RUN ["/bin/bash", "-c", "sudo bash < <(curl -s https://raw.githubusercontent.com/clojure-lsp/clojure-lsp/master/install)"]
PEZ commented 2 years ago

I now tried to generate a container from the docker file in this repo. It is still building the container after 15 minutes. Every step seems to take a very long time. Is this to be expected, would you say who have tried devcontainers?

PEZ commented 2 years ago

Looks like so:

image
willmruzek commented 2 years ago

That's not been my experience. Mine usually builds in <= 1min.

Are you using the same CPU arch for the base image as your host machine?

willmruzek commented 2 years ago

I've also had lengthy install times for homebrew (on my host M1 Mac though). It might be worth using Dockerfile's multi-stage build feature, ex:

# Install Clojure (make sure to match base image OS/arch)
COPY --from=clojure:openjdk-11-tools-deps-bullseye /usr/local/bin/clj /usr/local/bin/clojure /usr/local/bin/rlwrap /usr/local/bin/
COPY --from=clojure:openjdk-11-tools-deps-bullseye /usr/local/lib/clojure /usr/local/lib/clojure
COPY --from=clojure:openjdk-11-tools-deps-bullseye /usr/bin/rlwrap /usr/bin/rlwrap
Arkweid commented 2 years ago

Gitpod provide this Dockerfile https://github.com/gitpod-io/template-clojure/blob/main/.gitpod.Dockerfile Builds around 1 min on my PC. And then starts instantly after being cached by Docker.

PEZ commented 2 years ago

I tried with your docker file now, @mruzekw. It built much quicker.