From eb0134b3486e21014e926c43ba8cd3823c340c12 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Wed, 3 May 2023 23:24:18 +0000 Subject: [PATCH] fix(vscode/devcontainer): unexpected exit stdout /etc/passwd 1. Moved away from trying to handroll an Ubuntu-22.04 image for the dev container and instead used the "features" feature (no pun intended) of the dev container spec: https://code.visualstudio.com/blogs/2022/09/15/dev-container-features 2. This produces a container that builds and launches reliably without the issues the previous version was suffering from (which was that to some people the container would just exit randomly during the launch) 3. Our future goal of having the dev container being built in a reproducible way is still not achieved, but we've gotten closer because in the meantime while working on this issue it was discovered that we can re-build the images directly from the CLI by using the dev container CLI package: https://github.com/devcontainers/cli 4. The upside of not building the image from scratch is that we can count on future improvements/maintenance from others who are working on these images. 5. The downside of not building the image from scratch is that if we end up finding something that does not work due to the customizations, it might be more difficult to figure that out compared to if we had just build our own. 6. It is hard to predcit right now whether 4) or 5) will end up being having the stronger effect, but we can cross that bridge when we get to it. 7. In the meantime I've started working on a contribution to the dev container CLI itself for a dockerfile ejection feature (meaning that we'll be able to render a single Dockerfile for the dev container (that right now the CLI only stores/uses internally in it's own code at runtime). This eject feature will be good for debugging purposes in case anything goes wrong with the image in the future. 8. Also added a publishing workflow action that will build the dev container image on the main branch when there is a release tag (v*) issued. Fixes #2404 Signed-off-by: Peter Somogyvari --- .devcontainer/Dockerfile | 87 ---- .devcontainer/README.md | 42 -- .devcontainer/devcontainer.json | 94 +++-- .../library-scripts/common-debian.sh | 395 ------------------ .../docker-in-docker-debian.sh | 186 --------- .devcontainer/post-create-commands.sh | 13 - .../cacti-dev-container-vscode-publish.yaml | 64 +++ .github/workflows/ci.yaml | 12 +- 8 files changed, 138 insertions(+), 755 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/README.md delete mode 100644 .devcontainer/library-scripts/common-debian.sh delete mode 100644 .devcontainer/library-scripts/docker-in-docker-debian.sh delete mode 100755 .devcontainer/post-create-commands.sh create mode 100644 .github/workflows/cacti-dev-container-vscode-publish.yaml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 4b5cf9a85c..0000000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,87 +0,0 @@ -# Note: You can use any Debian/Ubuntu based image you want. -FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-20.04 - -# [Option] Install zsh -ARG INSTALL_ZSH="true" -# [Option] Upgrade OS packages to their latest versions -ARG UPGRADE_PACKAGES="false" -# [Option] Enable non-root Docker access in container -ARG ENABLE_NONROOT_DOCKER="true" -# [Option] Use the OSS Moby Engine instead of the licensed Docker Engine -ARG USE_MOBY="true" - -# Install needed packages and setup non-root user. Use a separate RUN statement to add your -# own dependencies. A user of "automatic" attempts to reuse an user ID if one already exists. -ARG USERNAME=automatic -ARG USER_UID=1000 -ARG USER_GID=$USER_UID -COPY library-scripts/*.sh /tmp/library-scripts/ -RUN apt-get update \ - && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \ - # Use Docker script from script library to set things up - && /bin/bash /tmp/library-scripts/docker-in-docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "${USERNAME}" "${USE_MOBY}" \ - # Clean up - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/ - -# Install software properties -RUN apt-get update \ - && apt-get install software-properties-common -y - -# Install pip3 -RUN apt-get update \ - && apt-get install python3-pip -y - -# Install GVM (Go Version Manager) dependencies -RUN apt-get update \ - && apt-get -y install curl git mercurial make binutils bison gcc build-essential - -# Install Indy-SDK -# Add Sovrin repository (only bionic release available, but works in recent ubuntu as well) -RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88 \ - && add-apt-repository "deb https://repo.sovrin.org/sdk/deb bionic stable" \ - # Install Indy SDK - && apt-get update \ - && apt-get install -y \ - libindy \ - libnullpay \ - libvcx \ - indy-cli \ - # Remove auto repo entry for focal release (use one from /etc/apt/sources.list) - && rm -f /etc/apt/sources.list.d/sovrin.list* \ - # Clean up - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/ - -VOLUME [ "/var/lib/docker" ] - -# Setting the ENTRYPOINT to docker-init.sh will start up the Docker Engine -# inside the container "overrideCommand": false is set in devcontainer.json. -# The script will also execute CMD if you need to alter startup behaviors. -ENTRYPOINT [ "/usr/local/share/docker-init.sh" ] -CMD [ "sleep", "infinity" ] - -# [Optional] Uncomment this section to install additional OS packages. -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends openjdk-11-jdk cmake - -COPY post-create-commands.sh /home/vscode/bin/ - -USER vscode -SHELL ["/bin/bash", "--login", "-i", "-c"] - -# Install GVM (Go Version Manager) -RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/1.0.22/binscripts/gvm-installer)"] -RUN source /home/vscode/.gvm/scripts/gvm - -# Install Go -RUN gvm install go1.16.5 -B -RUN gvm use go1.16.5 --default - -# Installing Node Version Manager (nvm) -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash -RUN source /home/vscode/.bashrc && nvm install 16.14.2 - -# Install Rust toolchain (rustup, rustc, cargo, etc.) -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --verbose --default-toolchain=1.57.0 - -SHELL ["/bin/bash", "--login", "-c"] -USER root \ No newline at end of file diff --git a/.devcontainer/README.md b/.devcontainer/README.md deleted file mode 100644 index 7fe70a5774..0000000000 --- a/.devcontainer/README.md +++ /dev/null @@ -1,42 +0,0 @@ - -- [Summary](#summary) -- [Prerequisites](#prerequisites) - - [Windows](#windows) - - [Linux](#linux) -- [Usage](#usage) - -## Summary - -The .devcontainer utilises a Dockerfile and devcontainer.json to create a docker container within Visual Studio Code that comes prebuilt with all dependancies needed to start contributing to Hyperledger Cactus. - -## Prerequisites - -Detailed below are the prerequisites for Windows and Linux - -### Windows - -1. Visual Studio Code -2. Docker Desktop 2.0+ (Windows 10 Pro/Enterprise) or Docker Desktop 2.3+ and the [WSL 2 back-end](https://docs.docker.com/docker-for-windows/wsl/)(Wndows 10 Home) - -For more guidance please see [developing inside a container](https://code.visualstudio.com/docs/remote/containers) - -### Linux - -1. Visual Studio Code -2. Follow the [official install instructions for Docker CE/EE for your distribution](https://docs.docker.com/get-docker/). If you are using Docker Compose, follow the [Docker Compose directions](https://docs.docker.com/compose/install/) as well. -3. Add your user to the docker group - sudo usermod -aG docker $USER -4. Sign out and back in - -For more guidance please see [developing inside a container](https://code.visualstudio.com/docs/remote/containers) - -## Usage - -1. Install the "Remote - Containers" VSC [extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) -2. Clone the repo -3. In VSC click the two green arrows at the bottom left -4. Click "Remote Containers: Open Folder In Container" -5. Navigate to repo and open at a root level - -You should see a pop up at the bottom right stating the container is starting. Once the container is ready you will see the repo opened, you should now be ready to start contributing to Hyperledger Cactus. - -Note - The first time you initiate the container it may take a while to complete. All other loads from then should be much faster. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 502017e622..d53894abf1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,39 +1,73 @@ -// 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.166.1/containers/docker-in-docker +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu { - "name": "Ubuntu 20.04 - Docker in Docker", - "dockerFile": "Dockerfile", - "runArgs": ["--init", "--privileged"], - "overrideCommand": false, + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy", + "runArgs": ["--network=host"], + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { + "moby": true, + "installDockerBuildx": true, + "version": "20.10.24", + "dockerDashComposeVersion": "v2" + }, + "ghcr.io/devcontainers/features/git:1": { + "ppa": true, + "version": "2.40.1" + }, + "ghcr.io/devcontainers/features/go:1": { + "version": "1.20.4" + }, + "ghcr.io/devcontainers/features/java:1": { + "installGradle": true, + "installMaven": false, + "installAnt": false, + "version": "11.0.12-open", + "jdkDistro": "open", + "gradleVersion": "7.5.1", + "mavenVersion": "3.8.6", + "antVersion": "1.10.12" + }, + "ghcr.io/devcontainers/features/node:1": { + "nodeGypDependencies": true, + "version": "18.16.0" + }, + "ghcr.io/devcontainers/features/rust:1": { + "version": "1.63", + "profile": "complete" + }, + "ghcr.io/devcontainers-contrib/features/actions-runner:1": { + "version": "latest", + "dotnetVersion": "latest" + }, + "ghcr.io/devcontainers-contrib/features/curl-apt-get:1": {}, + "ghcr.io/devcontainers-contrib/features/dive:1": { + "version": "v0.10.0" + }, + "ghcr.io/devcontainers-contrib/features/gitmux:1": { + "version": "v0.10.2" + }, + "ghcr.io/devcontainers-contrib/features/ionic-cli:2": { + "version": "7.1.1" + }, + "ghcr.io/devcontainers-contrib/features/kind:1": { + "version": "v0.18.0" + } + } - // Use this environment variable if you need to bind mount your local source code into a new container. - // Set *default* container specific settings.json values on container create. - "settings": { - // "terminal.integrated.shell.linux": "/bin/bash", - "terminal.integrated.rendererType": "auto" - }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "bierner.markdown-mermaid", - "ms-azuretools.vscode-docker", - "mhutchie.git-graph", - "alefragnani.bookmarks", - "yzhang.markdown-all-in-one", - "trabpukcip.vscode-npm-scripts", - "jebbs.plantuml", - "ms-vscode-remote.vscode-remote-extensionpack", - "juanblanco.solidity", - "dbaeumer.vscode-eslint", - "42crunch.vscode-openapi" - ], + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, // 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": "bash -i -c '~/bin/post-create-commands.sh'", + // "postCreateCommand": "uname -a", + + // Configure tool-specific properties. + // "customizations": {}, - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } diff --git a/.devcontainer/library-scripts/common-debian.sh b/.devcontainer/library-scripts/common-debian.sh deleted file mode 100644 index 3d4ca821bb..0000000000 --- a/.devcontainer/library-scripts/common-debian.sh +++ /dev/null @@ -1,395 +0,0 @@ -#!/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/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 Zsh! flag] [Add non-free packages] - -INSTALL_ZSH=${1:-"true"} -USERNAME=${2:-"automatic"} -USER_UID=${3:-"automatic"} -USER_GID=${4:-"automatic"} -UPGRADE_PACKAGES=${5:-"true"} -INSTALL_OH_MYS=${6:-"true"} -ADD_NON_FREE_PACKAGES=${7:-"false"} - -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 - -# 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="" - 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 - - 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 \ - manpages \ - manpages-dev " - - # 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 "s/deb http:\/\/deb\.debian\.org\/debian ${CODENAME} main/deb http:\/\/deb\.debian\.org\/debian ${CODENAME} main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${CODENAME} main/deb http:\/\/deb\.debian\.org\/debian ${CODENAME} main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${CODENAME}-updates main/deb http:\/\/deb\.debian\.org\/debian ${CODENAME}-updates main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${CODENAME}-updates main/deb http:\/\/deb\.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 - 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' - -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 ] && [ ! -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 - -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 -A1 "$0" | grep -v "$0" -} - -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 bash and OMZ themes - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/93ad3a88214b95f571e03c21f7d9bd76f9110938/themes/robbyrussell.zsh-theme -CODESPACES_BASH="$(cat \ -<<'EOF' - -# Codespaces bash prompt theme -__bash_prompt() { - local userpart='`export XIT=$? \ - && [ ! -z "${GITHUB_USER}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER} " || echo -n "\[\033[0;32m\]\u " \ - && [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`' - local gitbranch='`\ - export BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null); \ - if [ "${BRANCH}" = "HEAD" ]; then \ - export BRANCH=$(git describe --contains --all HEAD 2>/dev/null); \ - fi; \ - if [ "${BRANCH}" != "" ]; then \ - echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH}" \ - && if git ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \ - echo -n " \[\033[1;33m\]✗"; \ - fi \ - && echo -n "\[\033[0;36m\]) "; \ - fi`' - local lightblue='\[\033[1;34m\]' - local removecolor='\[\033[0m\]' - PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ " - unset -f __bash_prompt -} -__bash_prompt - -EOF -)" -CODESPACES_ZSH="$(cat \ -<<'EOF' -__zsh_prompt() { - local prompt_username - if [ ! -z "${GITHUB_USER}" ]; then - prompt_username="@${GITHUB_USER}" - else - prompt_username="%n" - fi - PROMPT="%{$fg[green]%}${prompt_username} %(?:%{$reset_color%}➜ :%{$fg_bold[red]%}➜ )" - PROMPT+='%{$fg_bold[blue]%}%~%{$reset_color%} $(git_prompt_info)%{$fg[white]%}$ %{$reset_color%}' - unset -f __zsh_prompt -} -ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[cyan]%}(%{$fg_bold[red]%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " -ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg_bold[yellow]%}✗%{$fg_bold[cyan]%})" -ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[cyan]%})" -__zsh_prompt -EOF -)" - -# Add notice that Oh My Bash! has been removed from images and how to provide information on how to install manually -OMB_README="$(cat \ -<<'EOF' -"Oh My Bash!" has been removed from this image in favor of a simple shell prompt. If you -still wish to use it, remove "~/.oh-my-bash" and install it from: https://github.com/ohmybash/oh-my-bash -You may also want to consider "Bash-it" as an alternative: https://github.com/bash-it/bash-it -See here for infomation on adding it to your image or dotfiles: https://aka.ms/codespaces/omb-remove -EOF -)" -OMB_STUB="$(cat \ -<<'EOF' -#!/usr/bin/env bash -if [ -t 1 ]; then - cat $HOME/.oh-my-bash/README.md -fi -EOF -)" - -# 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" - if [ "${USERNAME}" != "root" ]; then - echo "${CODESPACES_BASH}" >> "/root/.bashrc" - fi - 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 - 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 - chown -R "${USERNAME}:${USERNAME}" "${USER_RC_PATH}/.oh-my-bash" -fi - -# 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 - - # Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. - # See https://github.com/ohmyzsh/ohmyzsh/blob/93ad3a88214b95f571e03c21f7d9bd76f9110938/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 - -# 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!" diff --git a/.devcontainer/library-scripts/docker-in-docker-debian.sh b/.devcontainer/library-scripts/docker-in-docker-debian.sh deleted file mode 100644 index 1498725b33..0000000000 --- a/.devcontainer/library-scripts/docker-in-docker-debian.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/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/main/script-library/docs/docker-in-docker.md -# Maintainer: The VS Code and Codespaces Teams -# -# Syntax: ./docker-in-docker-debian.sh [enable non-root docker access flag] [non-root user] [use moby] - -ENABLE_NONROOT_DOCKER=${1:-"true"} -USERNAME=${2:-"automatic"} -USE_MOBY=${3:-"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 - -# Determine the appropriate non-root user -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=root - fi -elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then - USERNAME=root -fi - -# Function to run 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 -} - -# Ensure apt is in non-interactive to avoid prompts -export DEBIAN_FRONTEND=noninteractive - -# Install docker/dockerd dependencies if missing -if ! dpkg -s apt-transport-https curl ca-certificates lsb-release lxc pigz iptables > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then - apt-get-update-if-needed - apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates lsb-release lxc pigz iptables gnupg2 -fi - -# Swap to legacy iptables for compatibility -update-alternatives --set iptables /usr/sbin/iptables-legacy -update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy - -# Install Docker / Moby CLI if not already installed -if type docker > /dev/null 2>&1 && type dockerd > /dev/null 2>&1; then - echo "Docker / Moby CLI and Engine already installed." -else - if [ "${USE_MOBY}" = "true" ]; then - DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]') - CODENAME=$(lsb_release -cs) - curl -s https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) - echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-${DISTRO}-${CODENAME}-prod ${CODENAME} main" > /etc/apt/sources.list.d/microsoft.list - apt-get update - apt-get -y install --no-install-recommends moby-cli moby-engine - else - curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT) - echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list - apt-get update - apt-get -y install --no-install-recommends docker-ce-cli docker-ce - fi -fi - -echo "Finished installing docker / moby" - -# Install Docker Compose if not already installed -if type docker-compose > /dev/null 2>&1; then - echo "Docker Compose already installed." -else - LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")') - curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose -fi - -# If init file already exists, exit -if [ -f "/usr/local/share/docker-init.sh" ]; then - echo "/usr/local/share/docker-init.sh already exists, so exiting." - exit 0 -fi -echo "docker-init doesnt exist..." - -# Add user to the docker group -if [ "${ENABLE_NONROOT_DOCKER}" = "true" ]; then - if ! getent group docker > /dev/null 2>&1; then - groupadd docker - fi - usermod -aG docker ${USERNAME} -fi - -tee /usr/local/share/docker-init.sh > /dev/null \ -<< 'EOF' -#!/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. -#------------------------------------------------------------------------------------------------------------- - -sudoIf() -{ - if [ "$(id -u)" -ne 0 ]; then - sudo "$@" - else - "$@" - fi -} - -# explicitly remove dockerd and containerd PID file to ensure that it can start properly if it was stopped uncleanly -# ie: docker kill -sudoIf find /run /var/run -iname 'docker*.pid' -delete || : -sudoIf find /run /var/run -iname 'container*.pid' -delete || : - -set -e - -## Dind wrapper script from docker team -# Maintained: https://github.com/moby/moby/blob/v20.10.8/hack/dind - -export container=docker - -if [ -d /sys/kernel/security ] && ! sudoIf mountpoint -q /sys/kernel/security; then - sudoIf mount -t securityfs none /sys/kernel/security || { - echo >&2 'Could not mount /sys/kernel/security.' - echo >&2 'AppArmor detection and --privileged mode might break.' - } -fi - -# Mount /tmp (conditionally) -if ! sudoIf mountpoint -q /tmp; then - sudoIf mount -t tmpfs none /tmp -fi - -# cgroup v2: enable nesting -if [ -f /sys/fs/cgroup/cgroup.controllers ]; then - # move the init process (PID 1) from the root group to the /init group, - # otherwise writing subtree_control fails with EBUSY. - sudoIf mkdir -p /sys/fs/cgroup/init - sudoIf echo 1 > /sys/fs/cgroup/init/cgroup.procs - # enable controllers - sudoIf sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \ - > /sys/fs/cgroup/cgroup.subtree_control -fi -## Dind wrapper over. - -# Handle DNS -set +e -cat /etc/resolv.conf | grep -i 'internal.cloudapp.net' -if [ $? -eq 0 ] -then - echo "Setting dockerd Azure DNS." - CUSTOMDNS="--dns 168.63.129.16" -else - echo "Not setting dockerd DNS manually." - CUSTOMDNS="" -fi -set -e - -# Start docker/moby engine -( sudoIf dockerd $CUSTOMDNS > /tmp/dockerd.log 2>&1 ) & - -set +e - -# Execute whatever commands were passed in (if any). This allows us -# to set this script to ENTRYPOINT while still executing the default CMD. -exec "$@" -EOF - -chmod +x /usr/local/share/docker-init.sh -chown ${USERNAME}:root /usr/local/share/docker-init.sh diff --git a/.devcontainer/post-create-commands.sh b/.devcontainer/post-create-commands.sh deleted file mode 100755 index 200ccff193..0000000000 --- a/.devcontainer/post-create-commands.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e - -whoami - -NEW_PATH_ELEMENT="~/bin/" -echo "export PATH=\"$NEW_PATH_ELEMENT\":\${PATH}" >> ~/.bashrc - -docker info - -npm run install-yarn -npm run configure diff --git a/.github/workflows/cacti-dev-container-vscode-publish.yaml b/.github/workflows/cacti-dev-container-vscode-publish.yaml new file mode 100644 index 0000000000..64ce393275 --- /dev/null +++ b/.github/workflows/cacti-dev-container-vscode-publish.yaml @@ -0,0 +1,64 @@ +name: connector-fabric-publish + +on: + push: + # Publish `v1.2.3` tags as releases. + tags: + - v* + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + IMAGE_NAME: cacti-dev-container-vscode + +jobs: + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + build-tag-push-container: + runs-on: ubuntu-20.04 + env: + DOCKER_BUILDKIT: 1 + DOCKERFILE_PATH: ./packages/cactus-plugin-ledger-connector-fabric/Dockerfile + DOCKER_BUILD_DIR: ./packages/cactus-plugin-ledger-connector-fabric/ + permissions: + packages: write + contents: read + + steps: + - name: Use Node.js v20.3.0 + uses: actions/setup-node@v3.6.0 + with: + node-version: v20.3.0 + + - uses: actions/checkout@v3.5.2 + + - name: npm_install_@devcontainers/cli@0.44.0 + run: npm install -g @devcontainers/cli@0.44.0 + + - name: npx_yes_devcontainers_cli_build + run: npx --yes @devcontainers/cli@0.44.0 build --workspace-folder=./ --log-level=trace --push=false --config=./.devcontainer/devcontainer.json --image-name=$IMAGE_NAME + + - name: Log in to registry + # This is where you will update the PAT to GITHUB_TOKEN + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + SHORTHASH=$(git rev-parse --short "$GITHUB_SHA") + TODAYS_DATE="$(date +%F)" + DOCKER_TAG="$TODAYS_DATE-$SHORTHASH" + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Do not use the `latest` tag at all, tag with date + git short hash if there is no git tag + [ "$VERSION" == "main" ] && VERSION=$DOCKER_TAG + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e23f1dc05e..d66c5afec9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1347,10 +1347,18 @@ jobs: run: DOCKER_BUILDKIT=1 docker build ./tools/docker/corda-all-in-one/ -f ./tools/docker/corda-all-in-one/corda-v4_8/Dockerfile ghcr-dev-container-vscode: runs-on: ubuntu-20.04 + env: + IMAGE_NAME: cacti-dev-container-vscode steps: + - name: Use Node.js v20.3.0 + uses: actions/setup-node@v3.6.0 + with: + node-version: v20.3.0 - uses: actions/checkout@v3.5.2 - - name: ghcr.io/hyperledger/cactus-dev-container-vscode - run: DOCKER_BUILDKIT=1 docker build ./.devcontainer/ -f ./.devcontainer/Dockerfile + - name: npm_install_@devcontainers/cli@0.44.0 + run: npm install -g @devcontainers/cli@0.44.0 + - name: npx_yes_devcontainers_cli_build + run: npx --yes @devcontainers/cli@0.44.0 build --workspace-folder=./ --log-level=trace --push=false --config=./.devcontainer/devcontainer.json --image-name=$IMAGE_NAME ghcr-example-carbon-accounting: runs-on: ubuntu-20.04 steps: