Skip to content

Commit dcf5b80

Browse files
Add devcontainer
1 parent 4cc2ac6 commit dcf5b80

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# syntax=docker/dockerfile:1.6
2+
3+
# full semver just for python base image
4+
ARG PYTHON_VERSION=3.11.4
5+
6+
FROM python:${PYTHON_VERSION}-slim-bullseye AS builder
7+
8+
# avoid stuck build due to user prompt
9+
ARG DEBIAN_FRONTEND=noninteractive
10+
11+
# update apt repos and install dependencies
12+
RUN apt -qq update && apt -qq install \
13+
--no-install-recommends -y \
14+
curl \
15+
gcc \
16+
libpq-dev \
17+
python3-dev \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# pip env vars
21+
ENV PIP_NO_CACHE_DIR=off
22+
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
23+
ENV PIP_DEFAULT_TIMEOUT=100
24+
25+
# poetry env vars
26+
ENV POETRY_HOME="/opt/poetry"
27+
ENV POETRY_VERSION=1.5.1
28+
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
29+
ENV POETRY_NO_INTERACTION=1
30+
31+
# path
32+
ENV VENV="/opt/venv"
33+
ENV PATH="$POETRY_HOME/bin:$VENV/bin:$PATH"
34+
35+
RUN python -m venv $VENV \
36+
&& . "${VENV}/bin/activate" \
37+
&& python -m pip install "poetry==${POETRY_VERSION}"
38+
39+
FROM python:${PYTHON_VERSION}-slim-bullseye AS runner
40+
41+
# setup standard non-root user for use downstream
42+
ENV USER_NAME=appuser
43+
ENV USER_GROUP=appuser
44+
ENV HOME="/home/${USER_NAME}"
45+
ENV HOSTNAME="${HOST:-localhost}"
46+
ENV VENV="/opt/venv"
47+
48+
ENV PATH="${VENV}/bin:${VENV}/lib/python${PYTHON_VERSION}/site-packages:/usr/local/bin:${HOME}/.local/bin:/bin:/usr/bin:/usr/share/doc:$PATH"
49+
50+
# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
51+
ENV LANG C.UTF-8
52+
ENV LC_ALL C.UTF-8
53+
ENV PYTHONDONTWRITEBYTECODE 1
54+
ENV PYTHONFAULTHANDLER 1
55+
56+
# workers per core
57+
# https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker/blob/master/README.md#web_concurrency
58+
ENV WEB_CONCURRENCY=2
59+
60+
# avoid stuck build due to user prompt
61+
ARG DEBIAN_FRONTEND=noninteractive
62+
63+
# install dependencies
64+
RUN apt -qq update && apt -qq install \
65+
--no-install-recommends -y \
66+
bat \
67+
curl \
68+
dpkg \
69+
git \
70+
lsof \
71+
p7zip \
72+
perl \
73+
tldr \
74+
tree \
75+
&& rm -rf /var/lib/apt/lists/*
76+
77+
RUN groupadd ${USER_NAME} \
78+
&& useradd -m ${USER_NAME} -g ${USER_GROUP}
79+
80+
USER $USER_NAME
81+
WORKDIR $HOME
82+
83+
COPY --from=builder --chown=nonroot:nonroot $VENV $VENV
84+
85+
# qol: tooling
86+
RUN <<EOF
87+
#!/usr/bin/env bash
88+
# gh
89+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
90+
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
91+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
92+
apt update && apt install gh -y
93+
apt remove dpkg -y
94+
rm -rf /var/lib/apt/lists/*
95+
96+
# fzf
97+
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
98+
yes | ~/.fzf/install
99+
EOF
100+
101+
# qol: .bashrc
102+
RUN <<EOF tee -a $HOME/.bashrc
103+
# shared history
104+
HISTFILE=/var/tmp/.bash_history
105+
HISTFILESIZE=100
106+
HISTSIZE=100
107+
108+
stty -ixon
109+
110+
[ -f ~/.fzf.bash ] && . ~/.fzf.bash
111+
112+
# aliases
113+
alias ..='cd ../'
114+
alias ...='cd ../../'
115+
alias ll='ls -la --color=auto'
116+
EOF
117+
118+
# $PATH
119+
ENV PATH=$VENV_PATH/bin:$HOME/.local/bin:$PATH
120+
121+
CMD ["sleep", "infinity"]

.devcontainer/devcontainer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "Python 3",
5+
"build": {
6+
"dockerfile": "Dockerfile"
7+
},
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"aaron-bond.better-comments",
12+
"bradlc.vscode-tailwindcss",
13+
"eamodio.gitlens",
14+
"EditorConfig.EditorConfig",
15+
"GitHub.copilot-chat",
16+
"GitHub.copilot",
17+
"hashicorp.terraform",
18+
"ms-azuretools.vscode-docker",
19+
"ms-python.python",
20+
"ms-vscode.atom-keybindings",
21+
"ms-vscode.live-server",
22+
"ms-vsliveshare.vsliveshare",
23+
"redhat.vscode-yaml",
24+
"streetsidesoftware.code-spell-checker"
25+
]
26+
}
27+
},
28+
"forwardPorts": [
29+
8080,
30+
8081
31+
]
32+
}

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ repos:
5252
# https://pre-commit.com/#regular-expressions
5353
exclude: |
5454
(?x)^(
55+
.devcontainer/devcontainer.json|
5556
.vscode/launch.json|
5657
.vscode/settings.json
5758
)$

0 commit comments

Comments
 (0)