Last active
March 23, 2024 20:02
-
-
Save chrisliatas/b85185bae184f612c35a3197fc3a5389 to your computer and use it in GitHub Desktop.
Multi stage Dockerfile to create a development environment. Can be combined with vs code `devcontainers`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Variables | |
ARG VARIANT="3" | |
ARG VARIANT_SFX="-slim" | |
ARG FONTS_VERSION="3.1.1" | |
# Builder | |
FROM python:${VARIANT} as builder | |
ENV PYTHONFAULTHANDLER=1 \ | |
PYTHONHASHSEED=random \ | |
PYTHONUNBUFFERED=1 \ | |
PIP_DEFAULT_TIMEOUT=100 \ | |
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
PIP_NO_CACHE_DIR=1 | |
RUN apt-get update && apt-get -y update && \ | |
apt-get install -y --no-install-suggests --no-install-recommends pipx | |
# Install poetry | |
RUN python3 -m pip install --user pipx && \ | |
python3 -m pipx ensurepath && \ | |
pipx install poetry && \ | |
pipx inject poetry poetry-plugin-bundle | |
COPY requirements.txt . | |
RUN pip install -r requirements.txt | |
FROM python:${VARIANT}${VARIANT_SFX} | |
ARG VARIANT | |
ARG FONTS_VERSION | |
COPY --from=builder /usr/local/lib/python${VARIANT}/site-packages /usr/local/lib/python${VARIANT}/site-packages | |
COPY --from=builder /usr/local/bin /usr/local/bin | |
# Update and install necessary packages | |
RUN apt-get update && apt-get -y update && \ | |
apt-get install -y --no-install-suggests --no-install-recommends sudo zsh curl git npm vim wget unzip fontconfig && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* | |
# add git lhs to apt | |
# RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash | |
# Download and install Fira Code Nerd Font | |
RUN mkdir -p /usr/share/fonts/FiraCode && \ | |
wget -qO FiraCode.zip "https://github.com/ryanoasis/nerd-fonts/releases/download/v${FONTS_VERSION}/FiraCode.zip" && \ | |
unzip FiraCode.zip -d /usr/share/fonts/FiraCode && \ | |
rm FiraCode.zip && \ | |
fc-cache -fv | |
# Setup a non-root user '$USERNAME' with sudo access | |
ARG USERNAME="vscode" | |
ARG USER_UID=1000 | |
ARG USER_GID=$USER_UID | |
RUN groupadd --gid $USER_GID $USERNAME \ | |
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ | |
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ | |
&& chmod 0440 /etc/sudoers.d/$USERNAME | |
USER $USERNAME | |
WORKDIR /home/$USERNAME | |
# Set environment variable | |
# ARG OPENAIAPIKEY="your_key_here" | |
# ENV OPENAI_API_KEY=${OPENAIAPIKEY} | |
# Install oh-my-zsh & friends - OPTIONAL | |
ENV ZSH_CUSTOM=/home/$USERNAME/.oh-my-zsh/custom | |
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended | |
# Install zsh-autosuggestions | |
RUN git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions | |
# Install zsh-completions | |
RUN git clone https://github.com/zsh-users/zsh-completions $ZSH_CUSTOM/plugins/zsh-completions | |
# Install zsh-syntax-highlighting | |
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting | |
# Install spaceship-prompt theme | |
RUN git clone --depth=1 https://github.com/spaceship-prompt/spaceship-prompt.git $ZSH_CUSTOM/themes/spaceship-prompt && \ | |
ln -s $ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme $HOME/.oh-my-zsh/themes/spaceship.zsh-theme | |
# Configure .zshrc for spaceship | |
RUN echo 'ZSH_THEME="spaceship"' >> ~/.zshrc && \ | |
echo '\n# Spaceship Prompt customization\nSPACESHIP_PROMPT_ORDER=(user dir git host)' >> ~/.zshrc | |
RUN echo "source $HOME/.oh-my-zsh/oh-my-zsh.sh" >> ~/.zshrc \ | |
&& echo "plugins=(git zsh-autosuggestions zsh-completions)" >> ~/.zshrc | |
# Install Quarto - OPTIONAL | |
ARG QUARTO_REL="1.5.25" | |
RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \ | |
wget -q https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_REL}/quarto-${QUARTO_REL}-linux-${arch}.tar.gz && \ | |
mkdir -p /home/${USERNAME}/quarto/ && \ | |
tar -xzf quarto-${QUARTO_REL}-linux-${arch}.tar.gz --directory /home/${USERNAME}/quarto/ && \ | |
rm quarto-${QUARTO_REL}-linux-${arch}.tar.gz | |
ENV PATH="${PATH}:/home/${USERNAME}/quarto/quarto-${QUARTO_REL}/bin/" | |
# Set the default command to zsh | |
CMD ["/usr/bin/zsh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Combine in vs code
.devcontainers
with thisdevcontainer.json