From 55670bcc69b642f1b063ac98839e31a099eb439c Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Sat, 12 Dec 2020 20:21:49 +0000 Subject: [PATCH 01/15] Create Dockerfile --- containers/haskell/.devcontainer/Dockerfile | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 containers/haskell/.devcontainer/Dockerfile diff --git a/containers/haskell/.devcontainer/Dockerfile b/containers/haskell/.devcontainer/Dockerfile new file mode 100644 index 0000000000..06d16d4f15 --- /dev/null +++ b/containers/haskell/.devcontainer/Dockerfile @@ -0,0 +1,32 @@ +# Use the [Choice] comment to indicate option arguments that should appear in VS Code UX +# +# [Choice] Haskell version: 8, +ARG VARIANT=8 +FROM haskell:${VARIANT} + +# Use the [Option] comment to specify true/false arguments that should appear in VS Code UX +# +# [Option] Install zsh +ARG INSTALL_ZSH="true" +# [Option] Upgrade OS packages to their latest versions +ARG UPGRADE_PACKAGES="false" + +# 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 +COPY library-scripts/*.sh /tmp/library-scripts/ +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \ + # + # **************************************************************************** + # * TODO: Add any additional OS packages you want included in the definition * + # * here. We want to do this before cleanup to keep the "layer" small. + # **************************************************************************** + # && apt-get -y install --no-install-recommends \ + # + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends From 0713301589028a73533729e1ec065170848bd6a4 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Sat, 12 Dec 2020 20:23:29 +0000 Subject: [PATCH 02/15] Create devcontainer.json --- .../haskell/.devcontainer/devcontainer.json | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 containers/haskell/.devcontainer/devcontainer.json diff --git a/containers/haskell/.devcontainer/devcontainer.json b/containers/haskell/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..926d814163 --- /dev/null +++ b/containers/haskell/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +{ + "name": "Haskell Container Definition - Dockerfile", + + // Update the 'dockerfile' property if you aren't using the standard 'Dockerfile' filename. + "build": { + "dockerfile": "Dockerfile" + }, + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "haskell.haskell" + ], + + // 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": "uname -a", + + // Uncomment to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. + // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], + + // Uncomment when using a ptrace-based debugger like C++, Go, and Rust + // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp-unconfined" ], + + // Comment out connect as root instead. To add a non-root user, see: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} From 0a1ecb3dbc138f5c09f04d6423d12d6bb781dcff Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Sat, 12 Dec 2020 20:24:42 +0000 Subject: [PATCH 03/15] Create common-debian.sh --- .../library-scripts/common-debian.sh | 336 ++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 containers/haskell/.devcontainer/library-scripts/common-debian.sh diff --git a/containers/haskell/.devcontainer/library-scripts/common-debian.sh b/containers/haskell/.devcontainer/library-scripts/common-debian.sh new file mode 100644 index 0000000000..e99d29ab82 --- /dev/null +++ b/containers/haskell/.devcontainer/library-scripts/common-debian.sh @@ -0,0 +1,336 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/common.md +# +# Syntax: ./common-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag] [install Oh My *! flag] + +INSTALL_ZSH=${1:-"true"} +USERNAME=${2:-"automatic"} +USER_UID=${3:-"automatic"} +USER_GID=${4:-"automatic"} +UPGRADE_PACKAGES=${5:-"true"} +INSTALL_OH_MYS=${6:-"true"} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# If in automatic mode, determine if a user already exists, if not use vscode +if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then + USERNAME="" + POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") + for CURRENT_USER in ${POSSIBLE_USERS[@]}; do + if id -u ${CURRENT_USER} > /dev/null 2>&1; then + USERNAME=${CURRENT_USER} + break + fi + done + if [ "${USERNAME}" = "" ]; then + USERNAME=vscode + fi +elif [ "${USERNAME}" = "none" ]; then + USERNAME=root + USER_UID=0 + USER_GID=0 +fi + +# Load markers to see which steps have already run +MARKER_FILE="/usr/local/etc/vscode-dev-containers/common" +if [ -f "${MARKER_FILE}" ]; then + echo "Marker file found:" + cat "${MARKER_FILE}" + source "${MARKER_FILE}" +fi + +# Ensure apt is in non-interactive to avoid prompts +export DEBIAN_FRONTEND=noninteractive + +# Function to call apt-get if needed +apt-get-update-if-needed() +{ + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update + else + echo "Skipping apt-get update." + fi +} + +# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies +if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then + apt-get-update-if-needed + + PACKAGE_LIST="apt-utils \ + git \ + openssh-client \ + gnupg2 \ + iproute2 \ + procps \ + lsof \ + htop \ + net-tools \ + psmisc \ + curl \ + wget \ + rsync \ + ca-certificates \ + unzip \ + zip \ + nano \ + vim-tiny \ + less \ + jq \ + lsb-release \ + apt-transport-https \ + dialog \ + libc6 \ + libgcc1 \ + libkrb5-3 \ + libgssapi-krb5-2 \ + libicu[0-9][0-9] \ + liblttng-ust0 \ + libstdc++6 \ + zlib1g \ + locales \ + sudo \ + ncdu \ + man-db \ + strace" + + # Install libssl1.1 if available + if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then + PACKAGE_LIST="${PACKAGE_LIST} libssl1.1" + fi + + # Install appropriate version of libssl1.0.x if available + LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') + if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then + if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then + # Debian 9 + PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.2" + elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then + # Ubuntu 18.04, 16.04, earlier + PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.0" + fi + fi + + echo "Packages to verify are installed: ${PACKAGE_LIST}" + apt-get -y install --no-install-recommends ${PACKAGE_LIST} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 ) + + PACKAGES_ALREADY_INSTALLED="true" +fi + +# Get to latest versions of all packages +if [ "${UPGRADE_PACKAGES}" = "true" ]; then + apt-get-update-if-needed + apt-get -y upgrade --no-install-recommends + apt-get autoremove -y +fi + +# Ensure at least the en_US.UTF-8 UTF-8 locale is available. +# Common need for both applications and things like the agnoster ZSH theme. +if [ "${LOCALE_ALREADY_SET}" != "true" ] && ! grep -o -E '^\s*en_US.UTF-8\s+UTF-8' /etc/locale.gen > /dev/null; then + echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen + locale-gen + LOCALE_ALREADY_SET="true" +fi + +# Create or update a non-root user to match UID/GID. +if id -u ${USERNAME} > /dev/null 2>&1; then + # User exists, update if needed + if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then + groupmod --gid $USER_GID $USERNAME + usermod --gid $USER_GID $USERNAME + fi + if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then + usermod --uid $USER_UID $USERNAME + fi +else + # Create user + if [ "${USER_GID}" = "automatic" ]; then + groupadd $USERNAME + else + groupadd --gid $USER_GID $USERNAME + fi + if [ "${USER_UID}" = "automatic" ]; then + useradd -s /bin/bash --gid $USERNAME -m $USERNAME + else + useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME + fi +fi + +# Add add sudo support for non-root user +if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then + echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME + chmod 0440 /etc/sudoers.d/$USERNAME + EXISTING_NON_ROOT_USER="${USERNAME}" +fi + +# ** Shell customization section ** +if [ "${USERNAME}" = "root" ]; then + USER_RC_PATH="/root" +else + USER_RC_PATH="/home/${USERNAME}" +fi + +# .bashrc/.zshrc snippet +RC_SNIPPET="$(cat << EOF +export USER=\$(whoami) + +export PATH=\$PATH:\$HOME/.local/bin +EOF +)" + +# code shim, it fallbacks to code-insiders if code is not available +cat << 'EOF' > /usr/local/bin/code +#!/bin/sh + +get_in_path_except_current() { + which -a "$1" | grep -v "$0" | head -1 +} + +code="$(get_in_path_except_current code)" + +if [ -n "$code" ]; then + exec "$code" "$@" +elif [ "$(command -v code-insiders)" ]; then + exec code-insiders "$@" +else + echo "code or code-insiders is not installed" >&2 + exit 127 +fi +EOF +chmod +x /usr/local/bin/code + +# Codespaces themes - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme +CODESPACES_BASH="$(cat \ +<&1 + echo -e "$(cat "${TEMPLATE}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${USER_RC_FILE} + if [ "${OH_MY}" = "bash" ]; then + sed -i -e 's/OSH_THEME=.*/OSH_THEME="codespaces"/g' ${USER_RC_FILE} + mkdir -p ${OH_MY_INSTALL_DIR}/custom/themes/codespaces + echo "${CODESPACES_BASH}" > ${OH_MY_INSTALL_DIR}/custom/themes/codespaces/codespaces.theme.sh + else + sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="codespaces"/g' ${USER_RC_FILE} + mkdir -p ${OH_MY_INSTALL_DIR}/custom/themes + echo "${CODESPACES_ZSH}" > ${OH_MY_INSTALL_DIR}/custom/themes/codespaces.zsh-theme + fi + # Shrink git while still enabling updates + cd ${OH_MY_INSTALL_DIR} + git repack -a -d -f --depth=1 --window=1 + + if [ "${USERNAME}" != "root" ]; then + cp -rf ${USER_RC_FILE} ${OH_MY_INSTALL_DIR} /root + chown -R ${USERNAME}:${USERNAME} ${USER_RC_PATH} + fi +} + +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" >> /etc/bash.bashrc + RC_SNIPPET_ALREADY_ADDED="true" +fi +install-oh-my bash bashrc.osh-template https://github.com/ohmybash/oh-my-bash + +# Optionally install and configure zsh and Oh My Zsh! +if [ "${INSTALL_ZSH}" = "true" ]; then + if ! type zsh > /dev/null 2>&1; then + apt-get-update-if-needed + apt-get install -y zsh + fi + if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then + echo "${RC_SNIPPET}" >> /etc/zsh/zshrc + ZSH_ALREADY_INSTALLED="true" + fi + install-oh-my zsh zshrc.zsh-template https://github.com/ohmyzsh/ohmyzsh +fi + +# Write marker file +mkdir -p "$(dirname "${MARKER_FILE}")" +echo -e "\ + PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ + LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ + EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ + RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ + ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + +echo "Done!" From 18e3e8bff49f8cdce341fb8500b28b207bb0a9ef Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 13:03:04 +0100 Subject: [PATCH 04/15] Update Haskell version choice Listing 9, 8 Co-authored-by: Chuck Lantz --- containers/haskell/.devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/haskell/.devcontainer/Dockerfile b/containers/haskell/.devcontainer/Dockerfile index 06d16d4f15..098a79284a 100644 --- a/containers/haskell/.devcontainer/Dockerfile +++ b/containers/haskell/.devcontainer/Dockerfile @@ -1,6 +1,6 @@ # Use the [Choice] comment to indicate option arguments that should appear in VS Code UX # -# [Choice] Haskell version: 8, +# [Choice] Haskell version: 9, 8 ARG VARIANT=8 FROM haskell:${VARIANT} From b65f9a407856f1ef1c3542e53aaee5c751bf9e96 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 13:05:18 +0100 Subject: [PATCH 05/15] Remove TODO template information Remove TODO template information demonstration where to add additional OS packages. Co-authored-by: Chuck Lantz --- containers/haskell/.devcontainer/Dockerfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/containers/haskell/.devcontainer/Dockerfile b/containers/haskell/.devcontainer/Dockerfile index 098a79284a..9a2beebd3b 100644 --- a/containers/haskell/.devcontainer/Dockerfile +++ b/containers/haskell/.devcontainer/Dockerfile @@ -18,13 +18,6 @@ ARG USER_GID=$USER_UID COPY library-scripts/*.sh /tmp/library-scripts/ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \ - # - # **************************************************************************** - # * TODO: Add any additional OS packages you want included in the definition * - # * here. We want to do this before cleanup to keep the "layer" small. - # **************************************************************************** - # && apt-get -y install --no-install-recommends \ - # && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts # [Optional] Uncomment this section to install additional OS packages. From 033abf7845b38375dc5166e47501ec7b00ba5ff8 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 13:06:22 +0100 Subject: [PATCH 06/15] Change container definition name Reflect community created. Co-authored-by: Chuck Lantz --- containers/haskell/.devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/haskell/.devcontainer/devcontainer.json b/containers/haskell/.devcontainer/devcontainer.json index 926d814163..26d00a11bc 100644 --- a/containers/haskell/.devcontainer/devcontainer.json +++ b/containers/haskell/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "Haskell Container Definition - Dockerfile", + "name": "Haskell (Community)", // Update the 'dockerfile' property if you aren't using the standard 'Dockerfile' filename. "build": { From 76347a57806c0f402273a58f0ca101de83f3bb3f Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 13:08:25 +0100 Subject: [PATCH 07/15] Remove unused Docker and ptrace infomation Removed commented code demonstrating how to use Docker inside container and ptrace-based debugger. Co-authored-by: Chuck Lantz --- containers/haskell/.devcontainer/devcontainer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/containers/haskell/.devcontainer/devcontainer.json b/containers/haskell/.devcontainer/devcontainer.json index 26d00a11bc..120a6bcaf4 100644 --- a/containers/haskell/.devcontainer/devcontainer.json +++ b/containers/haskell/.devcontainer/devcontainer.json @@ -22,11 +22,6 @@ // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "uname -a", - // Uncomment to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. - // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], - - // Uncomment when using a ptrace-based debugger like C++, Go, and Rust - // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp-unconfined" ], // Comment out connect as root instead. To add a non-root user, see: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" From 3f821a235abfb32767b0f0d3d407332d32e41dc6 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 13:41:46 +0100 Subject: [PATCH 08/15] Add README.md Add README to definition --- containers/haskell/README.md | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 containers/haskell/README.md diff --git a/containers/haskell/README.md b/containers/haskell/README.md new file mode 100644 index 0000000000..bd08a5fba1 --- /dev/null +++ b/containers/haskell/README.md @@ -0,0 +1,48 @@ +# Haskell (Community) + +## Summary + +[Haskell](https://www.haskell.org/) is an advanced, purely functional programming language + +This definition will hopefully get you going quickly with Haskell running as a remote container in vscode. + +| Metadata | Value | +|---------------------------- | -----------------------------------------------------------------------------| +| *Contributors* | [Stuart Pike](https://github.com/stuartpike) | +| *Categories* | Community, Haskell | +| *Definition type* | Dockerfile | +| *Works in Codespaces* | Yes | +| *Container host OS support* | Linux, macOS, Windows | +| *Container OS* | Debian | +| *Languages, platforms* | Haskell | + + +## Using this definition + +While the definition itself works unmodified, you can select the version of Haskell the container uses by updating the `VARIANT` arg in the included `.devcontainer/devcontainer.json` file. + +```json +# [Choice] Haskell version: 9, 8 +ARG VARIANT=8 +``` + +### Adding the definition to a project or codespace + +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**. + + > **Note:** If needed, you can drag-and-drop the `.devcontainer` folder from this sub-folder in a locally cloned copy of this repository into the VS Code file explorer instead of using the command. + +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. + + +## License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/main/LICENSE). From 7b0436d04e141ec9a2126d57c95c474681563806 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 14:49:10 +0100 Subject: [PATCH 09/15] Remove deprecated settings item --- containers/haskell/.devcontainer/devcontainer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/containers/haskell/.devcontainer/devcontainer.json b/containers/haskell/.devcontainer/devcontainer.json index 120a6bcaf4..d708fe1dca 100644 --- a/containers/haskell/.devcontainer/devcontainer.json +++ b/containers/haskell/.devcontainer/devcontainer.json @@ -7,9 +7,7 @@ }, // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" - }, + "settings": {}, // Add the IDs of extensions you want installed when the container is created. "extensions": [ From ac382a1e0a34c17c9f510e2ea46afc374251a7ba Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 14:52:33 +0100 Subject: [PATCH 10/15] Update to use updated common-debian.sh file. --- containers/haskell/.devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/haskell/.devcontainer/Dockerfile b/containers/haskell/.devcontainer/Dockerfile index 9a2beebd3b..b5d7dc4bf0 100644 --- a/containers/haskell/.devcontainer/Dockerfile +++ b/containers/haskell/.devcontainer/Dockerfile @@ -17,7 +17,7 @@ ARG USER_UID=1000 ARG USER_GID=$USER_UID COPY library-scripts/*.sh /tmp/library-scripts/ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \ + && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true"\ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts # [Optional] Uncomment this section to install additional OS packages. From 93ba5b33150586ddddbc8f08e2c969e418021a38 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 14:54:03 +0100 Subject: [PATCH 11/15] Update common-debian.sh Use updated common-debian.sh file --- .../library-scripts/common-debian.sh | 333 ++++++++++++------ 1 file changed, 235 insertions(+), 98 deletions(-) diff --git a/containers/haskell/.devcontainer/library-scripts/common-debian.sh b/containers/haskell/.devcontainer/library-scripts/common-debian.sh index e99d29ab82..80d8af6a00 100644 --- a/containers/haskell/.devcontainer/library-scripts/common-debian.sh +++ b/containers/haskell/.devcontainer/library-scripts/common-debian.sh @@ -4,9 +4,12 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- # -# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/common.md +# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/common.md +# Maintainer: The VS Code and Codespaces Teams # -# Syntax: ./common-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag] [install Oh My *! flag] +# Syntax: ./common-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag] [install Oh My Zsh! flag] [Add non-free packages] + +set -e INSTALL_ZSH=${1:-"true"} USERNAME=${2:-"automatic"} @@ -14,14 +17,19 @@ USER_UID=${3:-"automatic"} USER_GID=${4:-"automatic"} UPGRADE_PACKAGES=${5:-"true"} INSTALL_OH_MYS=${6:-"true"} - -set -e +ADD_NON_FREE_PACKAGES=${7:-"false"} +SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)" if [ "$(id -u)" -ne 0 ]; then echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' exit 1 fi +# Ensure that login shells get the correct path if the user updated the PATH using ENV. +rm -f /etc/profile.d/00-restore-env.sh +echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh +chmod +x /etc/profile.d/00-restore-env.sh + # If in automatic mode, determine if a user already exists, if not use vscode if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then USERNAME="" @@ -65,7 +73,6 @@ apt-get-update-if-needed() # Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then - apt-get-update-if-needed PACKAGE_LIST="apt-utils \ git \ @@ -102,7 +109,28 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then sudo \ ncdu \ man-db \ - strace" + strace \ + manpages \ + manpages-dev \ + init-system-helpers" + + # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian + if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then + CODENAME="$(cat /etc/os-release | grep -oE '^VERSION_CODENAME=.+$' | cut -d'=' -f2)" + sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${CODENAME} main contrib non-free/" /etc/apt/sources.list + sed -i -E "s/deb-src http:\/\/(deb|httredir)\.debian\.org\/debian ${CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${CODENAME} main contrib non-free/" /etc/apt/sources.list + sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${CODENAME}-updates main contrib non-free/" /etc/apt/sources.list + sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${CODENAME}-updates main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${CODENAME}-backports main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${CODENAME}-backports main contrib non-free/" /etc/apt/sources.list + echo "Running apt-get update..." + apt-get update + PACKAGE_LIST="${PACKAGE_LIST} manpages-posix manpages-posix-dev" + else + apt-get-update-if-needed + fi # Install libssl1.1 if available if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then @@ -180,11 +208,43 @@ else USER_RC_PATH="/home/${USERNAME}" fi +# Restore user .bashrc defaults from skeleton file if it doesn't exist or is empty +if [ ! -f "${USER_RC_PATH}/.bashrc" ] || [ ! -s "${USER_RC_PATH}/.bashrc" ] ; then + cp /etc/skel/.bashrc "${USER_RC_PATH}/.bashrc" +fi + +# Restore user .profile defaults from skeleton file if it doesn't exist or is empty +if [ ! -f "${USER_RC_PATH}/.profile" ] || [ ! -s "${USER_RC_PATH}/.profile" ] ; then + cp /etc/skel/.profile "${USER_RC_PATH}/.profile" +fi + # .bashrc/.zshrc snippet -RC_SNIPPET="$(cat << EOF -export USER=\$(whoami) +RC_SNIPPET="$(cat << 'EOF' + +if [ -z "${USER}" ]; then export USER=$(whoami); fi +if [[ "${PATH}" != *"$HOME/.local/bin"* ]]; then export PATH="${PATH}:$HOME/.local/bin"; fi + +# Display optional first run image specific notice if configured and terminal is interactive +if [ -t 1 ] && [[ "${TERM_PROGRAM}" = "vscode" || "${TERM_PROGRAM}" = "codespaces" ]] && [ ! -f "$HOME/.config/vscode-dev-containers/first-run-notice-already-displayed" ]; then + if [ -f "/usr/local/etc/vscode-dev-containers/first-run-notice.txt" ]; then + cat "/usr/local/etc/vscode-dev-containers/first-run-notice.txt" + elif [ -f "/workspaces/.codespaces/shared/first-run-notice.txt" ]; then + cat "/workspaces/.codespaces/shared/first-run-notice.txt" + fi + mkdir -p "$HOME/.config/vscode-dev-containers" + # Mark first run notice as displayed after 10s to avoid problems with fast terminal refreshes hiding it + ((sleep 10s; touch "$HOME/.config/vscode-dev-containers/first-run-notice-already-displayed") &) +fi + +# Set the default git editor +if [ "${TERM_PROGRAM}" = "vscode" ]; then + if [[ -n $(command -v code-insiders) && -z $(command -v code) ]]; then + export GIT_EDITOR="code-insiders --wait" + else + export GIT_EDITOR="code --wait" + fi +fi -export PATH=\$PATH:\$HOME/.local/bin EOF )" @@ -193,123 +253,133 @@ cat << 'EOF' > /usr/local/bin/code #!/bin/sh get_in_path_except_current() { - which -a "$1" | grep -v "$0" | head -1 + which -a "$1" | grep -A1 "$0" | grep -v "$0" } code="$(get_in_path_except_current code)" if [ -n "$code" ]; then - exec "$code" "$@" + exec "$code" "$@" elif [ "$(command -v code-insiders)" ]; then - exec code-insiders "$@" + exec code-insiders "$@" else - echo "code or code-insiders is not installed" >&2 - exit 127 + echo "code or code-insiders is not installed" >&2 + exit 127 fi EOF chmod +x /usr/local/bin/code -# Codespaces themes - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme +# systemctl shim - tells people to use 'service' if systemd is not running +cat << 'EOF' > /usr/local/bin/systemctl +#!/bin/sh +set -e +if [ -d "/run/systemd/system" ]; then + exec /bin/systemctl/systemctl "$@" +else + echo '\n"systemd" is not running in this container due to its overhead.\nUse the "service" command to start services intead. e.g.: \n\nservice --status-all' +fi +EOF +chmod +x /usr/local/bin/systemctl + +# Codespaces bash and OMZ themes - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme CODESPACES_BASH="$(cat \ -<&1 - echo -e "$(cat "${TEMPLATE}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${USER_RC_FILE} - if [ "${OH_MY}" = "bash" ]; then - sed -i -e 's/OSH_THEME=.*/OSH_THEME="codespaces"/g' ${USER_RC_FILE} - mkdir -p ${OH_MY_INSTALL_DIR}/custom/themes/codespaces - echo "${CODESPACES_BASH}" > ${OH_MY_INSTALL_DIR}/custom/themes/codespaces/codespaces.theme.sh - else - sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="codespaces"/g' ${USER_RC_FILE} - mkdir -p ${OH_MY_INSTALL_DIR}/custom/themes - echo "${CODESPACES_ZSH}" > ${OH_MY_INSTALL_DIR}/custom/themes/codespaces.zsh-theme +# Add RC snippet and custom bash prompt +if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + echo "${RC_SNIPPET}" >> /etc/bash.bashrc + echo "${CODESPACES_BASH}" >> "${USER_RC_PATH}/.bashrc" + echo 'export PROMPT_DIRTRIM=4' >> "${USER_RC_PATH}/.bashrc" + if [ "${USERNAME}" != "root" ]; then + echo "${CODESPACES_BASH}" >> "/root/.bashrc" + echo 'export PROMPT_DIRTRIM=4' >> "/root/.bashrc" fi - # Shrink git while still enabling updates - cd ${OH_MY_INSTALL_DIR} - git repack -a -d -f --depth=1 --window=1 + chown ${USERNAME}:${USERNAME} "${USER_RC_PATH}/.bashrc" + RC_SNIPPET_ALREADY_ADDED="true" +fi +# Add stub for Oh My Bash! +if [ ! -d "${USER_RC_PATH}/.oh-my-bash}" ] && [ "${INSTALL_OH_MYS}" = "true" ]; then + mkdir -p "${USER_RC_PATH}/.oh-my-bash" "/root/.oh-my-bash" + echo "${OMB_README}" >> "${USER_RC_PATH}/.oh-my-bash/README.md" + echo "${OMB_STUB}" >> "${USER_RC_PATH}/.oh-my-bash/oh-my-bash.sh" + chmod +x "${USER_RC_PATH}/.oh-my-bash/oh-my-bash.sh" if [ "${USERNAME}" != "root" ]; then - cp -rf ${USER_RC_FILE} ${OH_MY_INSTALL_DIR} /root - chown -R ${USERNAME}:${USERNAME} ${USER_RC_PATH} + echo "${OMB_README}" >> "/root/.oh-my-bash/README.md" + echo "${OMB_STUB}" >> "/root/.oh-my-bash/oh-my-bash.sh" + chmod +x "/root/.oh-my-bash/oh-my-bash.sh" fi -} - -if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then - echo "${RC_SNIPPET}" >> /etc/bash.bashrc - RC_SNIPPET_ALREADY_ADDED="true" + chown -R "${USERNAME}:${USERNAME}" "${USER_RC_PATH}/.oh-my-bash" fi -install-oh-my bash bashrc.osh-template https://github.com/ohmybash/oh-my-bash # Optionally install and configure zsh and Oh My Zsh! if [ "${INSTALL_ZSH}" = "true" ]; then @@ -321,7 +391,74 @@ if [ "${INSTALL_ZSH}" = "true" ]; then echo "${RC_SNIPPET}" >> /etc/zsh/zshrc ZSH_ALREADY_INSTALLED="true" fi - install-oh-my zsh zshrc.zsh-template https://github.com/ohmyzsh/ohmyzsh + + # Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. + # See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script. + OH_MY_INSTALL_DIR="${USER_RC_PATH}/.oh-my-zsh" + if [ ! -d "${OH_MY_INSTALL_DIR}" ] && [ "${INSTALL_OH_MYS}" = "true" ]; then + TEMPLATE_PATH="${OH_MY_INSTALL_DIR}/templates/zshrc.zsh-template" + USER_RC_FILE="${USER_RC_PATH}/.zshrc" + umask g-w,o-w + mkdir -p ${OH_MY_INSTALL_DIR} + git clone --depth=1 \ + -c core.eol=lf \ + -c core.autocrlf=false \ + -c fsck.zeroPaddedFilemode=ignore \ + -c fetch.fsck.zeroPaddedFilemode=ignore \ + -c receive.fsck.zeroPaddedFilemode=ignore \ + "https://github.com/ohmyzsh/ohmyzsh" "${OH_MY_INSTALL_DIR}" 2>&1 + echo -e "$(cat "${TEMPLATE_PATH}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${USER_RC_FILE} + sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="codespaces"/g' ${USER_RC_FILE} + + mkdir -p ${OH_MY_INSTALL_DIR}/custom/themes + echo "${CODESPACES_ZSH}" > "${OH_MY_INSTALL_DIR}/custom/themes/codespaces.zsh-theme" + # Shrink git while still enabling updates + cd "${OH_MY_INSTALL_DIR}" + git repack -a -d -f --depth=1 --window=1 + # Copy to non-root user if one is specified + if [ "${USERNAME}" != "root" ]; then + cp -rf "${USER_RC_FILE}" "${OH_MY_INSTALL_DIR}" /root + chown -R ${USERNAME}:${USERNAME} "${USER_RC_PATH}" + fi + fi +fi + +# Persist image metadata info, script if meta.env found in same directory +META_INFO_SCRIPT="$(cat << 'EOF' +#!/bin/sh +. /usr/local/etc/vscode-dev-containers/meta.env + +# Minimal output +if [ "$1" = "version" ] || [ "$1" = "image-version" ]; then + echo "${VERSION}" + exit 0 +elif [ "$1" = "release" ]; then + echo "${GIT_REPOSITORY_RELEASE}" + exit 0 +elif [ "$1" = "content" ] || [ "$1" = "content-url" ] || [ "$1" = "contents" ] || [ "$1" = "contents-url" ]; then + echo "${CONTENTS_URL}" + exit 0 +fi + +#Full output +echo +echo "Development container image information" +echo +if [ ! -z "${VERSION}" ]; then echo "- Image version: ${VERSION}"; fi +if [ ! -z "${DEFINITION_ID}" ]; then echo "- Definition ID: ${DEFINITION_ID}"; fi +if [ ! -z "${VARIANT}" ]; then echo "- Variant: ${VARIANT}"; fi +if [ ! -z "${GIT_REPOSITORY}" ]; then echo "- Source code repository: ${GIT_REPOSITORY}"; fi +if [ ! -z "${GIT_REPOSITORY_RELEASE}" ]; then echo "- Source code release/branch: ${GIT_REPOSITORY_RELEASE}"; fi +if [ ! -z "${BUILD_TIMESTAMP}" ]; then echo "- Timestamp: ${BUILD_TIMESTAMP}"; fi +if [ ! -z "${CONTENTS_URL}" ]; then echo && echo "More info: ${CONTENTS_URL}"; fi +echo +EOF +)" +if [ -f "${SCRIPT_DIR}/meta.env" ]; then + mkdir -p /usr/local/etc/vscode-dev-containers/ + cp -f "${SCRIPT_DIR}/meta.env" /usr/local/etc/vscode-dev-containers/meta.env + echo "${META_INFO_SCRIPT}" > /usr/local/bin/devcontainer-info + chmod +x /usr/local/bin/devcontainer-info fi # Write marker file From b9c749d515ba213dcfa6235ee66d2e030963a861 Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 14:57:53 +0100 Subject: [PATCH 12/15] Update README.md Add contributor --- containers/haskell/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/containers/haskell/README.md b/containers/haskell/README.md index bd08a5fba1..37c74d4b64 100644 --- a/containers/haskell/README.md +++ b/containers/haskell/README.md @@ -8,13 +8,13 @@ This definition will hopefully get you going quickly with Haskell running as a r | Metadata | Value | |---------------------------- | -----------------------------------------------------------------------------| -| *Contributors* | [Stuart Pike](https://github.com/stuartpike) | +| *Contributors* | [Stuart Pike](https://github.com/stuartpike), [eitsupi](https://github.com/eitsupi) | | *Categories* | Community, Haskell | -| *Definition type* | Dockerfile | -| *Works in Codespaces* | Yes | -| *Container host OS support* | Linux, macOS, Windows | -| *Container OS* | Debian | -| *Languages, platforms* | Haskell | +| *Definition type* | Dockerfile | +| *Works in Codespaces* | Yes | +| *Container host OS support* | Linux, macOS, Windows | +| *Container OS* | Debian | +| *Languages, platforms* | Haskell | ## Using this definition From 48ed211a56c278af00860687f30ea0af9963c52b Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 15:04:44 +0100 Subject: [PATCH 13/15] Update README.md Added contributors --- containers/haskell/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/haskell/README.md b/containers/haskell/README.md index 37c74d4b64..592ef861ee 100644 --- a/containers/haskell/README.md +++ b/containers/haskell/README.md @@ -8,7 +8,7 @@ This definition will hopefully get you going quickly with Haskell running as a r | Metadata | Value | |---------------------------- | -----------------------------------------------------------------------------| -| *Contributors* | [Stuart Pike](https://github.com/stuartpike), [eitsupi](https://github.com/eitsupi) | +| *Contributors* | [Stuart Pike](https://github.com/stuartpike), [Chuck Lantz](https://github.com/Chuxel), [Javier Neira](https://github.com/Chuxel), [eitsupi](https://github.com/eitsupi) | | *Categories* | Community, Haskell | | *Definition type* | Dockerfile | | *Works in Codespaces* | Yes | From da670ab8c1b3d0a1e0eab9d946a093847f9f4b5a Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 16:10:05 +0100 Subject: [PATCH 14/15] Update code snippet Show where to set Haskell version utilizing choice option. Co-authored-by: Chuck Lantz --- containers/haskell/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/containers/haskell/README.md b/containers/haskell/README.md index 592ef861ee..17551a717f 100644 --- a/containers/haskell/README.md +++ b/containers/haskell/README.md @@ -22,8 +22,12 @@ This definition will hopefully get you going quickly with Haskell running as a r While the definition itself works unmodified, you can select the version of Haskell the container uses by updating the `VARIANT` arg in the included `.devcontainer/devcontainer.json` file. ```json -# [Choice] Haskell version: 9, 8 -ARG VARIANT=8 +"build": { + "dockerfile": "Dockerfile", + "args": { + "VARIANT": "9" + } +} ``` ### Adding the definition to a project or codespace From 2b1b1ecffb38a62a1670e9ab96d791c18da2336e Mon Sep 17 00:00:00 2001 From: Stuart Pike Date: Wed, 30 Jun 2021 16:13:18 +0100 Subject: [PATCH 15/15] Update devcontainer.json Add build.args property --- containers/haskell/.devcontainer/devcontainer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/containers/haskell/.devcontainer/devcontainer.json b/containers/haskell/.devcontainer/devcontainer.json index d708fe1dca..f761047ae4 100644 --- a/containers/haskell/.devcontainer/devcontainer.json +++ b/containers/haskell/.devcontainer/devcontainer.json @@ -3,7 +3,11 @@ // Update the 'dockerfile' property if you aren't using the standard 'Dockerfile' filename. "build": { - "dockerfile": "Dockerfile" + "dockerfile": "Dockerfile", + "args": { + // Update 'VARIANT' to pick a Haskell version: 9, 8 + "VARIANT": "8" + } }, // Set *default* container specific settings.json values on container create.