From cd2925d7d9d56d83f23adf3804d2cc61c8723f38 Mon Sep 17 00:00:00 2001 From: Jeremy Albright Date: Thu, 14 Mar 2024 14:53:13 -0800 Subject: [PATCH 1/3] feat(devx): integrate dev container Sets up a dev container docker image for cross-platform compatibility and portability of the developer environment --- .devcontainer/Dockerfile | 50 +++++++++++++++ .devcontainer/bootstrap.sh | 60 ++++++++++++++++++ .devcontainer/devcontainer.json | 103 +++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 14 +++++ .devcontainer/extensions.json | 80 ++++++++++++++++++++++++ build-tailwind.sh | 11 ---- 6 files changed, 307 insertions(+), 11 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100755 .devcontainer/bootstrap.sh create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/extensions.json delete mode 100755 build-tailwind.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..8a9a784 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,50 @@ +# Start from a base image +FROM ubuntu:20.04 as base +ARG node_version=20 + +# Install zsh, python, perl, nodejs, and .NET Core +RUN apt-get update && apt-get install -y \ + curl gnupg2 lsb-release \ + zsh python3 perl + +## Setup NodeJS via Volta +ENV PATH="/root/.volta/bin:$PATH" +RUN curl https://get.volta.sh |bash + +RUN volta install "node@$node_version" && \ + volta install pnpm && \ + pnpm setup && \ + pnpm add -g tailwindcss@latest postcss@latest + +## Setup git flow +RUN apt-get update && \ + apt-get install -y git git-flow-avh + +# Install .NET Core SDK +RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +RUN dpkg -i packages-microsoft-prod.deb +RUN apt-get update && \ + apt-get install -y \ + apt-transport-https \ + dotnet-sdk-8.0 + +# Cleanup package manager +RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/ + +# Set zsh as the default shell +RUN chsh -s $(which zsh) + +FROM base as dev + +ENV PROJECT_LOCATION=/workspace/SmartOrder +WORKDIR $PROJECT_LOCATION + +COPY ./.devcontainer/bootstrap.sh /tmp/bootstrap.sh +RUN chmod +x /tmp/bootstrap.sh && /tmp/bootstrap.sh + +VOLUME [\ + "/workspaces/SmartOrder", \ + "/workspaces/SmartOrderApi", \ + "/workspaces/daemon-dotnet" \ +] \ No newline at end of file diff --git a/.devcontainer/bootstrap.sh b/.devcontainer/bootstrap.sh new file mode 100755 index 0000000..4267ab0 --- /dev/null +++ b/.devcontainer/bootstrap.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +# Check if the SmartOrderApi directory exists and is a Git repository +for project in SmartOrderApi daemon-dotnet; do + [[ -d "../$project/.git" ]] && continue; + git clone "$GITHUB_DAEMONTECHTOOLS/$project" "../$project" +done + +## Sanity checking.... +declare -x IN_DOCKER=false IN_VSCODE=false + +### If we are running docker, then the container knows what to do +if [[ -f .dockerenv ]]; then + export IN_DOCKER=true; +fi + +### Same thing as vscode; the extension handles setting things up +if ${VSCODE:-false}; then + export IN_VSCODE=true; +fi + +### Exit early if setup is handled by others +if $IN_DOCKER || $IN_VSCODE; then + exit 0; +fi + +### Otherwise, we need to make we have some dependencies +declare -a deps=( 'docker' 'jq' ); +declare red="" reset="" +red="$(printf "%s\n" 'enacs' 'smacs' 'setaf 1' |tput -S)"; +reset="$(printf "sgr0\nrmacs" |tput -S)"; + +alias printerr='printf "$red%s$reset\n"'; +for dep in "${deps[@]}"; do + if '!' command -v $dep &>/dev/null; then + printerr \ + "Dependency is not installed: '$dep'"\ + "Please install it and try again"; + exit 1 + fi +done + +cd "./.devcontainer" || exit 1; +declare metafl="$PWD/devcontainer.json" +declare -x IMAGENAME="" +IMAGENAME="$(jq -Mr '.service' "$metafl")" + +declare build_image=false; +[[ -z "$(docker images --all -q "$IMAGENAME")" ]] && build_image=true; + +if $build_image; then + declare builder_name="${IMAGENAME}-build"; + docker buildx create --name "$builder_name" --use && + docker buildx bake \ + -f docker-compose.yml \ + --set "*.platform=linux/amd64" \ + --set "*.cache-from=type=registry,ref=${IMAGENAME,,}:cache" \ + --load || + docker buildx rm "$builder_name" +fi \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b25bf10 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,103 @@ +{ + "name": "SmartOrder Container", + "service": "smart-order", + "runServices": ["smart-order"], + "dockerComposeFile": "docker-compose.yml", + "workspaceFolder": "/workspaces/SmartOrder", + "onCreateCommand": "/bin/bash .devcontainer/bootstrap.sh", + "containerEnv": { + "VSCODE": "true" + }, + "mounts": [ + "source=${localWorkspaceFolder}/../,target=/workspaces,type=bind,consistency=cached" + ], + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/zsh" + }, + "extensions": [ + "aaron-bond.better-comments", + "adam-bender.commit-message-editor", + "adrianwilczynski.add-reference", + "adrianwilczynski.asp-net-core-snippet-pack", + "adrianwilczynski.asp-net-core-switcher", + "adrianwilczynski.blazor-snippet-pack", + "adrianwilczynski.namespace", + "alcyon-dev.git-skip", + "alefragnani.bookmarks", + "alefragnani.project-manager", + "aliasadidev.nugetpackagemanagergui", + "andreasarvidsson.bashbook", + "asvetliakov.vscode-neovim", + "austenc.tailwind-docs", + "axetroy.vscode-gpm", + "azsdktm.securityintellisense", + "cake-build.cake-vscode", + "compilouit.manpage", + "corygross.vscode-mdn-docs", + "corylulu.csharp-interpolated-string-converter", + "deitry.msbuild-solution-syntax", + "donjayamanne.githistory", + "dotenv.dotenv-vscode", + "eamodio.gitlens", + "editorconfig.editorconfig", + "eridem.vscode-nupkg", + "eservice-online.vs-sharper", + "felipecaputo.git-project-manager", + "forevolve.git-extensions-for-vs-code", + "foxundermoon.shell-format", + "github.codespaces", + "github.copilot", + "github.copilot-chat", + "github.remotehub", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "gitworktrees.git-worktrees", + "graphite.gti-vscode", + "howardzuo.vscode-git-tags", + "jacknq.texttemplating", + "jetmartin.bats", + "k--kato.docomment", + "k9982874.github-gist-explorer", + "kishoreithadi.dotnet-core-essentials", + "kreativ-software.csharpextensions", + "lambdageek.msbuild-structured-log-viewer", + "leo-labs.dotnet", + "linjun.git-graph-pro", + "mads-hartmann.bash-ide-vscode", + "meronz.manpages", + "mhutchie.git-graph", + "micnil.vscode-checkpoints", + "ms-azuretools.vscode-docker", + "ms-dotnettools.blazorwasm-companion", + "ms-dotnettools.csdevkit", + "ms-dotnettools.csharp", + "ms-dotnettools.vscode-dotnet-runtime", + "ms-python.python", + "ms-vscode-remote.remote-containers", + "ms-vscode-remote.remote-wsl", + "ms-vscode-remote.vscode-remote-extensionpack", + "ms-vscode.azure-repos", + "ms-vscode.mono-debug", + "ms-vscode.node-debug2", + "ms-vscode.remote-explorer", + "ms-vscode.remote-repositories", + "ms-vscode.remote-server", + "pomber.git-file-history", + "rogalmic.bash-debug", + "rogalmic.vscode-xml-complete", + "shakram02.bash-beautify", + "shd101wyy.markdown-preview-enhanced", + "shyykoserhiy.git-autoconfig", + "timonwong.shellcheck", + "tintoy.msbuild-project-tools", + "tombonnike.vscode-status-bar-format-toggle", + "vivaxy.vscode-conventional-commits", + "zbecknell.t4-support", + "ziyasal.vscode-open-in-github", + "zxh404.vscode-proto3" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..0446266 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' +services: + smart-order: + image: ${IMAGENAME}:latest + build: + context: .. + dockerfile: ./.devcontainer/Dockerfile + volumes: + - ../SmartOrderApi:/workspaces/SmartOrderApi + - ../daemon-dotnet:/workspaces/daemon-dotnet + ports: + - "3000:3000" + environment: + SHELL: "/usr/bin/bash" \ No newline at end of file diff --git a/.devcontainer/extensions.json b/.devcontainer/extensions.json new file mode 100644 index 0000000..24be038 --- /dev/null +++ b/.devcontainer/extensions.json @@ -0,0 +1,80 @@ +[ + "aaron-bond.better-comments", + "adam-bender.commit-message-editor", + "adrianwilczynski.add-reference", + "adrianwilczynski.asp-net-core-snippet-pack", + "adrianwilczynski.asp-net-core-switcher", + "adrianwilczynski.blazor-snippet-pack", + "adrianwilczynski.namespace", + "alcyon-dev.git-skip", + "alefragnani.bookmarks", + "alefragnani.project-manager", + "aliasadidev.nugetpackagemanagergui", + "andreasarvidsson.bashbook", + "asvetliakov.vscode-neovim", + "austenc.tailwind-docs", + "axetroy.vscode-gpm", + "azsdktm.securityintellisense", + "cake-build.cake-vscode", + "compilouit.manpage", + "corygross.vscode-mdn-docs", + "corylulu.csharp-interpolated-string-converter", + "deitry.msbuild-solution-syntax", + "donjayamanne.githistory", + "dotenv.dotenv-vscode", + "eamodio.gitlens", + "editorconfig.editorconfig", + "eridem.vscode-nupkg", + "eservice-online.vs-sharper", + "felipecaputo.git-project-manager", + "forevolve.git-extensions-for-vs-code", + "foxundermoon.shell-format", + "github.codespaces", + "github.copilot", + "github.copilot-chat", + "github.remotehub", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "gitworktrees.git-worktrees", + "graphite.gti-vscode", + "howardzuo.vscode-git-tags", + "jacknq.texttemplating", + "jetmartin.bats", + "k--kato.docomment", + "k9982874.github-gist-explorer", + "kishoreithadi.dotnet-core-essentials", + "kreativ-software.csharpextensions", + "lambdageek.msbuild-structured-log-viewer", + "leo-labs.dotnet", + "linjun.git-graph-pro", + "mads-hartmann.bash-ide-vscode", + "meronz.manpages", + "mhutchie.git-graph", + "micnil.vscode-checkpoints", + "ms-azuretools.vscode-docker", + "ms-dotnettools.blazorwasm-companion", + "ms-dotnettools.csdevkit", + "ms-dotnettools.csharp", + "ms-dotnettools.vscode-dotnet-runtime", + "ms-vscode-remote.remote-containers", + "ms-vscode-remote.remote-wsl", + "ms-vscode-remote.vscode-remote-extensionpack", + "ms-vscode.azure-repos", + "ms-vscode.mono-debug", + "ms-vscode.remote-explorer", + "ms-vscode.remote-repositories", + "ms-vscode.remote-server", + "pomber.git-file-history", + "rogalmic.bash-debug", + "rogalmic.vscode-xml-complete", + "shakram02.bash-beautify", + "shd101wyy.markdown-preview-enhanced", + "shyykoserhiy.git-autoconfig", + "timonwong.shellcheck", + "tintoy.msbuild-project-tools", + "tombonnike.vscode-status-bar-format-toggle", + "vivaxy.vscode-conventional-commits", + "zbecknell.t4-support", + "ziyasal.vscode-open-in-github", + "zxh404.vscode-proto3" +] \ No newline at end of file diff --git a/build-tailwind.sh b/build-tailwind.sh deleted file mode 100755 index c13bfd4..0000000 --- a/build-tailwind.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -appStylesPathIn="./Styles/styles.css" -appStylesPathOut="./wwwroot/css/site.css" - -if [ -z ${TAILWINDCSS_PATH} ]; then - # Not set, so use default - TAILWINDCSS_PATH=$(which tailwindcss) -fi - -$TAILWINDCSS_PATH -i $appStylesPathIn -o $appStylesPathOut $@ \ No newline at end of file From 98e1973b4339d6872094a7a83bb207af9abe132e Mon Sep 17 00:00:00 2001 From: Jeremy Albright Date: Thu, 14 Mar 2024 15:08:38 -0800 Subject: [PATCH 2/3] fix(devcontainer): fix node package management * Added the SHELL environment variable to make pnpm happy * Removed extraneous dependencies, like perl, python, and zsh * If desired, those could be added later --- .devcontainer/Dockerfile | 23 ++++++++++++++--------- .devcontainer/docker-compose.yml | 9 ++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8a9a784..436777f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,25 +1,30 @@ # Start from a base image FROM ubuntu:20.04 as base -ARG node_version=20 +ARG SHELL="/usr/bin/bash" +ARG NODE_VERSION=20 + +## Set up other repositories +RUN apt-get update && \ + apt-get install -y software-properties-common && \ + ## git-flow-avh + add-apt-repository -y ppa:git-core/ppa # Install zsh, python, perl, nodejs, and .NET Core RUN apt-get update && apt-get install -y \ curl gnupg2 lsb-release \ - zsh python3 perl + git git-flow ## Setup NodeJS via Volta ENV PATH="/root/.volta/bin:$PATH" +ENV SHELL=${SHELL} RUN curl https://get.volta.sh |bash -RUN volta install "node@$node_version" && \ +RUN volta install "node@$NODE_VERSION" && \ volta install pnpm && \ pnpm setup && \ + . /root/.bashrc && \ pnpm add -g tailwindcss@latest postcss@latest -## Setup git flow -RUN apt-get update && \ - apt-get install -y git git-flow-avh - # Install .NET Core SDK RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb RUN dpkg -i packages-microsoft-prod.deb @@ -32,8 +37,8 @@ RUN apt-get update && \ RUN apt-get clean && \ rm -rf /var/lib/apt/lists/ -# Set zsh as the default shell -RUN chsh -s $(which zsh) +# Set bash as the default shell +RUN chsh -s $(which bash) FROM base as dev diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 0446266..72e455d 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -5,10 +5,13 @@ services: build: context: .. dockerfile: ./.devcontainer/Dockerfile + args: + SHELL: "/usr/bin/bash" + NODE_VERSION: "20" + environment: + SHELL: "/usr/bin/bash" volumes: - ../SmartOrderApi:/workspaces/SmartOrderApi - ../daemon-dotnet:/workspaces/daemon-dotnet ports: - - "3000:3000" - environment: - SHELL: "/usr/bin/bash" \ No newline at end of file + - "3000:3000" \ No newline at end of file From 6f7f438bf16f76b76f91bd3aa447f2ef46229714 Mon Sep 17 00:00:00 2001 From: Jeremy Albright Date: Thu, 14 Mar 2024 15:10:55 -0800 Subject: [PATCH 3/3] fix(devcontainer): add wget --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 436777f..3c7a66d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -11,7 +11,7 @@ RUN apt-get update && \ # Install zsh, python, perl, nodejs, and .NET Core RUN apt-get update && apt-get install -y \ - curl gnupg2 lsb-release \ + curl wget gnupg2 lsb-release \ git git-flow ## Setup NodeJS via Volta