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
66FROM python:${PYTHON_VERSION}-slim-bullseye AS builder
77
88# avoid stuck build due to user prompt
99ARG 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
2626ENV POETRY_HOME="/opt/poetry"
27- ENV POETRY_VERSION=1.8.3
27+ ENV POETRY_VERSION=1.8.5
2828ENV POETRY_VIRTUALENVS_IN_PROJECT=true
2929ENV POETRY_NO_INTERACTION=1
3030
3131# path
3232ENV VENV="/opt/venv"
3333ENV PATH="$POETRY_HOME/bin:$VENV/bin:$PATH"
3434
35+ # create app directory and set as working directory
3536WORKDIR /app
3637
38+ # copy dependencies
3739COPY requirements.txt requirements.txt
3840
41+ # install poetry and dependencies
3942RUN 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
4447FROM python:${PYTHON_VERSION}-slim-bullseye AS dev
4548
46- ENV HOSTNAME= "${HOST:-localhost}"
49+ # setup path
4750ENV VENV="/opt/venv"
4851ENV 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
6164ARG 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
8589RUN 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
8896COPY --from=builder --chown=${USER_NAME}:${USER_GROUP} $VENV $VENV
8997
9098# qol: tooling
9199RUN <<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
102102git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
103103yes | ~/.fzf/install
104104EOF
105105
106+ # switch to non-root user
106107USER $USER_NAME
107108
108109# qol: .bashrc
109- RUN tee -a "$HOME/.bashrc" <<EOF
110+ RUN tee -a "$HOME/.bashrc" <<"EOF"
111+
110112# shared history
111113HISTFILE=/var/tmp/.bash_history
112114HISTFILESIZE=100
113115HISTSIZE=100
114116
115117stty -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
120132alias ..='cd ../'
121133alias ...='cd ../../'
122134alias ll='ls -la --color=auto'
135+
123136EOF
124137
125138FROM dev AS runner
126139
140+ # change working directory
127141WORKDIR /app
128142
129143# $PATH
@@ -132,6 +146,8 @@ ENV PATH=$VENV_PATH/bin:$HOME/.local/bin:$PATH
132146# port needed by app
133147EXPOSE 8000
134148
149+ # run container indefinitely
135150CMD ["sleep" , "infinity" ]
136151
137- LABEL org.opencontainers.image.title="mvp"
152+ # metadata
153+ LABEL org.opencontainers.image.title="python-class"
0 commit comments