From 262ee5ae6c7ef0645205d2f0d63b67753b215d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sun, 14 Jan 2024 16:19:01 +0000 Subject: [PATCH 01/28] [wip] devcontainer --- .devcontainer/Dockerfile | 45 ++ .devcontainer/devcontainer.json | 37 ++ .../library-scripts/common-debian.sh | 454 ++++++++++++++++++ 3 files changed, 536 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/library-scripts/common-debian.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..45a3f8f --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,45 @@ +# Update the VARIANT arg in devcontainer.json to pick a Perl version +ARG VARIANT=5 +FROM perl:${VARIANT} + +# [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. This section is for the devcontainer setup. Use a separate RUN statement to add project dependencies. +ARG USERNAME=swmaker +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" \ + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts + +# [Optional] Uncomment this section to install additional packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + carton \ + libanyevent-perl \ + libclass-refresh-perl \ + libcompiler-lexer-perl \ + libcoro-perl \ + libdata-clone-perl \ + libdata-dump-perl \ + libdatetime-perl \ + libio-aio-perl \ + libjson-perl \ + liblist-moreutils-perl \ + libmoose-perl \ + libpadwalker-perl \ + libscalar-list-utils-perl \ + && cpanm Perl::LanguageServer + # && cpanm Perl::LanguageServer \ + # Cache::FastMmap \ + # Data::Clone \ + # Data::UUID \ + # DBD::SQLite \ + # DBI::Const::GetInfoType + + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fa88d74 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +{ + "name": "Perl (Community)", + "build": { + "dockerfile": "Dockerfile", + // Update VARIANT to pick a Perl version + "args": { "VARIANT": "5" } + }, + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "d9705996.perl-toolbox", + "richterger.perl", + "samosad.tt" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 3000, + 3001 + ], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "carton install --cached", + + // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "swmaker", + "features": { + "ghcr.io/warrenbuckley/codespace-features/sqlite:1": {} + } +} diff --git a/.devcontainer/library-scripts/common-debian.sh b/.devcontainer/library-scripts/common-debian.sh new file mode 100644 index 0000000..efdca35 --- /dev/null +++ b/.devcontainer/library-scripts/common-debian.sh @@ -0,0 +1,454 @@ +#!/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] + +set -e + +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"} +SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)" +MARKER_FILE="/usr/local/etc/vscode-dev-containers/common" + +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 +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 \ + openssh-client \ + gnupg2 \ + dirmngr \ + 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-ust[0-9] \ + libstdc++6 \ + zlib1g \ + locales \ + sudo \ + ncdu \ + man-db \ + 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 + # Bring in variables from /etc/os-release like VERSION_CODENAME + . /etc/os-release + sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list + sed -i -E "s/deb-src http:\/\/(deb|httredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list + sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list + sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list + # Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html + sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list + sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security 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_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') + if [ "$(echo "$LIlibssl_packageBSSL" | 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 ) + + # Install git if not already installed (may be more recent than distro version) + if ! type git > /dev/null 2>&1; then + apt-get -y install --no-install-recommends git + fi + + 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. +group_name="${USERNAME}" +if id -u ${USERNAME} > /dev/null 2>&1; then + # User exists, update if needed + if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then + group_name="$(id -gn $USERNAME)" + groupmod --gid $USER_GID ${group_name} + 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 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 + +# 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 "$@" +else + echo '\n"systemd" is not running in this container due to its overhead.\nUse the "service" command to start services instead. 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='`\ + if [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \ + 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; \ + 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 config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ] && git_prompt_info)' # Git status + PROMPT+='%{$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 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}:${group_name} "${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}" ] && [ "${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}:${group_name} "${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 +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 0730f71ef548a532efd142837a83ab298d55343a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sat, 10 Feb 2024 00:15:34 +0000 Subject: [PATCH 02/28] add devcontainer and postgres dev env running, runtime and deps not set up yet, access-sytem not configured --- .devcontainer/devcontainer.json | 81 +++- .devcontainer/docker-compose.yaml | 26 + .../library-scripts/common-debian.sh | 454 ------------------ .github/dependabot.yml | 12 + docker-compose.yaml | 14 + 5 files changed, 108 insertions(+), 479 deletions(-) create mode 100644 .devcontainer/docker-compose.yaml delete mode 100644 .devcontainer/library-scripts/common-debian.sh create mode 100644 .github/dependabot.yml create mode 100644 docker-compose.yaml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fa88d74..8912d8a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,37 +1,68 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose { - "name": "Perl (Community)", - "build": { - "dockerfile": "Dockerfile", - // Update VARIANT to pick a Perl version - "args": { "VARIANT": "5" } + "name": "Existing Docker Compose (Extend)", + + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. + "dockerComposeFile": [ + "../docker-compose.yaml", + "docker-compose.yaml" + ], + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "access-system", + + // The optional 'workspaceFolder' property is the path VS Code should open by default when + // connected. This is typically a file mount in .devcontainer/docker-compose.yml + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": true, + "configureZshAsDefaultShell": true, + "installOhMyZsh": true, + "installOhMyZshConfig": true, + "upgradePackages": true, + "username": "devcontainer", + "userUid": "automatic", + "userGid": "automatic" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "installDirectlyFromGitHubRelease": true, + "version": "latest" + } }, - "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // 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": [], + + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", // Configure tool-specific properties. "customizations": { - // Configure properties specific to VS Code. "vscode": { - // Add the IDs of extensions you want installed when the container is created. "extensions": [ - "d9705996.perl-toolbox", "richterger.perl", - "samosad.tt" + "cfgweb.vscode-perl", + "tamasfe.even-better-toml", + "maattdd.gitless", + "mtxr.sqltools", + "ms-azuretools.vscode-docker" ] } - }, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - "forwardPorts": [ - 3000, - 3001 - ], - - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "carton install --cached", - - // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "swmaker", - "features": { - "ghcr.io/warrenbuckley/codespace-features/sqlite:1": {} } + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" } diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml new file mode 100644 index 0000000..9ced3ce --- /dev/null +++ b/.devcontainer/docker-compose.yaml @@ -0,0 +1,26 @@ +version: '3.8' +services: + # Update this to the name of the service you want to work with in your docker-compose.yml file + access-system: + # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer + # folder. Note that the path of the Dockerfile and context is relative to the *primary* + # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" + # array). The sample below assumes your primary file is in the root of your project. + # + # build: + # context: . + # dockerfile: .devcontainer/Dockerfile + + volumes: + # Update this to wherever you want VS Code to mount the folder of your project + - ..:/workspaces:cached + + # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. + # cap_add: + # - SYS_PTRACE + # security_opt: + # - seccomp:unconfined + + # Overrides default command so things don't shut down after the process ends. + command: /bin/sh -c "while sleep 1000; do :; done" + diff --git a/.devcontainer/library-scripts/common-debian.sh b/.devcontainer/library-scripts/common-debian.sh deleted file mode 100644 index efdca35..0000000 --- a/.devcontainer/library-scripts/common-debian.sh +++ /dev/null @@ -1,454 +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] - -set -e - -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"} -SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)" -MARKER_FILE="/usr/local/etc/vscode-dev-containers/common" - -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 -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 \ - openssh-client \ - gnupg2 \ - dirmngr \ - 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-ust[0-9] \ - libstdc++6 \ - zlib1g \ - locales \ - sudo \ - ncdu \ - man-db \ - 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 - # Bring in variables from /etc/os-release like VERSION_CODENAME - . /etc/os-release - sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list - sed -i -E "s/deb-src http:\/\/(deb|httredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list - sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list - sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list - # Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html - sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list - sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security 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_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') - if [ "$(echo "$LIlibssl_packageBSSL" | 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 ) - - # Install git if not already installed (may be more recent than distro version) - if ! type git > /dev/null 2>&1; then - apt-get -y install --no-install-recommends git - fi - - 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. -group_name="${USERNAME}" -if id -u ${USERNAME} > /dev/null 2>&1; then - # User exists, update if needed - if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then - group_name="$(id -gn $USERNAME)" - groupmod --gid $USER_GID ${group_name} - 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 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 - -# 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 "$@" -else - echo '\n"systemd" is not running in this container due to its overhead.\nUse the "service" command to start services instead. 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='`\ - if [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \ - 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; \ - 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 config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ] && git_prompt_info)' # Git status - PROMPT+='%{$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 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}:${group_name} "${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}" ] && [ "${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}:${group_name} "${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 -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/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..d61a9ce --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,14 @@ +version: '3.8' +services: + access-system: + build: + context: . + dockerfile: .devcontainer/Dockerfile + # volumes: + # - ..:/opt + depends_on: + - db + db: + image: postgres:11 + environment: + POSTGRES_PASSWORD: test From 4055878fea5130c7bed89fc33754614259759fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sat, 10 Feb 2024 01:12:52 +0000 Subject: [PATCH 03/28] add perl libs to container --- .devcontainer/devcontainer.json | 1 + docker-compose.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8912d8a..4083501 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -58,6 +58,7 @@ "tamasfe.even-better-toml", "maattdd.gitless", "mtxr.sqltools", + "mtxr.sqltools-driver-pg", "ms-azuretools.vscode-docker" ] } diff --git a/docker-compose.yaml b/docker-compose.yaml index d61a9ce..cd4d3cb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,7 +3,7 @@ services: access-system: build: context: . - dockerfile: .devcontainer/Dockerfile + dockerfile: Dockerfile # volumes: # - ..:/opt depends_on: From 6ef5f43749027c30d55a5479f489a69f4368757a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sat, 10 Feb 2024 11:20:42 +0000 Subject: [PATCH 04/28] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45c7b9e..e61704b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Technologies * [Catalyst](https://metacpan.org/pod/Catalyst) - Perl Web Framework -* [RapidApp](https://metacpan.org/pod/RadpiApp) - CRUD built atop Catalyst +* [RapidApp](https://metacpan.org/pod/RapidApp) - CRUD built atop Catalyst * [DBIx::Class](https://metacpan.org/pod/DBIx::Class) - Perl ORM From 8fcdbbf064517236182755ca3e83c724aa7abef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sat, 10 Feb 2024 20:39:10 +0000 Subject: [PATCH 05/28] reduce image layers and remove apt cache --- Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Dockerfile b/Dockerfile index 2de86ce..1a5c2bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,3 +46,10 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ libcoro-perl \ && cpanm Perl::LanguageServer \ && rm -rf /var/lib/apt/lists/* + +# WORKDIR /opt +# WORKDIR /workspaces + +# COPY . . + +# RUN carton install --cached From 19fd49f8f0f7ecd31ca88a45d4170127597835d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sat, 17 Feb 2024 09:47:04 +0000 Subject: [PATCH 06/28] set access system dev image as devcontainer base --- .gitignore | 1 + docker-compose.yaml | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f8436b9..9dde3d4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .plx/ .vscode/perl-lang/ +*.code-workspace # exception for email template assets !root/img/*.png diff --git a/docker-compose.yaml b/docker-compose.yaml index cd4d3cb..9fe4ca5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,7 @@ version: '3.8' services: access-system: - build: - context: . - dockerfile: Dockerfile + image: ghcr.io/swindonmakers/access-system-dev:latest # volumes: # - ..:/opt depends_on: From 2807867a8a8e345dd6ea401ce0f7fe1508e3107b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 22 Feb 2024 19:27:29 +0000 Subject: [PATCH 07/28] highlight code examples in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e61704b..57994cf 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,11 @@ INSTALL * Install cpanm, either via [App::cpanminus](https://metacpan.org/pod/App::cpanminus) or wget [cpanm](http://xrl.us/cpanm), make the result executable. -* Install carton: cpanm -S Carton +* Install carton: `cpanm -S Carton` * Checkout this git repo, cd into the repo directory. -* Install Perl dependencies for this system: carton install --cached +* Install Perl dependencies for this system: `carton install --cached` SETUP ----- From 3771dff60fe4daaae0098768ef17084a437f7eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 22 Feb 2024 19:28:54 +0000 Subject: [PATCH 08/28] remove not needed Dockerfile from .devcontainer folder --- .devcontainer/Dockerfile | 45 ------------------------------- .devcontainer/docker-compose.yaml | 1 - 2 files changed, 46 deletions(-) delete mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 45a3f8f..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -# Update the VARIANT arg in devcontainer.json to pick a Perl version -ARG VARIANT=5 -FROM perl:${VARIANT} - -# [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. This section is for the devcontainer setup. Use a separate RUN statement to add project dependencies. -ARG USERNAME=swmaker -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" \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts - -# [Optional] Uncomment this section to install additional packages. -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends \ - carton \ - libanyevent-perl \ - libclass-refresh-perl \ - libcompiler-lexer-perl \ - libcoro-perl \ - libdata-clone-perl \ - libdata-dump-perl \ - libdatetime-perl \ - libio-aio-perl \ - libjson-perl \ - liblist-moreutils-perl \ - libmoose-perl \ - libpadwalker-perl \ - libscalar-list-utils-perl \ - && cpanm Perl::LanguageServer - # && cpanm Perl::LanguageServer \ - # Cache::FastMmap \ - # Data::Clone \ - # Data::UUID \ - # DBD::SQLite \ - # DBI::Const::GetInfoType - - - diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml index 9ced3ce..5a44d22 100644 --- a/.devcontainer/docker-compose.yaml +++ b/.devcontainer/docker-compose.yaml @@ -23,4 +23,3 @@ services: # Overrides default command so things don't shut down after the process ends. command: /bin/sh -c "while sleep 1000; do :; done" - From 3bb095bf4cf165347b933c6c8740299492dc9b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 22 Feb 2024 20:06:54 +0000 Subject: [PATCH 09/28] Add libpq-dev for PostgreSQL support and swmakers user --- Dockerfile | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a5c2bd..8400ba5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ libtimedate-perl \ liburi-perl \ libscalar-list-utils-perl \ + # postgres + libpq-dev \ && cpanm -S Carton \ # for Perl::LanguageServer && apt-get -y install --no-install-recommends \ @@ -47,9 +49,14 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && cpanm Perl::LanguageServer \ && rm -rf /var/lib/apt/lists/* -# WORKDIR /opt -# WORKDIR /workspaces +COPY cpanfile* vendor /workspaces/AccessSystem/ -# COPY . . +WORKDIR /workspaces/AccessSystem -# RUN carton install --cached +RUN groupadd --gid 1001 swmakers \ + && useradd --uid 1001 --gid swmakers --shell /bin/bash --create-home swmakers \ + && chown -R swmakers:swmakers /workspaces/AccessSystem + +USER swmakers + +RUN carton install --cached From 02b0101c25f31d7032e3c60fedd3566bf3a2531e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 22 Feb 2024 21:25:56 +0000 Subject: [PATCH 10/28] Update CPAN dependencies and versions Needed to resovle error in container build --- cpanfile.snapshot | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cpanfile.snapshot b/cpanfile.snapshot index d451433..1919ff3 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -1190,6 +1190,22 @@ DISTRIBUTIONS Module::Build::Tiny 0.035 URI::Escape 0 perl 5.008001 + Cpanel-JSON-XS-4.37 + pathname: R/RU/RURBAN/Cpanel-JSON-XS-4.37.tar.gz + provides: + Cpanel::JSON::XS 4.37 + Cpanel::JSON::XS::Type undef + requirements: + Carp 0 + Config 0 + Encode 1.9801 + Exporter 0 + ExtUtils::MakeMaker 0 + Pod::Text 2.08 + XSLoader 0 + overload 0 + strict 0 + warnings 0 Crypt-Blowfish-2.14 pathname: D/DP/DPARIS/Crypt-Blowfish-2.14.tar.gz provides: @@ -7861,6 +7877,19 @@ DISTRIBUTIONS XML::RegExp 0.04 requirements: ExtUtils::MakeMaker 0 + XS-Parse-Keyword-0.39 + pathname: P/PE/PEVANS/XS-Parse-Keyword-0.39.tar.gz + provides: + XS::Parse::Infix 0.39 + XS::Parse::Infix::Builder 0.39 + XS::Parse::Keyword 0.39 + XS::Parse::Keyword::Builder 0.39 + requirements: + ExtUtils::CBuilder 0 + ExtUtils::CChecker 0.11 + ExtUtils::ParseXS 3.16 + Module::Build 0.4004 + perl 5.014 YAML-1.15 pathname: I/IN/INGY/YAML-1.15.tar.gz provides: From fe5821d45643896f40d0ffbf3b2d4dbc3d28c7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 22 Feb 2024 22:31:57 +0000 Subject: [PATCH 11/28] Add support for SQLite database in Dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8400ba5..fe6a28d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,8 +32,9 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ libtimedate-perl \ liburi-perl \ libscalar-list-utils-perl \ - # postgres + # database support libpq-dev \ + sqlite3 \ && cpanm -S Carton \ # for Perl::LanguageServer && apt-get -y install --no-install-recommends \ From efc1d3243a6798bfde4cd7a1df5b4279ca265d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 22 Feb 2024 22:36:49 +0000 Subject: [PATCH 12/28] Update devcontainer.json with new name and forwardPorts --- .devcontainer/devcontainer.json | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4083501..c1a2ad6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose { - "name": "Existing Docker Compose (Extend)", + "name": "Swindon Makerspace Access System devcontainer", // Update the 'dockerComposeFile' list if you have more compose files or use different names. // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. @@ -24,7 +24,7 @@ "installOhMyZsh": true, "installOhMyZshConfig": true, "upgradePackages": true, - "username": "devcontainer", + "username": "automatic", "userUid": "automatic", "userGid": "automatic" }, @@ -38,7 +38,7 @@ // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + "forwardPorts": [3000, 3001], // Uncomment the next line if you want start specific services in your Docker Compose config. // "runServices": [], @@ -59,11 +59,9 @@ "maattdd.gitless", "mtxr.sqltools", "mtxr.sqltools-driver-pg", - "ms-azuretools.vscode-docker" + "alexcvzz.vscode-sqlite" ] } - } - - // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "devcontainer" + }, + "remoteUser": "swmakers" } From d014c0a9dfd23a6feb81f69f473016284bc9a70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Wed, 11 Dec 2024 21:59:52 +0000 Subject: [PATCH 13/28] Fix COPY commands in Dockerfile to ensure proper file structure --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fe6a28d..87a085b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,7 +50,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && cpanm Perl::LanguageServer \ && rm -rf /var/lib/apt/lists/* -COPY cpanfile* vendor /workspaces/AccessSystem/ +COPY cpanfile* /workspaces/AccessSystem/ +COPY vendor/ /workspaces/AccessSystem/vendor/ WORKDIR /workspaces/AccessSystem From c36d90b0db9688f5a4a6b008fefe6da0f551a241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Wed, 11 Dec 2024 23:03:51 +0000 Subject: [PATCH 14/28] Build Docker image with caching support --- Dockerfile => .devcontainer/Dockerfile | 0 .github/workflows/build-dev-image.yaml | 15 +++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) rename Dockerfile => .devcontainer/Dockerfile (100%) diff --git a/Dockerfile b/.devcontainer/Dockerfile similarity index 100% rename from Dockerfile rename to .devcontainer/Dockerfile diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml index b0351b5..056c975 100644 --- a/.github/workflows/build-dev-image.yaml +++ b/.github/workflows/build-dev-image.yaml @@ -25,11 +25,18 @@ jobs: - name: 📦 Checkout code uses: actions/checkout@v4 - - name: 🏗️ Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID},sha=${GITHUB_SHA},ref=${GITHUB_REF}" - - name: 🔐 Log in to registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $CONTAINER_REGISTRY -u $ --password-stdin + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login $CONTAINER_REGISTRY -u $ --password-stdin + + - name: 🏗️ Build image + run: | + docker build . \ + --file .devcontainer/Dockerfile \ + --tag $IMAGE_NAME \ + --label "runnumber=${GITHUB_RUN_ID},sha=${GITHUB_SHA},ref=${GITHUB_REF}" \ + --cache-from=type=gha \ + --cache-to=type=gha,mode=max - name: 💾 Push image run: | From 4e7632a4b0c9d2a62f93ac2e3cdc62e24a4df28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Wed, 11 Dec 2024 23:16:41 +0000 Subject: [PATCH 15/28] Add support for versioned tags in build workflow --- .github/workflows/build-dev-image.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml index 056c975..1533660 100644 --- a/.github/workflows/build-dev-image.yaml +++ b/.github/workflows/build-dev-image.yaml @@ -4,6 +4,8 @@ on: push: branches: - master + tags: + - 'v*' pull_request: branches: - master From a19bf51511d1ca2d05d71ae17f75d946bebccbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 12 Dec 2024 00:10:28 +0000 Subject: [PATCH 16/28] Refactor GitHub Actions workflow to generate Docker metadata and improve image build process --- .github/workflows/build-dev-image.yaml | 68 ++++++++++++++++---------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml index 1533660..08acb58 100644 --- a/.github/workflows/build-dev-image.yaml +++ b/.github/workflows/build-dev-image.yaml @@ -27,29 +27,45 @@ jobs: - name: 📦 Checkout code uses: actions/checkout@v4 - - name: 🔐 Log in to registry - run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login $CONTAINER_REGISTRY -u $ --password-stdin - - - name: 🏗️ Build image - run: | - docker build . \ - --file .devcontainer/Dockerfile \ - --tag $IMAGE_NAME \ - --label "runnumber=${GITHUB_RUN_ID},sha=${GITHUB_SHA},ref=${GITHUB_REF}" \ - --cache-from=type=gha \ - --cache-to=type=gha,mode=max - - - name: 💾 Push image - run: | - IMAGE_ID=$CONTAINER_REGISTRY/$GITHUB_REPOSITORY_OWNER/$IMAGE_NAME - VERSION=$(echo "${BRANCH_NAME#refs/heads/}" | sed -e 's/[^a-zA-Z0-9]/-/g') # Get the branch name from the ref and replace non-alphanumeric characters with hyphens - [ "$VERSION" == "master" ] && VERSION=latest - echo "🆔 Image ID: $IMAGE_ID" - echo "#️⃣ GITHUB_SHA: $GITHUB_SHA" - echo "🎯 Version: $VERSION" - echo "🚀 Pushing image to registry........................................." - docker tag $IMAGE_NAME $IMAGE_ID:$GITHUB_SHA - docker push $IMAGE_ID:$GITHUB_SHA - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: 🏷️ Generate Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.CONTAINER_REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch,priority=610 + type=ref,event=pr + type=semver,pattern={{raw}} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=semver,pattern=v{{major}} + type=sha,format=long + type=raw,value=latest,enable={{is_default_branch}} + annotations: | + runnumber=${{ github.run_id }} + sha=${{ github.sha }} + ref=${{ github.ref }} + + - name: 🔐 Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.CONTAINER_REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: 🛠️ Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: 🚀 Build and push image + uses: docker/build-push-action@v6 + with: + context: . + file: .devcontainer/Dockerfile + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} + cache-from: type=gha + cache-to: type=gha,mode=max From 7afe7ee303402213fc21f4250cb14043117ada70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 12 Dec 2024 00:39:21 +0000 Subject: [PATCH 17/28] Add step to retrieve and sanitize branch name in build workflow --- .github/workflows/build-dev-image.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml index 08acb58..6a7eaa1 100644 --- a/.github/workflows/build-dev-image.yaml +++ b/.github/workflows/build-dev-image.yaml @@ -27,6 +27,11 @@ jobs: - name: 📦 Checkout code uses: actions/checkout@v4 + - name: 🧰 Get branch name + run: | # Get the branch name from the ref and replace non-alphanumeric characters with hyphens + BRANCH=$(echo "${BRANCH_NAME#refs/heads/}" | sed -e 's/[^a-zA-Z0-9]/-/g') + echo "BRANCH=$BRANCH" >> $GITHUB_ENV + - name: 🏷️ Generate Docker metadata id: meta uses: docker/metadata-action@v5 @@ -43,6 +48,7 @@ jobs: type=semver,pattern=v{{major}} type=sha,format=long type=raw,value=latest,enable={{is_default_branch}} + type=raw,value=${{ env.BRANCH_NAME }},priority=10 annotations: | runnumber=${{ github.run_id }} sha=${{ github.sha }} From c1df5c165779835ba365de3386d17626c58c0893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 12 Dec 2024 00:47:09 +0000 Subject: [PATCH 18/28] Enable pushing of Docker images in build workflow --- .github/workflows/build-dev-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml index 6a7eaa1..fa8f4ca 100644 --- a/.github/workflows/build-dev-image.yaml +++ b/.github/workflows/build-dev-image.yaml @@ -69,7 +69,7 @@ jobs: with: context: . file: .devcontainer/Dockerfile - push: false + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} From c75425598feb37a8f3acd6ddd518a03dad540f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Thu, 12 Dec 2024 00:51:13 +0000 Subject: [PATCH 19/28] Remove dependencies from cpanfile.snapshot --- cpanfile.snapshot | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/cpanfile.snapshot b/cpanfile.snapshot index 1919ff3..d451433 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -1190,22 +1190,6 @@ DISTRIBUTIONS Module::Build::Tiny 0.035 URI::Escape 0 perl 5.008001 - Cpanel-JSON-XS-4.37 - pathname: R/RU/RURBAN/Cpanel-JSON-XS-4.37.tar.gz - provides: - Cpanel::JSON::XS 4.37 - Cpanel::JSON::XS::Type undef - requirements: - Carp 0 - Config 0 - Encode 1.9801 - Exporter 0 - ExtUtils::MakeMaker 0 - Pod::Text 2.08 - XSLoader 0 - overload 0 - strict 0 - warnings 0 Crypt-Blowfish-2.14 pathname: D/DP/DPARIS/Crypt-Blowfish-2.14.tar.gz provides: @@ -7877,19 +7861,6 @@ DISTRIBUTIONS XML::RegExp 0.04 requirements: ExtUtils::MakeMaker 0 - XS-Parse-Keyword-0.39 - pathname: P/PE/PEVANS/XS-Parse-Keyword-0.39.tar.gz - provides: - XS::Parse::Infix 0.39 - XS::Parse::Infix::Builder 0.39 - XS::Parse::Keyword 0.39 - XS::Parse::Keyword::Builder 0.39 - requirements: - ExtUtils::CBuilder 0 - ExtUtils::CChecker 0.11 - ExtUtils::ParseXS 3.16 - Module::Build 0.4004 - perl 5.014 YAML-1.15 pathname: I/IN/INGY/YAML-1.15.tar.gz provides: From 0d33e5519c429a22074cd76df25a038445d8fc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sun, 22 Dec 2024 14:29:31 +0000 Subject: [PATCH 20/28] Refactor Dockerfile to streamline user setup and permissions --- .devcontainer/Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 87a085b..a758036 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,6 +1,13 @@ FROM mcr.microsoft.com/devcontainers/base:buster +ENV PATH="/workspaces/AccessSystem/local/bin:${PATH}" + +WORKDIR /workspaces/AccessSystem + +RUN groupadd --gid 1001 swmakers \ + && useradd --uid 1001 --gid swmakers --shell /bin/bash --create-home swmakers + RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install --no-install-recommends \ perl=5.28.1-6+deb10u1 \ @@ -53,11 +60,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ COPY cpanfile* /workspaces/AccessSystem/ COPY vendor/ /workspaces/AccessSystem/vendor/ -WORKDIR /workspaces/AccessSystem - -RUN groupadd --gid 1001 swmakers \ - && useradd --uid 1001 --gid swmakers --shell /bin/bash --create-home swmakers \ - && chown -R swmakers:swmakers /workspaces/AccessSystem +RUN chown -R swmakers:swmakers /workspaces/AccessSystem USER swmakers From 5d93717ded2aef3cd3e4b969fb9bdad6447b5e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sun, 22 Dec 2024 18:26:24 +0000 Subject: [PATCH 21/28] Refactor Dockerfile to set and use CATALYST_HOME variable --- .devcontainer/Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a758036..7dad5a8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,8 @@ FROM mcr.microsoft.com/devcontainers/base:buster -ENV PATH="/workspaces/AccessSystem/local/bin:${PATH}" +ENV CATALYST_HOME="/workspaces/AccessSystem" +ENV PATH="${CATALYST_HOME}/local/bin:${PATH}" WORKDIR /workspaces/AccessSystem @@ -57,10 +58,10 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && cpanm Perl::LanguageServer \ && rm -rf /var/lib/apt/lists/* -COPY cpanfile* /workspaces/AccessSystem/ -COPY vendor/ /workspaces/AccessSystem/vendor/ +COPY cpanfile* "${CATALYST_HOME}/" +COPY vendor/ "${CATALYST_HOME}/vendor/" -RUN chown -R swmakers:swmakers /workspaces/AccessSystem +RUN chown -R swmakers:swmakers "${CATALYST_HOME}" USER swmakers From dc4cc166f084443298b4ea3f9160732e85cc5c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Mon, 23 Dec 2024 15:55:47 +0000 Subject: [PATCH 22/28] Remove unused services and comments from docker-compose.yaml --- .devcontainer/docker-compose.yaml | 1 - docker-compose.yaml | 9 --------- 2 files changed, 10 deletions(-) diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml index 5a44d22..bea12c6 100644 --- a/.devcontainer/docker-compose.yaml +++ b/.devcontainer/docker-compose.yaml @@ -1,4 +1,3 @@ -version: '3.8' services: # Update this to the name of the service you want to work with in your docker-compose.yml file access-system: diff --git a/docker-compose.yaml b/docker-compose.yaml index 9fe4ca5..5a60505 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,12 +1,3 @@ -version: '3.8' services: access-system: image: ghcr.io/swindonmakers/access-system-dev:latest - # volumes: - # - ..:/opt - depends_on: - - db - db: - image: postgres:11 - environment: - POSTGRES_PASSWORD: test From ace9d1aeec43f2366122d1ce4ec016265370e1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Mon, 23 Dec 2024 16:28:22 +0000 Subject: [PATCH 23/28] Remove duplicate dependency from cpanfile --- cpanfile | 1 - 1 file changed, 1 deletion(-) diff --git a/cpanfile b/cpanfile index 72579d6..58f0f45 100644 --- a/cpanfile +++ b/cpanfile @@ -21,7 +21,6 @@ requires 'Template::Stash::XS'; requires 'HTML::FormHandlerX::Field::noCAPTCHA'; requires 'Daemon::Control'; requires 'Catalyst::View::JSON'; -requires 'Daemon::Control'; requires 'LWP::UserAgent'; requires 'LWP::Protocol::https'; requires 'JSON'; From d8183fc6ce7456e379c2cd08e238ad50c429fc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Mon, 23 Dec 2024 17:21:00 +0000 Subject: [PATCH 24/28] Add MailHog service --- .devcontainer/docker-compose.yaml | 4 ++-- docker-compose.yaml | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml index bea12c6..7204f0d 100644 --- a/.devcontainer/docker-compose.yaml +++ b/.devcontainer/docker-compose.yaml @@ -1,7 +1,7 @@ services: - # Update this to the name of the service you want to work with in your docker-compose.yml file access-system: - # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer + # We use a pre-built image to save time. You can also use a Dockerfile to build your own. + # Uncomment if you want to override the service's image with the Dockerfile in the .devcontainer # folder. Note that the path of the Dockerfile and context is relative to the *primary* # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" # array). The sample below assumes your primary file is in the root of your project. diff --git a/docker-compose.yaml b/docker-compose.yaml index 5a60505..7077aaa 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,3 +1,9 @@ services: access-system: image: ghcr.io/swindonmakers/access-system-dev:latest + + mailhog: + image: mailhog/mailhog + ports: + - "1025:1025" + - "8025:8025" From c8aaf82294d2c63237a5dba187c8fc2de8775435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Mon, 23 Dec 2024 23:11:16 +0000 Subject: [PATCH 25/28] Add configuration files and scripts for development environment setup --- .devcontainer/config/accesssystem.conf.dev | 21 +++++ .../config/accesssystem_api.conf.dev | 31 +++++++ .../config/accesssystem_api_local.conf.dev | 10 +++ .devcontainer/devcontainer.json | 22 +++-- .devcontainer/init-config | 33 +++++++ .devcontainer/init-sqlite | 86 +++++++++++++++++++ .devcontainer/seed-sqlite.sql | 14 +++ .devcontainer/start-services | 17 ++++ .gitignore | 1 + .../accesssystem_api_daemon_devcontainer.pl | 27 ++++++ script/accesssystem_daemon_devcontainer.pl | 27 ++++++ 11 files changed, 280 insertions(+), 9 deletions(-) create mode 100644 .devcontainer/config/accesssystem.conf.dev create mode 100644 .devcontainer/config/accesssystem_api.conf.dev create mode 100644 .devcontainer/config/accesssystem_api_local.conf.dev create mode 100755 .devcontainer/init-config create mode 100755 .devcontainer/init-sqlite create mode 100644 .devcontainer/seed-sqlite.sql create mode 100755 .devcontainer/start-services create mode 100755 script/accesssystem_api_daemon_devcontainer.pl create mode 100755 script/accesssystem_daemon_devcontainer.pl diff --git a/.devcontainer/config/accesssystem.conf.dev b/.devcontainer/config/accesssystem.conf.dev new file mode 100644 index 0000000..c8dd11b --- /dev/null +++ b/.devcontainer/config/accesssystem.conf.dev @@ -0,0 +1,21 @@ + + + dsn DBI:SQLite:db/dev.db + + + + site_key 6LdHZx0TAAAAAMuUdG-NScgCCbJ_HMyL1bdeM9vp + secret_key 6LdHZx0TAAAAAEAnQyttqqhDkEVXfUcsnDLPGmvi + + + + mailer SMTP + + host mailhog + port 1025 + sasl_username info@swindon-makerspace.org + sasl_password password + debug 1 + + + diff --git a/.devcontainer/config/accesssystem_api.conf.dev b/.devcontainer/config/accesssystem_api.conf.dev new file mode 100644 index 0000000..4547946 --- /dev/null +++ b/.devcontainer/config/accesssystem_api.conf.dev @@ -0,0 +1,31 @@ +# use_request_uri_for_path 1 +using_frontend-proxy 1 + + + site_key 6LdHZx0TAAAAAMuUdG-NScgCCbJ_HMyL1bdeM9vp + secret_key 6LdHZx0TAAAAAEAnQyttqqhDkEVXfUcsnDLPGmvi + + + + mailer SMTP + + host mailhog + port 1025 + helo localhost + sasl_username info@swindon-makerspace.org + sasl_password password + debug 1 + + + + + subdomain swindon-makerspace + domain swindon-makerspace.api.oneall.com + public_key + private_key + callback_url https://localhost/oneall_login_callback + + + name access_system + mac_secret C7B626AC-87A8-4C10-B5CC-D98BED2DBE0B + diff --git a/.devcontainer/config/accesssystem_api_local.conf.dev b/.devcontainer/config/accesssystem_api_local.conf.dev new file mode 100644 index 0000000..b88734c --- /dev/null +++ b/.devcontainer/config/accesssystem_api_local.conf.dev @@ -0,0 +1,10 @@ + + + dsn DBI:SQLite:db/dev.db + + + + api-key + +base_url http://localhost:3000/ +overlap_days 14 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c1a2ad6..bfa2c81 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,6 +17,8 @@ // The optional 'workspaceFolder' property is the path VS Code should open by default when // connected. This is typically a file mount in .devcontainer/docker-compose.yml "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/common-utils:2": { "installZsh": true, @@ -34,9 +36,6 @@ } }, - // 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": [3000, 3001], @@ -46,8 +45,9 @@ // Uncomment the next line if you want to keep your containers running after VS Code shuts down. // "shutdownAction": "none", - // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "cat /etc/os-release", + // Run commands after the container is created. + "postCreateCommand": ".devcontainer/init-sqlite -d dev.db", + "postStartCommand": ".devcontainer/start-services", // Configure tool-specific properties. "customizations": { @@ -57,11 +57,15 @@ "cfgweb.vscode-perl", "tamasfe.even-better-toml", "maattdd.gitless", - "mtxr.sqltools", - "mtxr.sqltools-driver-pg", - "alexcvzz.vscode-sqlite" + "EditorConfig.EditorConfig" ] - } + }, + "jetbrains" : { + "settings": { + "com.intellij:app:HttpConfigurable.use_proxy_pac": true + }, + "backend" : "IntelliJ" + }, }, "remoteUser": "swmakers" } diff --git a/.devcontainer/init-config b/.devcontainer/init-config new file mode 100755 index 0000000..92e1b9b --- /dev/null +++ b/.devcontainer/init-config @@ -0,0 +1,33 @@ +#!/bin/bash + +# Define the source and destination directories +src_dir="$(dirname "$0")/config" +dest_dir="$(dirname "$0")/.." + +# Find all .conf.dev files in the source directory +IFS=$'\n' read -rd '' -a config_files <<< "$(find "$src_dir" -name "*.conf.dev" -exec basename {} \;)" + +# Function to copy and rename files +copy_and_rename() { + local src_file="$1" + local dest_file="$2" + + if [ ! -f "$dest_file" ]; then + cp "$src_file" "$dest_file" + echo "Copied $src_file to $dest_file" + else + echo "File $dest_file already exists, not overwriting" + fi +} + +# Process each config file +for config_file in "${config_files[@]}"; do + src_file="$src_dir/$config_file" + dest_file="$dest_dir/${config_file%.dev}" + + if [ -f "$src_file" ]; then + copy_and_rename "$src_file" "$dest_file" + else + echo "Source file $src_file does not exist" + fi +done diff --git a/.devcontainer/init-sqlite b/.devcontainer/init-sqlite new file mode 100755 index 0000000..9e9bb89 --- /dev/null +++ b/.devcontainer/init-sqlite @@ -0,0 +1,86 @@ +#!/bin/sh + +# Function to display usage +usage() { + echo "Initialize an SQLite database for development in db/ folder\n" + echo "Options:" + echo "\t -d , e.g. dev.db" + echo "\t -f Force recreate the database file if it exists" + echo "\nUsage: $0 -d [-f]" + exit 1 +} + +force_recreate=false + +# Parse command line arguments +while getopts ":d:f" opt; do + case ${opt} in + d ) + db_filename=$OPTARG + ;; + f ) + force_recreate=true + ;; + \? ) + usage + ;; + esac +done + +# Check if the db_filename is provided +if [ -z "$db_filename" ]; then + usage +fi + +# Check if the filename ends with .db +if [ "${db_filename##*.}" != "db" ]; then + echo "Error: The database filename must end with .db" + usage +fi + +# Create the db folder if it doesn't exist +db_folder="$(dirname "$0")/../db" +mkdir -p "$db_folder" + +# Create the SQLite database file +db_path="$db_folder/$db_filename" + +# Check if the database file already exists +if [ -f "$db_path" ]; then + if [ "$force_recreate" = true ]; then + # Create a backup of the existing database file with the current date and time + timestamp=$(date +"%Y-%m-%d_%H:%M") + cp "$db_path" "$db_path.$timestamp.bak" + echo "Existing database file backed up as $db_filename.$timestamp.bak" + else + echo "Database file $db_filename already exists. Use -f to force recreate." + exit 0 + fi +fi + +# Create or overwrite the SQLite database file +sqlite3 "$db_path" "VACUUM;" + +# Find the latest SQLite schema file +sql_folder="$(dirname "$0")/../sql" +latest_sql_file=$(ls -1t "$sql_folder"/AccessSystem-Schema*SQLite.sql | head -n 1) + +# Check if the latest SQL file is found +if [ -z "$latest_sql_file" ]; then + echo "No SQLite schema file found in $sql_folder" + exit 1 +fi + +# Run the latest SQL schema file on the database +echo "Initializing database $db_filename with $latest_sql_file...\n" +sqlite3 "$db_path" -cmd ".echo on" ".read $latest_sql_file" + +echo "\nDatabase $db_filename created and initialized with $latest_sql_file" + +# use the .devcontainer/seed-sqlite.sql file to populate the database +seed_sql_file="$(dirname "$0")/seed-sqlite.sql" +if [ -f "$seed_sql_file" ]; then + echo "Seeding database $db_filename with $seed_sql_file...\n" + sqlite3 "$db_path" -cmd ".echo on" ".read $seed_sql_file" + echo "\nDatabase $db_filename seeded with $seed_sql_file" +fi diff --git a/.devcontainer/seed-sqlite.sql b/.devcontainer/seed-sqlite.sql new file mode 100644 index 0000000..2455ac6 --- /dev/null +++ b/.devcontainer/seed-sqlite.sql @@ -0,0 +1,14 @@ +INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions) +VALUES (4, 'Sponsor', 'Access 24hours a day, 365 days a year', 3500, true, true, '{}'); +INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions) +VALUES (3, 'Standard', 'Access 24hours a day, 365 days a year', 2500, true, true, '{}'); +INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions) +VALUES (1, 'MemberOfOtherHackspace', + 'Living outside of Swindon Borough and a fully paid up member of another Maker or Hackspace', 500, false, true, + '{}'); +INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions) +VALUES (2, 'Weekend', 'Access 12:00am Saturday until 12:00am Monday, and Wednesdays 6:30pm to 11:59pm only', 1500, true, + true, + '{"times":[{"from":"3:18:00","to":"3:23:59"},{"from":"6:00:01","to":"6:23:59"},{"from":"7:00:01","to":"7:23:59"}]}'); +INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions) +VALUES (5, 'MensShed', 'Members of Renew only, rate now retired', 1000, false, false, '{}'); diff --git a/.devcontainer/start-services b/.devcontainer/start-services new file mode 100755 index 0000000..3e1d352 --- /dev/null +++ b/.devcontainer/start-services @@ -0,0 +1,17 @@ +#!/bin/bash + +export PERL5LIB="/workspace/AccessSystem/local/lib/perl5/" +# export PATH="/workspace/AccessSystem/local/bin:${PATH}" + +echo "Initializing service configuration..." +.devcontainer/init-config + +echo "Starting services in the background..." + +echo "Starting database admin (RapidApp) @ http://localhost:3001/admin" +carton exec perl script/accesssystem_daemon_devcontainer.pl start + +echo "Starting API server @ http://localhost:3000" +carton exec perl script/accesssystem_api_daemon_devcontainer.pl start + +echo "It may take a few seconds for the services to be up. Please wait..." diff --git a/.gitignore b/.gitignore index 9dde3d4..25baf8e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .plx/ .vscode/perl-lang/ *.code-workspace +.idea/ # exception for email template assets !root/img/*.png diff --git a/script/accesssystem_api_daemon_devcontainer.pl b/script/accesssystem_api_daemon_devcontainer.pl new file mode 100755 index 0000000..dcbb8d5 --- /dev/null +++ b/script/accesssystem_api_daemon_devcontainer.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl +use warnings; +use strict; +use local::lib '/workspaces/AccessSystem/local/lib/perl5/'; +use Daemon::Control; +my $path = "/workspaces/AccessSystem"; + +exit Daemon::Control->new( + name => "AccessSystem-API", + lsb_start => '$syslog $remote_fs', + lsb_stop => '$syslog', + lsb_sdesc => 'AccessSystem API', + lsb_desc => 'AccessSystem API controls the AccessSystem API daemon.', + path => "$path/script/accesssystem_api_daemon_devcontainer.pl", + directory => "$path", +# init_config => "$path etc/environment", + user => 'swmakers', + group => 'swmakers', + program => "carton exec $path/script/accesssystem_api_server.pl --restart --port 3000 > /proc/1/fd/1 2> /proc/1/fd/2", + + pid_file => '/tmp/accesssystem_api.pid', + stderr_file => '/proc/1/fd/2', + stdout_file => '/proc/1/fd/1', + + fork => 2, + + )->run; diff --git a/script/accesssystem_daemon_devcontainer.pl b/script/accesssystem_daemon_devcontainer.pl new file mode 100755 index 0000000..d83d1b3 --- /dev/null +++ b/script/accesssystem_daemon_devcontainer.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl +use warnings; +use strict; +use local::lib '/workspaces/AccessSystem/local/lib/perl5/'; +use Daemon::Control; +my $path = "/workspaces/AccessSystem"; + +exit Daemon::Control->new( + name => "AccessSystem-CRUD", + lsb_start => '$syslog $remote_fs', + lsb_stop => '$syslog', + lsb_sdesc => 'AccessSystem CRUD', + lsb_desc => 'AccessSystem CRUD controls the AccessSystem CRUD daemon.', + path => "$path/script/accesssystem_daemon_devcontainer.pl", + directory => "$path", +# init_config => "$path etc/environment", + user => 'swmakers', + group => 'swmakers', + program => "carton exec $path/script/accesssystem_server.pl --restart --port 3001 > /proc/1/fd/1 2> /proc/1/fd/2", + + pid_file => '/tmp/accesssystem_crud.pid', + stderr_file => '/proc/1/fd/2', + stdout_file => '/proc/1/fd/1', + + fork => 2, + + )->run; From 2011001b6cf9300004bd363bccc909abbe8b3a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Mon, 23 Dec 2024 23:18:00 +0000 Subject: [PATCH 26/28] Remove unused port mapping for MailHog service in docker-compose.yaml --- docker-compose.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 7077aaa..1500f88 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,5 +5,4 @@ services: mailhog: image: mailhog/mailhog ports: - - "1025:1025" - "8025:8025" From 5d5aef4bb429353a7ba2b4d0027a87d732dea07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Mon, 23 Dec 2024 23:57:59 +0000 Subject: [PATCH 27/28] Remove unused access system configuration files --- .devcontainer/config/accesssystem.conf.dev | 21 ------------------- .../config/accesssystem_api.conf.dev | 1 - 2 files changed, 22 deletions(-) delete mode 100644 .devcontainer/config/accesssystem.conf.dev diff --git a/.devcontainer/config/accesssystem.conf.dev b/.devcontainer/config/accesssystem.conf.dev deleted file mode 100644 index c8dd11b..0000000 --- a/.devcontainer/config/accesssystem.conf.dev +++ /dev/null @@ -1,21 +0,0 @@ - - - dsn DBI:SQLite:db/dev.db - - - - site_key 6LdHZx0TAAAAAMuUdG-NScgCCbJ_HMyL1bdeM9vp - secret_key 6LdHZx0TAAAAAEAnQyttqqhDkEVXfUcsnDLPGmvi - - - - mailer SMTP - - host mailhog - port 1025 - sasl_username info@swindon-makerspace.org - sasl_password password - debug 1 - - - diff --git a/.devcontainer/config/accesssystem_api.conf.dev b/.devcontainer/config/accesssystem_api.conf.dev index 4547946..9e06729 100644 --- a/.devcontainer/config/accesssystem_api.conf.dev +++ b/.devcontainer/config/accesssystem_api.conf.dev @@ -1,4 +1,3 @@ -# use_request_uri_for_path 1 using_frontend-proxy 1 From 27ed3091f6806d88b4966f30b672c2014e88dabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C3=96st=C3=B6r?= Date: Sun, 29 Dec 2024 22:40:26 +0000 Subject: [PATCH 28/28] Update OneAll configuration for development environment --- .devcontainer/config/accesssystem_api.conf.dev | 8 ++++---- root/src/login.tt | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.devcontainer/config/accesssystem_api.conf.dev b/.devcontainer/config/accesssystem_api.conf.dev index 9e06729..ddad03e 100644 --- a/.devcontainer/config/accesssystem_api.conf.dev +++ b/.devcontainer/config/accesssystem_api.conf.dev @@ -19,10 +19,10 @@ using_frontend-proxy 1 subdomain swindon-makerspace - domain swindon-makerspace.api.oneall.com - public_key - private_key - callback_url https://localhost/oneall_login_callback + domain mock-login:8080 + public_key + private_key + callback_url http://access-system/oneall_login_callback name access_system diff --git a/root/src/login.tt b/root/src/login.tt index c17f2f7..d614adf 100644 --- a/root/src/login.tt +++ b/root/src/login.tt @@ -2,12 +2,12 @@