Skip to content

Commit

Permalink
Merge pull request #22 from guzman-raphael/reduce-image
Browse files Browse the repository at this point in the history
Optimize DevContainer
  • Loading branch information
guzman-raphael authored Mar 22, 2023
2 parents a92e972 + 77e420f commit bee49f7
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 50 deletions.
37 changes: 33 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
FROM mcr.microsoft.com/devcontainers/python:3.7-bullseye
FROM python:3.7-slim

RUN \
adduser --system --disabled-password --shell /bin/bash vscode && \
# install docker
apt-get update && \
apt-get install ca-certificates curl gnupg lsb-release -y && \
mkdir -m 0755 -p /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y && \
usermod -aG docker vscode && \
apt-get clean

RUN \
# dev setup
apt update && \
apt-get install bash-completion graphviz default-mysql-client -y && \
pip install flake8 black faker ipykernel
apt-get install sudo git bash-completion graphviz default-mysql-client -y && \
usermod -aG sudo vscode && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
pip install --no-cache-dir --upgrade black pip && \
echo '. /etc/bash_completion' >> /home/vscode/.bashrc && \
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /home/vscode/.bashrc && \
# dircolors -b >> /home/vscode/.bashrc && \ # somehow fix colors
apt-get clean
COPY ./requirements.txt /tmp/
RUN \
# tutorial dependencies
pip install --no-cache-dir black faker ipykernel && \
pip install --no-cache-dir -r /tmp/requirements.txt && \
rm /tmp/requirements.txt

ENV DJ_HOST fakeservices.datajoint.io
ENV DJ_USER root
ENV DJ_PASS simple
ENV DJ_PASS simple

USER vscode
CMD bash -c "sudo rm /var/run/docker.pid; sudo dockerd"
13 changes: 4 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
},
// https://containers.dev/features
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/eitsupi/devcontainer-features/jq-likes:1": {},
"ghcr.io/guiyomh/features/vim:0": {}
},
"onCreateCommand": "pip install -e .",
"postStartCommand": "MYSQL_VER=8.0 docker compose down && MYSQL_VER=8.0 docker compose up --build --wait",
"onCreateCommand": "pip install -e . && MYSQL_VER=8.0 docker compose down && MYSQL_VER=8.0 docker compose up --build --wait",
"postStartCommand": "docker volume prune -f",
"hostRequirements": {
"cpus": 2,
"memory": "4gb"
"memory": "4gb",
"storage": "32gb"
},
"forwardPorts": [
3306
Expand Down
12 changes: 9 additions & 3 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
version: "3"
services:
app:
build: .
cpus: 2
mem_limit: 4g
build:
context: ..
dockerfile: ./.devcontainer/Dockerfile
extra_hosts:
- fakeservices.datajoint.io:127.0.0.1
volumes:
- ../..:/workspaces:cached
entrypoint: /usr/local/share/docker-init.sh
command: tail -f /dev/null
- docker_data:/var/lib/docker # persist docker images
privileged: true # only because of dind
volumes:
docker_data:
23 changes: 19 additions & 4 deletions 00-Getting_Started/01-DataJoint Basics - Interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1537,22 +1537,32 @@
"+ [02-calcium imaging](../01-Calcium_Imaging/02-Imported%20Tables%20-%20Interactive.ipynb)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Clean up"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# schema.drop()"
]
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,py:light"
},
"kernelspec": {
"display_name": "workflow-array-ephys",
"display_name": "Python 3",
"language": "python",
"name": "workflow-array-ephys"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1564,7 +1574,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.7.16"
},
"vscode": {
"interpreter": {
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
}
}
},
"nbformat": 4,
Expand Down
52 changes: 22 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,34 @@ Interactive tutorials on the DataJoint framework, in Python. Throughout this set
- `.populate()` for automated computation
- `.populate(reserve_jobs=True)` for parallelization

## Getting started
## Interactive Tutorial

The easiest way to learn about the basics of DataJoint is to use these tutorial notebooks within a [GitHub Codespace](https://docs.github.com/en/codespaces/overview). Please follow the steps below for the best experience:
The easiest way to learn DataJoint is to use the tutorial notebooks within the included interactive environment configured using [DevContainer](https://containers.dev/).

1. Fork this repository to your GitHub account.
### Launch Environment

2. Select the green `Code` button.
Here are some options that provide a great experience:

3. Within the dropdown menu, select the `Codespaces` tab.
- **Cloud-based IDE**: (*recommended*)
- Launch using [GitHub Codespaces](https://github.com/features/codespaces) using the `+` option which will `Create codespace on main` in the codebase repository on your fork with default options. For more control, see the `...` where you may create `New with options...`.
- Build time for a codespace is **~5m**. This is done infrequently and cached for convenience.
- Start time for a codespace is **~30s**. This will pull the built codespace from cache when you need it.
- *Tip*: Each month, GitHub renews a [free-tier](https://docs.github.com/en/billing/managing-billing-for-github-codespaces/about-billing-for-github-codespaces#monthly-included-storage-and-core-hours-for-personal-accounts) quota of compute and storage. Typically we run into the storage limits before anything else since Codespaces consume storage while stopped. It is best to delete Codespaces when not actively in use and recreate when needed. We'll soon be creating prebuilds to avoid larger build times. Once any portion of your quota is reached, you will need to wait for it to be reset at the end of your cycle or add billing info to your GitHub account to handle overages.
- *Tip*: GitHub auto names the codespace but you can rename the codespace so that it is easier to identify later.
- **Local IDE**:
- Ensure you have [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- Ensure you have [Docker](https://docs.docker.com/get-docker/)
- Ensure you have [VSCode](https://code.visualstudio.com/)
- Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
- `git clone` the codebase repository and open it in VSCode
- Use the `Dev Containers extension` to `Reopen in Container` (More info in the `Getting started` included with the extension)

4. Select the green `Create codespace on main` button.
You will know your environment has finished loading once you either see a terminal open related to `Running postStartCommand` with a final message: `Done` or the `README.md` is opened in `Preview`.

5. The environment is ready when a Visual Studio Code window is rendered within your browser. This takes ~5 minutes the first time being launched, and ~1 minute if you revisit this Codespace.
### Instructions

6. Navigate to the `00-Getting_Started` directory on the left panel and open the `00-Getting Started.ipynb` Jupyter notebook. Execute the cells in this notebook to begin your walk through the tutorials. We recommend finishing all notebooks in `00-Getting_Started` before proceeding to `01-Calcium_Imaging` and `02-Electrophysiology`.
1. We recommend you start by navigating to the `notebooks` directory on the left panel and go through the `00-Getting_Started/01-DataJoint Basics - Interactive.ipynb` Jupyter notebook. Execute the cells in the notebooks to begin your walk through of the tutorial.

7. Once you are done, GitHub will automatically stop the Codespace after 30 minutes of inactivity or you can manually stop the Codespace.
1. Once you are done, see the options available to you in the menu in the bottom-left corner. For example, in Codespace you will have an option to `Stop Current Codespace` but when running DevContainer on your own machine the equivalent option is `Reopen folder locally`. By default, GitHub will also automatically stop the Codespace after 30 minutes of inactivity.

8. After stopping the Codespace, we recommend deleting the Codespace to save on storage costs, which are free for the first 15 GB-month.

+ If you are new to GitHub and run into any errors, please contact us via email at [email protected]. If you are experienced with GitHub, please create an issue on the upstream repository or issue a pull request with a thorough explanation of the error and proposed solution.

+ **Please Note:** GitHub Codespaces are limited to 120 core-hours per month and 15 GB-month for free users. Once you exceed this limit, you will have to wait for the usage quota to reset or pay to use Codespaces.

## Run in Local Development Environment

- Install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)

- Install [Docker](https://docs.docker.com/get-docker/)

- Install [VSCode](https://code.visualstudio.com/)

- Install the VSCode [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)

- `git clone` the codebase repository and open it in VSCode

- Use the `Dev Containers extension` to `Reopen in Container` (More info in the `Getting started` included with the extension.)

- You will know your environment has finished loading once you see a terminal open related to `Running postStartCommand` with a final message: `Done`.
If you are new to GitHub and run into any errors, please contact us via email at [email protected]. If you are experienced with GitHub, please create an issue on the upstream repository or if you'd like help contribute, feel free to create a pull request. Please include a thorough explanantion of the error and/or proposed solution.

0 comments on commit bee49f7

Please sign in to comment.