Skip to content

Commit

Permalink
Merge pull request #5 from cogent3/devcontainer
Browse files Browse the repository at this point in the history
Docker container
  • Loading branch information
GavinHuttley authored Jun 5, 2024
2 parents f39cbe0 + e130457 commit bc7fc91
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .devcontainer/DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Use continuumio/miniconda3 as the base image
FROM continuumio/miniconda3

LABEL maintainer="Richard Morris <[email protected]>"

# Install required packages
RUN apt-get update -q && \
apt-get install -q -y --no-install-recommends \
git \
zsh \
wget \
curl \
sudo \
openssh-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Set up a non-root user with sudo access
RUN useradd -m user && \
echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Switch to the non-root user
USER user
WORKDIR /home/user

# Set up zsh as the default shell
SHELL ["/bin/zsh", "-c"]

# Install Oh My Zsh
RUN sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --unattended

# Install zsh autosuggestions
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# Install zsh syntax highlighting
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# Configure zsh
RUN sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' ~/.zshrc

# Create a new conda environment with Python 3.12
RUN source /opt/conda/etc/profile.d/conda.sh && \
/opt/conda/bin/conda create -n c312 python=3.12 -y && \
conda activate c312


# Initialize conda for zsh shell
RUN echo "source /opt/conda/etc/profile.d/conda.sh" >> ~/.zshrc && \
echo "conda activate c312" >> ~/.zshrc

# Clone the repositories using SSH
WORKDIR /home/user/repos
RUN git clone --branch develop https://github.com/cogent3/cogent3.git /home/$USERNAME/repos/cogent3 && \
git clone --branch master https://github.com/cogent3/EnsemblLite.git /home/$USERNAME/repos/EnsemblLite

# Install flit in the conda environment
RUN source /opt/conda/etc/profile.d/conda.sh && \
conda activate c312 && \
conda install -c conda-forge flit -y

# Install the repositories using flit
RUN source /opt/conda/etc/profile.d/conda.sh && \
conda activate c312 && \
cd /home/user/repos/cogent3 && \
flit install -s && \
cd /home/user/repos/EnsemblLite && \
flit install -s

# Start in the home directory
WORKDIR /home/user

# Set zsh as the default shell for the container
CMD [ "zsh" ]
36 changes: 36 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Cogent3 workshop Development container for cogent3 and EnsemblLite

This folder contains a Docker configuration file for setting up the workshop environment for working with `cogent3` and `EnsemblLite` in a docker container, and a `devcontainer.json` configuration so that VS Code can manage the container. The container installs the develop branch of `cogent3`, and the master branch of `EnsemblLite`. It also pre-populates VS code extensions for jupiter notebooks and for working with python.

For instructions for building this docker image into a container to run the workshop, see the [Computer setup instructions](https://github.com/cogent3/Cogent3Workshop/wiki/Computer-Setup).

## Configuring Resource Allocation

You can configure the resource used for the development container by modifying the `devcontainer.json` file. This file allows you to specify the number of CPUs and the amount of RAM the container can use.

Steps

- Open the devcontainer.json file in your editor.
- Look for the runArgs property. by default it is set to ` "runArgs": ["--cpus", "2", "-m", "4g"],`, which is 2 cpu and 4GB of RAM.
- To limit the number of CPUs the container can use, add "--cpus" and your desired number of CPUs to the runArgs array.
- To limit the amount of RAM the container can use, add "-m" and "4g" (or your desired amount of RAM) to the runArgs array.

Please note that these settings will only limit the maximum resources a container can use. The container will use less resources if it doesn't need the maximum amount. Also, please make sure that your Docker host has enough resources to allocate to the container. If the host doesn't have enough resources, the container may not start.

## Container description

This development container is designed to provide a consistent and reproducible development environment for working with the `cogent3` and `EnsemblLite` Python packages. It is based on a slim Debian image and includes a variety of tools and configurations to facilitate development.

- Base Image: The base image is continuumIO/miniconda3 which is based on debian:bookworm-slim, a slim version of the latest Debian release.
- Python: Python 3.12 is installed and set as the default Python version.
- Non-root User: A non-root user named user is created for running the container. This is a good security practice.
- Repositories: The cogent3 and EnsemblLite repositories are cloned into the /home/user/repos directory.
- Conda Environment: A new conda environment named c312 is created with Python 3.12. This environment is activated when a new shell is started.
- Packages: Flit is installed in the c312 environment
- `cogent3` and `EnsemblLite`: The `cogent3` and `EnsemblLite` packages are installed from the cloned repositories in the c312 environment using flit.
- Zsh and Oh My Zsh: The Zsh shell is installed and set as the default shell. Oh My Zsh is installed for additional shell features and configurations. Several plugins are enabled, including git, zsh-autosuggestions, zsh-syntax-highlighting, and autojump.

## Using the Container

To use the container, you can load your clone of the workshop repository in VS-Code and you will be asked if you want to run in a devcontainer. When you select yes, VS-Code will rebuild the container, start it, remote connect into the container, and open a new VS-Code window in the container. You can then open a terminal in the container and you should automatically be in the zsh shell, in the mamba c312 environment, logged in as the user `User`, and in the directory /workspaces/$workshopname$ with the workshop files. You can navigate to the the /home/user/repos directory to access the cogent3 and EnsemblLite repositories.

24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Cogent3 Workshop",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"runArgs": ["--cpus", "2", "-m", "4g"],
"
settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "zsh"
}
},
"python.defaultInterpreterPath": "/home/user/.conda/envs/c312/bin/python",
},
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter"
],
"remoteUser": "user",
"postStartCommand": "echo 'Cogent3 Workshop 2024 environment is ready!'"
}

0 comments on commit bc7fc91

Please sign in to comment.