fapi/Dockerfile

84 lines
2.7 KiB
Docker

# Choose a base image. Debian is a good choice due to pyenv
FROM debian:latest
# Update the package list and install necessary dependencies
RUN apt-get update && apt-get install -y \
aptitude \
tmux vim-nox nano mc git curl termshark procps \
sudo iproute2 iputils-ping bridge-utils \
ifupdown udev make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget llvm libncurses5-dev \
libncursesw5-dev xz-utils libffi-dev liblzma-dev \
sqlite3 default-libmysqlclient-dev pkg-config \
python3-pip \
npm
# Set password for root user (optional, for configuration)
RUN echo 'root:rootpass' | chpasswd
# Add a new user `user` with password `pass` and prepare the environment
RUN useradd -m user && echo 'user:pass' | chpasswd && adduser user sudo
# Switch to user `user`
USER user
WORKDIR /home/user
# Install pyenv
RUN git clone https://github.com/pyenv/pyenv .pyenv
# Install pyenv-virtualenv
RUN git clone https://github.com/pyenv/pyenv-virtualenv .pyenv/plugins/pyenv-virtualenv
# Set environment variables
ENV HOME /home/user
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
# Add pyenv and pyenv-virtualenv configuration to .bashrc
RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> .bashrc
RUN echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> .bashrc
RUN echo 'eval "$(pyenv init -)"' >> .bashrc
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> .bashrc
# Install Python 3.12 with --enable-shared
RUN bash -i -c "source ~/.bashrc && env PYTHON_CONFIGURE_OPTS='--enable-shared' pyenv install 3.12"
# Create a virtual environment p3.12
RUN bash -i -c "source ~/.bashrc && pyenv virtualenv 3.12 p3.12"
# Set p3.12 as the default virtual environment
RUN bash -i -c "source ~/.bashrc && pyenv local p3.12"
# Install ipython in the p3.12 environment
RUN bash -i -c "source ~/.bashrc && pyenv activate p3.12 && pip install ipython"
# Install Vim-Plug for Vim plugin management
RUN curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# Copy the vim configuration file for plugins
COPY ./_confs/.vimrc /home/user/.vimrc
# Install Vim plugins via Vim-Plug
RUN vim +'PlugInstall --sync' +qall
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 -
# Copy the project into the image
COPY --chown=user:user . /home/user/fapi
COPY ./_confs/* ./
# Set the working directory for installing dependencies
WORKDIR /home/user/fapi
# Add Poetry path to PATH directly in the Dockerfile
ENV PATH="$HOME/.local/bin:$PATH"
# Install dependencies using Poetry
RUN bash -i -c "source ~/.bashrc && poetry config virtualenvs.create false && poetry install"
# Run the application
CMD ["/bin/bash", "-c", "python entrypoint.py"]