Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integrate-dev-container #11

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Start from a base image
FROM ubuntu:20.04 as base
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 wget gnupg2 lsb-release \
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" && \
volta install pnpm && \
pnpm setup && \
. /root/.bashrc && \
pnpm add -g tailwindcss@latest postcss@latest

# 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 bash as the default shell
RUN chsh -s $(which bash)

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" \
]
60 changes: 60 additions & 0 deletions .devcontainer/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need this mechanism explained to me. The difference of running in Docker, Vs Code or neither. Maybe we can get on a call tomorrow?

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
103 changes: 103 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mounting whatever folder contains all your projects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the goal, yes. I figure that the parent folder of the SmartOrder project would the one. Alternatively, we could have a different repo host them all, and this stuff would just sit in the top of it. The other 3 could be subrepositories

],
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/zsh"
},
"extensions": [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all the vs code plugins you're bundling in the container? I thought vs code was still running locally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not bundling. These are just settings that get loaded when you load the container. This tells vscode to install these extensions (but only in the context of the container).

There's still a few in here I meant to remove, I just noticed...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's kinda what I meant. Inside the container, vs code is being bundled with all those extensions. I'll read more on Dev Containers but clarification on them is a big part of our call today.

"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"
]
}
}
}
17 changes: 17 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'
services:
smart-order:
image: ${IMAGENAME}:latest
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"
80 changes: 80 additions & 0 deletions .devcontainer/extensions.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extensions need to be duplicated here and in devcontainer.json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file actually needs to go away

Original file line number Diff line number Diff line change
@@ -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"
]
11 changes: 0 additions & 11 deletions build-tailwind.sh

This file was deleted.