Skip to content

Commit

Permalink
Fix devcontainer (#810)
Browse files Browse the repository at this point in the history
* Update devcontainer pattern to a more modern style using the devcontainer "features" capability.

* Switches the devcontainer user from root to vscode

* Automatically add the toolchain and dev deps for static cross compilation

* Fix issue with go dependecy
  • Loading branch information
hulto authored Dec 29, 2024
1 parent b007f12 commit ff98f67
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 1,017 deletions.
67 changes: 5 additions & 62 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,71 +1,14 @@
# See VSCode default image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/go/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/devcontainers/base:bookworm@sha256:6155a486f236fd5127b76af33086029d64f64cf49dd504accb6e5f949098eb7e

# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon)
ARG GO_VARIANT=1.20.2-buster
FROM golang:${GO_VARIANT}

# Copy library scripts to execute
COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/

# [Option] Install zsh
ARG INSTALL_ZSH="true"
# [Option] Upgrade OS packages to their latest versions
ARG UPGRADE_PACKAGES="true"
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
# Install Jekyll
RUN bash /tmp/library-scripts/jekyll-debian.sh

# Persist Bash History
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
&& echo $SNIPPET >> "/root/.bashrc"

# Install Go tools
ENV GO111MODULE=auto
RUN bash /tmp/library-scripts/go-debian.sh "none" "/usr/local/go" "${GOPATH}" "${USERNAME}" "false" \
&& go install golang.org/x/tools/gopls@latest \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install Rust tools
RUN bash /tmp/library-scripts/rust-debian.sh "${CARGO_HOME}" "${RUSTUP_HOME}" "${USERNAME}" "true" "true" \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install gRPC tools
ENV CARGO_HOME="/usr/local/cargo"
ENV RUSTUP_HOME="/usr/local/rustup"
ENV PATH=${CARGO_HOME}/bin:${PATH}
RUN apt update -y \
&& apt install -y protobuf-compiler libprotobuf-dev \
&& go install google.golang.org/protobuf/cmd/[email protected] \
&& go install google.golang.org/grpc/cmd/[email protected] \
&& cargo install protobuf-codegen

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="lts/*"
ENV NVM_DIR=/usr/local/share/nvm
ENV NVM_SYMLINK_CURRENT=true \
PATH=${NVM_DIR}/current/bin:${PATH}
RUN bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install Jekyll
RUN bash /tmp/library-scripts/jekyll-debian.sh

# Remove library scripts for final image
RUN rm -rf /tmp/library-scripts

# [Choice] Node.js version: lts/*, 16, 14, 12, 10
#ARG NODE_VERSION="lts/*"
#RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c ". /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 the next line to use go get to install anything else you need
# RUN go get -x <your-dependency-or-tool>

# [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 additional rust dependencies for static cross compile builds
RUN apt update && apt install -y musl-tools gcc-mingw-w64
48 changes: 31 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
{
"name": "Realm DevContainer",
"name": "Debian",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile",
"args": {
// Use the -bullseye variants if you are on a M1 mac.
"GO_VARIANT": "1.20.2-buster",
"RUST_VARIANT": "buster",
// Options
"NODE_VERSION": "lts/*"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Set *default* container specific settings.json values on container create.
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"installOhMyZshConfig": true,
"username": "vscode",
"userUid": "1001",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.23"
},
"ghcr.io/devcontainers/features/python:1": {
"installTools": true,
"version": "3.12"
},
"ghcr.io/devcontainers/features/rust:1": {
"version": "1.76",
"profile": "minimal",
"targets": "aarch64-unknown-linux-gnu,x86_64-unknown-linux-musl,x86_64-pc-windows-gnu"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
}
},
"customizations": {
"vscode": {
"settings": {
Expand Down Expand Up @@ -49,17 +65,15 @@
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"appPort": [
"127.0.0.1:80:80"
],
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
// SPEEEEEEED on MacOS & Windows. Note that your local clone of realm will not be updated.
"remoteUser": "vscode",
"workspaceMount": "source=realm,target=/workspaces/realm,type=volume",
"workspaceFolder": "/workspaces/realm",
"postCreateCommand": "cd /workspaces && git clone https://github.com/spellshift/realm.git",
"postCreateCommand": "sudo chown -R vscode:vscode /workspaces && cd /workspaces && git clone https://github.com/spellshift/realm.git",
"mounts": [
"source=realm-bashhistory,target=/commandhistory,type=volume"
]

}
2 changes: 0 additions & 2 deletions .devcontainer/library-scripts/README.md

This file was deleted.

Loading

0 comments on commit ff98f67

Please sign in to comment.