Skip to content

Commit 0167a41

Browse files
committed
Add devcontainer for working on windows
1 parent 582b56d commit 0167a41

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

.devcontainer/Dockerfile

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
FROM node:12
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# The node image includes a non-root user with sudo access. Use the
12+
# "remoteUser" property in devcontainer.json to use it. On Linux, update
13+
# these values to ensure the container user's UID/GID matches your local values.
14+
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
15+
ARG USERNAME=node
16+
ARG USER_UID=1000
17+
ARG USER_GID=$USER_UID
18+
19+
# Configure apt and install packages
20+
RUN apt-get update \
21+
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
22+
#
23+
# Verify git and needed tools are installed
24+
&& apt-get -y install git iproute2 procps \
25+
#
26+
# Remove outdated yarn from /opt and install via package
27+
# so it can be easily updated via apt-get upgrade yarn
28+
&& rm -rf /opt/yarn-* \
29+
&& rm -f /usr/local/bin/yarn \
30+
&& rm -f /usr/local/bin/yarnpkg \
31+
&& apt-get install -y curl apt-transport-https lsb-release \
32+
&& curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
33+
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
34+
&& apt-get update \
35+
&& apt-get -y install --no-install-recommends yarn tmux locales \
36+
#
37+
# Install eslint globally
38+
&& npm install -g eslint \
39+
#
40+
# [Optional] Update a non-root user to UID/GID if needed.
41+
&& if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
42+
groupmod --gid $USER_GID $USERNAME \
43+
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
44+
&& chown -R $USER_UID:$USER_GID /home/$USERNAME; \
45+
fi \
46+
# [Optional] Add add sudo support for non-root user
47+
&& apt-get install -y sudo \
48+
&& echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
49+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
50+
#
51+
# Clean up
52+
&& apt-get autoremove -y \
53+
&& apt-get clean -y \
54+
&& rm -rf /var/lib/apt/lists/*
55+
56+
RUN curl https://raw.githubusercontent.com/brianc/dotfiles/master/.tmux.conf > ~/.tmux.conf
57+
58+
# install nvm
59+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
60+
61+
# Set the locale
62+
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
63+
ENV LANG en_US.UTF-8
64+
ENV LANGUAGE en_US:en
65+
ENV LC_ALL en_US.UTF-8
66+
67+
# Switch back to dialog for any ad-hoc use of apt-get
68+
ENV DEBIAN_FRONTEND=dialog

.devcontainer/devcontainer.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
2+
{
3+
"name": "Node.js 12 & Postgres",
4+
"dockerComposeFile": "docker-compose.yml",
5+
"service": "web",
6+
"workspaceFolder": "/workspace",
7+
8+
// Use 'settings' to set *default* container specific settings.json values on container create.
9+
// You can edit these settings after create using File > Preferences > Settings > Remote.
10+
"settings": {
11+
"terminal.integrated.shell.linux": "/bin/bash"
12+
},
13+
14+
// Uncomment the next line if you want start specific services in your Docker Compose config.
15+
// "runServices": [],
16+
17+
// Uncomment the line below if you want to keep your containers running after VS Code shuts down.
18+
// "shutdownAction": "none",
19+
20+
// Uncomment the next line to run commands after the container is created.
21+
// "postCreateCommand": "npm install",
22+
23+
// Uncomment the next line to have VS Code connect as an existing non-root user in the container. See
24+
// https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist.
25+
// "remoteUser": "node",
26+
27+
// Add the IDs of extensions you want installed when the container is created in the array below.
28+
"extensions": [
29+
"dbaeumer.vscode-eslint"
30+
]
31+
}

.devcontainer/docker-compose.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
version: '3'
7+
services:
8+
web:
9+
# Uncomment the next line to use a non-root user for all processes. You can also
10+
# simply use the "remoteUser" property in devcontainer.json if you just want VS Code
11+
# and its sub-processes (terminals, tasks, debugging) to execute as the user. On Linux,
12+
# you may need to update USER_UID and USER_GID in .devcontainer/Dockerfile to match your
13+
# user if not 1000. See https://aka.ms/vscode-remote/containers/non-root for details.
14+
# user: node
15+
16+
build:
17+
context: .
18+
dockerfile: Dockerfile
19+
20+
volumes:
21+
- ..:/workspace:cached
22+
23+
environment:
24+
PGPASSWORD: pass
25+
PGUSER: user
26+
PGDATABASE: data
27+
PGHOST: db
28+
29+
# Overrides default command so things don't shut down after the process ends.
30+
command: sleep infinity
31+
32+
links:
33+
- db
34+
35+
db:
36+
image: postgres
37+
restart: unless-stopped
38+
ports:
39+
- 5432:5432
40+
environment:
41+
POSTGRES_PASSWORD: pass
42+
POSTGRES_USER: user
43+
POSTGRES_DB: data
44+

0 commit comments

Comments
 (0)