Skip to content

Commit 6ff1884

Browse files
ci: update container and build files
fix makefile, fix dockerfile heredoc, add devcontainer extension, remove version from compose file
1 parent b426ba9 commit 6ff1884

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030
"foxundermoon.shell-format",
3131
"GitHub.copilot-chat",
3232
"GitHub.copilot",
33-
"jetpack-io.devbox",
3433
"mads-hartmann.bash-ide-vscode",
3534
"mechatroner.rainbow-csv",
3635
"ms-azuretools.vscode-docker",
36+
"ms-python.debugpy",
3737
"ms-python.python",
3838
"ms-vscode.atom-keybindings",
39-
"redhat.ansible",
4039
"redhat.vscode-yaml",
4140
"ryu1kn.partial-diff",
4241
"timonwong.shellcheck",
@@ -50,7 +49,6 @@
5049
"ghcr.io/devcontainers/features/sshd:1": {},
5150
"ghcr.io/joshuanianji/devcontainer-features/github-cli-persistence:1": {},
5251
"ghcr.io/audacioustux/devcontainers/taskfile:1": {},
53-
"ghcr.io/nikobockerman/devcontainer-features/poetry-persistent-cache:1": {},
5452
"ghcr.io/va-h/devcontainers-features/uv:1": {}
5553
},
5654
"forwardPorts": [

Dockerfile

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# syntax=docker/dockerfile:1.7
1+
# syntax=docker/dockerfile:1.7.0
22

33
# full semver just for python base image
4-
ARG PYTHON_VERSION=3.11.9
4+
ARG PYTHON_VERSION=3.11.11
55

66
FROM python:${PYTHON_VERSION}-slim-bullseye AS builder
77

88
# avoid stuck build due to user prompt
99
ARG DEBIAN_FRONTEND=noninteractive
1010

1111
# update apt-get repos and install dependencies
12-
RUN apt-get -qq update && apt-get -qq install \
13-
--no-install-recommends -y \
12+
RUN apt-get -qq update \
13+
&& apt-get -qq install --no-install-recommends -y \
1414
curl \
1515
gcc \
1616
libpq-dev \
@@ -24,26 +24,29 @@ ENV PIP_DEFAULT_TIMEOUT=100
2424

2525
# poetry env vars
2626
ENV POETRY_HOME="/opt/poetry"
27-
ENV POETRY_VERSION=1.8.3
27+
ENV POETRY_VERSION=1.8.5
2828
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
2929
ENV POETRY_NO_INTERACTION=1
3030

3131
# path
3232
ENV VENV="/opt/venv"
3333
ENV PATH="$POETRY_HOME/bin:$VENV/bin:$PATH"
3434

35+
# create app directory and set as working directory
3536
WORKDIR /app
3637

38+
# copy dependencies
3739
COPY requirements.txt requirements.txt
3840

41+
# install poetry and dependencies
3942
RUN python -m venv $VENV \
4043
&& . "${VENV}/bin/activate" \
4144
&& python -m pip install "poetry==${POETRY_VERSION}" \
4245
&& python -m pip install -r requirements.txt
4346

4447
FROM python:${PYTHON_VERSION}-slim-bullseye AS dev
4548

46-
ENV HOSTNAME="${HOST:-localhost}"
49+
# setup path
4750
ENV VENV="/opt/venv"
4851
ENV PATH="${VENV}/bin:${VENV}/lib/python${PYTHON_VERSION}/site-packages:/usr/local/bin:${HOME}/.local/bin:/bin:/usr/bin:/usr/share/doc:$PATH"
4952

@@ -61,8 +64,8 @@ ENV WEB_CONCURRENCY=2
6164
ARG DEBIAN_FRONTEND=noninteractive
6265

6366
# install dependencies
64-
RUN apt-get -qq update && apt-get -qq install \
65-
--no-install-recommends -y \
67+
RUN apt-get -qq update \
68+
&& apt-get -qq install --no-install-recommends -y \
6669
bat \
6770
curl \
6871
dpkg \
@@ -73,6 +76,7 @@ RUN apt-get -qq update && apt-get -qq install \
7376
p7zip \
7477
perl \
7578
shellcheck \
79+
sudo \
7680
tldr \
7781
tree \
7882
&& rm -rf /var/lib/apt/lists/*
@@ -85,45 +89,55 @@ ARG USER_GID=$USER_UID
8589
RUN groupadd --gid $USER_GID $USER_NAME \
8690
&& useradd --uid $USER_UID --gid $USER_GID -m $USER_NAME
8791

92+
RUN echo "$USER_NAME ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER_NAME \
93+
&& chmod 0440 /etc/sudoers.d/$USER_NAME
94+
95+
# copy virtual environment from builder stage
8896
COPY --from=builder --chown=${USER_NAME}:${USER_GROUP} $VENV $VENV
8997

9098
# qol: tooling
9199
RUN <<EOF
92100
#!/usr/bin/env bash
93-
# gh
94-
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
95-
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
96-
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
97-
apt-get update && apt-get install --no-install-recommends gh -y
98-
apt-get remove dpkg -y
99-
rm -rf /var/lib/apt/lists/*
100-
101101
# fzf
102102
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
103103
yes | ~/.fzf/install
104104
EOF
105105

106+
# switch to non-root user
106107
USER $USER_NAME
107108

108109
# qol: .bashrc
109-
RUN tee -a "$HOME/.bashrc" <<EOF
110+
RUN tee -a "$HOME/.bashrc" <<"EOF"
111+
110112
# shared history
111113
HISTFILE=/var/tmp/.bash_history
112114
HISTFILESIZE=100
113115
HISTSIZE=100
114116

115117
stty -ixon
116118

119+
# fzf
117120
[ -f ~/.fzf.bash ] && . ~/.fzf.bash
118121

122+
# asdf
123+
# https://asdf-vm.com/guide/getting-started.html
124+
export ASDF_DIR="$HOME/.asdf"
125+
[[ -f "${ASDF_DIR}/asdf.sh" ]] && . "${ASDF_DIR}/asdf.sh"
126+
127+
# homebrew
128+
export BREW_PREFIX="/home/linuxbrew/.linuxbrew/bin"
129+
[[ -f "${BREW_PREFIX}/brew" ]] && eval "$(${BREW_PREFIX}/brew shellenv)"
130+
119131
# aliases
120132
alias ..='cd ../'
121133
alias ...='cd ../../'
122134
alias ll='ls -la --color=auto'
135+
123136
EOF
124137

125138
FROM dev AS runner
126139

140+
# change working directory
127141
WORKDIR /app
128142

129143
# $PATH
@@ -132,6 +146,8 @@ ENV PATH=$VENV_PATH/bin:$HOME/.local/bin:$PATH
132146
# port needed by app
133147
EXPOSE 8000
134148

149+
# run container indefinitely
135150
CMD ["sleep", "infinity"]
136151

137-
LABEL org.opencontainers.image.title="mvp"
152+
# metadata
153+
LABEL org.opencontainers.image.title="python-class"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# ENV VARS
88
export SHELL := $(shell which sh)
99
export UNAME := $(shell uname -s)
10-
export ASDF_VERSION := v0.13.1
10+
export ASDF_VERSION := v0.15.0
1111

1212
# check commands and OS
1313
ifeq ($(UNAME), Darwin)
@@ -75,7 +75,7 @@ ifeq ($(UNAME), Darwin)
7575
echo "brew already installed."; \
7676
fi
7777
else ifeq ($(UNAME), Linux)
78-
@if [ "${ID_LIKE}" = "debian" ]; then \
78+
@if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then \
7979
if ! command -v brew >/dev/null 2>&1; then \
8080
echo "Installing Homebrew..."; \
8181
NONINTERACTIVE=1 /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
app:
53
container_name: mvp-app

0 commit comments

Comments
 (0)