diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..d8f9e043 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,39 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/ubuntu/.devcontainer/base.Dockerfile + +# [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 +ARG VARIANT +FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} +ARG TARGETARCH + +######################################################### +### Create bin folder under $HOME for random binaries ### +######################################################### +USER vscode +RUN mkdir $HOME/bin +ENV PATH=$PATH:$HOME/bin + +######################################### +### Bazel and Bazel releated binaries ### +######################################### +# Install bazelisk +RUN curl -o $HOME/bin/bazelisk-linux-$TARGETARCH -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-$TARGETARCH \ + && mv $HOME/bin/bazelisk-linux-$TARGETARCH $HOME/bin/bazelisk \ + && chmod +x $HOME/bin/bazelisk \ + && ln -s $HOME/bin/bazelisk $HOME/bin/bazel + +# Install bazel-watcher +RUN curl -o $HOME/bin/ibazel_linux_$TARGETARCH -fsSL https://github.com/bazelbuild/bazel-watcher/releases/download/v0.24.0/ibazel_linux_$TARGETARCH \ + && mv $HOME/bin/ibazel_linux_$TARGETARCH $HOME/bin/ibazel \ + && chmod +x $HOME/bin/ibazel + +# Install buildifier +RUN curl -o $HOME/bin/buildifier-linux-$TARGETARCH -fsSL https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-linux-$TARGETARCH \ + && mv $HOME/bin/buildifier-linux-$TARGETARCH $HOME/bin/buildifier \ + && chmod +x $HOME/bin/buildifier + +# Install buildozer +RUN curl -o $HOME/bin/buildozer-linux-$TARGETARCH -fsSL https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-linux-$TARGETARCH \ + && mv $HOME/bin/buildozer-linux-$TARGETARCH $HOME/bin/buildozer \ + && chmod +x $HOME/bin/buildozer + +COPY --chown=vscode ./devcontainer.bazelrc /home/vscode/.bazelrc diff --git a/.devcontainer/devcontainer.bazelrc b/.devcontainer/devcontainer.bazelrc new file mode 100644 index 00000000..70dc8967 --- /dev/null +++ b/.devcontainer/devcontainer.bazelrc @@ -0,0 +1,4 @@ +# Set the Bazel build outputs to the ~/.cache directory so that the build outputs +# are persisted on the cache volume between devcontainers. +startup --output_user_root=~/.cache/bazel_output_user_root +startup --output_base=~/.cache/bazel_output_base diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..afe46a58 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,65 @@ +// 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.245.0/containers/ubuntu +{ + "name": "rules_dotnet", + "containerEnv": { + // Override .Net cache locations: https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders + "NUGET_PACKAGES": "/home/vscode/.cache/nuget_packages", + "NUGET_HTTP_CACHE_PATH": "/home/vscode/.cache/nuget_http_cache" + }, + "mounts": [ + // We mount the caches as volumes so that they persist between containers + "source=rules-dotnet-caches,target=/home/vscode/.cache,type=volume" + ], + "onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/onCreateCommand.sh", + // We need to chown the .cache folder since it's created by the root user during the container creation + "postCreateCommand": "sudo chown vscode /home/vscode/.cache", + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + // Set the default terminal to use Bash because it can get wonky + // if the user has e.g. zsh or fish configured as their default shell + // and it's not installed in the container. + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash", + "args": [] + } + }, + "terminal.integrated.defaultProfile.linux": "bash" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "BazelBuild.vscode-bazel", + "ms-dotnettools.csharp", + "Ionide.Ionide-fsharp", + "zxh404.vscode-proto3", + "timonwong.shellcheck", + "mutantdino.resourcemonitor" + ] + } + }, + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04 + // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon. + "args": { + "VARIANT": "ubuntu-22.04" + } + }, + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "ghcr.io/devcontainers/features/dotnet:2.0.2": { + "version": "7.0.404" + }, + "ghcr.io/devcontainers/features/git:1.1.6": { + "version": "2.43.0" + }, + "ghcr.io/devcontainers/features/github-cli:1.0.11": { + "version": "2.42.1" + } + } +} diff --git a/.devcontainer/scripts/onCreateCommand.sh b/.devcontainer/scripts/onCreateCommand.sh new file mode 100755 index 00000000..b541ca73 --- /dev/null +++ b/.devcontainer/scripts/onCreateCommand.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -eoux pipefail +DEVCONTAINER_CONFIG_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" + +# Copy a bazelrc to the home dir with some devcontainer specific settings +cp "${DEVCONTAINER_CONFIG_DIR}/home/devcontainer.bazelrc" "/home/vscode/.bazelrc"