diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2021-09-20 23:08:50 +0000 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2021-09-20 23:08:50 +0000 |
| commit | 49373b9b516fbb4aaa69376d4c8705fdfa633fa0 (patch) | |
| tree | 1812a66836cfaea85420f15d236e7bc0dafdf332 | |
| parent | 22af0d845e56615b216457111524e3a268d2a526 (diff) | |
| download | ao-coverage-49373b9b516fbb4aaa69376d4c8705fdfa633fa0.tar.gz ao-coverage-49373b9b516fbb4aaa69376d4c8705fdfa633fa0.tar.bz2 ao-coverage-49373b9b516fbb4aaa69376d4c8705fdfa633fa0.zip | |
Last .devcontainer changes
- Copy over more RC changes
- Copy over Microsoft's license and copyright for brevity
- Change container names
| -rw-r--r-- | .devcontainer/Dockerfile | 3 | ||||
| -rw-r--r-- | .devcontainer/devcontainer.json | 6 | ||||
| -rw-r--r-- | .devcontainer/docker-compose.yml | 11 | ||||
| -rw-r--r-- | .devcontainer/node.sh | 213 | ||||
| -rw-r--r-- | README.md | 4 |
5 files changed, 228 insertions, 9 deletions
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index eae9427..0c2907b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,9 +4,10 @@ FROM ubuntu:bionic # Install needed packages, yarn, nvm and setup non-root user RUN groupadd --gid 1000 node \ && useradd --uid 1000 --gid node --shell /bin/bash --create-home node +ARG INSTALL_ZSH=false COPY node.sh ./ RUN chmod +x ./node.sh -RUN ./node.sh +RUN ./node.sh $INSTALL_ZSH # Install MongoDB command line tools ARG MONGO_TOOLS_VERSION=4.2 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6605c26..c16b503 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,9 +1,9 @@ // 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.194.0/containers/javascript-node-mongo { - "name": "Ubuntu, Node.js & Mongo DB", + "name": "AO Coverage", "dockerComposeFile": "docker-compose.yml", - "service": "app", + "service": "aocov", "workspaceFolder": "/workspace", // Set *default* container specific settings.json values on container create. @@ -15,6 +15,6 @@ "esbenp.prettier-vscode" ], "forwardPorts": [3000, 27017], - "postCreateCommand": "sudo locale-gen 'en_US.UTF-8'; sudo chown node:node node_modules; yarn install", + "postCreateCommand": "sudo chown node:node node_modules; yarn install", "remoteUser": "node" }
\ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 20632f3..74b5210 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: - app: + aocov: build: context: . dockerfile: Dockerfile @@ -10,6 +10,9 @@ services: USER_UID: 1000 USER_GID: 1000 + # Change this if you want zsh as your shell + INSTALL_ZSH: false + # Volume directory for hosted files. This directory is created in the Dockerfile with proper permissions. This is set as an env-var in the Dockerfile HOST_DIR: /dist @@ -20,7 +23,7 @@ services: TARGET_URL: http://localhost:3000 # DB info - MONGO_URI: mongodb://db:27017 + MONGO_URI: mongodb://aocov-db:27017 MONGO_DB: ao-coverage # App configuration @@ -37,7 +40,7 @@ services: command: sleep infinity # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. - network_mode: service:db + network_mode: service:aocov-db # Uncomment the next line to use a non-root user for all processes. user: node @@ -45,7 +48,7 @@ services: # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # (Adding the "ports" property to this file will not forward from a Codespace.) - db: + aocov-db: image: mongo:latest restart: unless-stopped volumes: diff --git a/.devcontainer/node.sh b/.devcontainer/node.sh index 0b47058..3306fbe 100644 --- a/.devcontainer/node.sh +++ b/.devcontainer/node.sh @@ -1,9 +1,24 @@ #!/bin/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 +# +# This is file is derived from multiple of the image scripts provided by Microsoft (common-debian.sh and +# node-debian.sh). The reasoning for the separate maintenance is to provide support for both Node and Mongo +# tools on the arm64 architecture. Mongo's own repository does not provide those tools for arm64 on Debian, +# on which Microsoft bases all of their Node devcontainer images. The scripts have thus been adapted to work +# with one of the official Ubuntu Docker images. The mentioned MongoDB tools are installed via the Dockerfile +# that calls this script. export NVM_DIR="/usr/local/share/nvm" export NODE_VERSION="lts" export NVM_VERSION="0.38.0" USERNAME="node" +INSTALL_ZSH=${1:-"true"} +MARKER_FILE="/usr/local/etc/vscode-dev-containers/common" updaterc() { echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..." @@ -28,7 +43,7 @@ apt_get_update_if_needed() check_packages() { if ! dpkg -s "$@" > /dev/null 2>&1; then apt_get_update_if_needed - apt-get -y install --no-install-recommends "$@" + apt-get -y install --no-install-recommends "$@" 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 ) fi } @@ -84,6 +99,14 @@ check_packages apt-utils \ echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME +# 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 + # Install yarn if type yarn > /dev/null 2>&1; then echo "Yarn already installed." @@ -141,4 +164,192 @@ export NVM_DIR="${NVM_DIR}" EOF )" +# ** Shell customization section ** +if [ "${USERNAME}" = "root" ]; then + user_rc_path="/root" +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' +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 not already set +if [ -z "$(git config --get core.editor)" ] && [ -z "${GIT_EDITOR}" ]; then + 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 +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 + +# 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 \ +<<'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 symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null); \ + 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' +# Codespaces zsh prompt theme +__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]%}➜ )" # User/exit code arrow + PROMPT+='%{$fg_bold[blue]%}%(5~|%-1~/…/%3~|%4~)%{$reset_color%} ' # cwd + PROMPT+='$(git_prompt_info)%{$fg[white]%}$ %{$reset_color%}' # Git status + 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 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 + chown ${USERNAME}:${USERNAME} "${user_rc_path}/.bashrc" + RC_SNIPPET_ALREADY_ADDED="true" +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/master/tools/install.sh for official script. + oh_my_install_dir="${user_rc_path}/.oh-my-zsh" + if [ ! -d "${oh_my_install_dir}" ]; 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!"
\ No newline at end of file @@ -4,6 +4,10 @@ A simple coverage handler and server. The basic function provides an SVG badge w Currently, the only supported code coverage format is [Tarpaulin](https://crates.io/crates/cargo-tarpaulin), which is specific to Rust. Recommended formats and pull requests are welcome! If you want an account for this Gitea to interact with this repository, please contact the maintainer at [kjhoerr@submelon.tech](mailto:kjhoerr@submelon.tech). +## Developing + +This repository includes a `.devcontainer` to assist with getting developing off the ground as quickly as possible. This includes a Docker image for the repository with installed tools for MongoDB, and MongoDB in a compose stack. The provided image was completely rewritten from the ubuntu base to provide support for `arm64`, so the initial build may take a little while. This comes completely preconfigured, and a generated TOKEN gets printed to logs when you start the server. + ## License This project is licensed under [the Parity Public License](LICENSE.md). Currently, proprietary-use licenses are not available and offers will not be considered.
\ No newline at end of file |
