Skip to content

Commit bee49f7

Browse files
Merge pull request #22 from guzman-raphael/reduce-image
Optimize DevContainer
2 parents a92e972 + 77e420f commit bee49f7

File tree

5 files changed

+87
-50
lines changed

5 files changed

+87
-50
lines changed

.devcontainer/Dockerfile

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1-
FROM mcr.microsoft.com/devcontainers/python:3.7-bullseye
1+
FROM python:3.7-slim
22

33
RUN \
4+
adduser --system --disabled-password --shell /bin/bash vscode && \
5+
# install docker
6+
apt-get update && \
7+
apt-get install ca-certificates curl gnupg lsb-release -y && \
8+
mkdir -m 0755 -p /etc/apt/keyrings && \
9+
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
10+
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 && \
11+
apt-get update && \
12+
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y && \
13+
usermod -aG docker vscode && \
14+
apt-get clean
15+
16+
RUN \
17+
# dev setup
418
apt update && \
5-
apt-get install bash-completion graphviz default-mysql-client -y && \
6-
pip install flake8 black faker ipykernel
19+
apt-get install sudo git bash-completion graphviz default-mysql-client -y && \
20+
usermod -aG sudo vscode && \
21+
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
22+
pip install --no-cache-dir --upgrade black pip && \
23+
echo '. /etc/bash_completion' >> /home/vscode/.bashrc && \
24+
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /home/vscode/.bashrc && \
25+
# dircolors -b >> /home/vscode/.bashrc && \ # somehow fix colors
26+
apt-get clean
27+
COPY ./requirements.txt /tmp/
28+
RUN \
29+
# tutorial dependencies
30+
pip install --no-cache-dir black faker ipykernel && \
31+
pip install --no-cache-dir -r /tmp/requirements.txt && \
32+
rm /tmp/requirements.txt
733

834
ENV DJ_HOST fakeservices.datajoint.io
935
ENV DJ_USER root
10-
ENV DJ_PASS simple
36+
ENV DJ_PASS simple
37+
38+
USER vscode
39+
CMD bash -c "sudo rm /var/run/docker.pid; sudo dockerd"

.devcontainer/devcontainer.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
1010
},
1111
// https://containers.dev/features
12-
"features": {
13-
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
14-
"ghcr.io/devcontainers/features/git:1": {},
15-
"ghcr.io/eitsupi/devcontainer-features/jq-likes:1": {},
16-
"ghcr.io/guiyomh/features/vim:0": {}
17-
},
18-
"onCreateCommand": "pip install -e .",
19-
"postStartCommand": "MYSQL_VER=8.0 docker compose down && MYSQL_VER=8.0 docker compose up --build --wait",
12+
"onCreateCommand": "pip install -e . && MYSQL_VER=8.0 docker compose down && MYSQL_VER=8.0 docker compose up --build --wait",
13+
"postStartCommand": "docker volume prune -f",
2014
"hostRequirements": {
2115
"cpus": 2,
22-
"memory": "4gb"
16+
"memory": "4gb",
17+
"storage": "32gb"
2318
},
2419
"forwardPorts": [
2520
3306

.devcontainer/docker-compose.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
version: "3"
22
services:
33
app:
4-
build: .
4+
cpus: 2
5+
mem_limit: 4g
6+
build:
7+
context: ..
8+
dockerfile: ./.devcontainer/Dockerfile
59
extra_hosts:
610
- fakeservices.datajoint.io:127.0.0.1
711
volumes:
812
- ../..:/workspaces:cached
9-
entrypoint: /usr/local/share/docker-init.sh
10-
command: tail -f /dev/null
13+
- docker_data:/var/lib/docker # persist docker images
14+
privileged: true # only because of dind
15+
volumes:
16+
docker_data:

00-Getting_Started/01-DataJoint Basics - Interactive.ipynb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,22 +1537,32 @@
15371537
"+ [02-calcium imaging](../01-Calcium_Imaging/02-Imported%20Tables%20-%20Interactive.ipynb)"
15381538
]
15391539
},
1540+
{
1541+
"attachments": {},
1542+
"cell_type": "markdown",
1543+
"metadata": {},
1544+
"source": [
1545+
"# Clean up"
1546+
]
1547+
},
15401548
{
15411549
"cell_type": "code",
15421550
"execution_count": null,
15431551
"metadata": {},
15441552
"outputs": [],
1545-
"source": []
1553+
"source": [
1554+
"# schema.drop()"
1555+
]
15461556
}
15471557
],
15481558
"metadata": {
15491559
"jupytext": {
15501560
"formats": "ipynb,py:light"
15511561
},
15521562
"kernelspec": {
1553-
"display_name": "workflow-array-ephys",
1563+
"display_name": "Python 3",
15541564
"language": "python",
1555-
"name": "workflow-array-ephys"
1565+
"name": "python3"
15561566
},
15571567
"language_info": {
15581568
"codemirror_mode": {
@@ -1564,7 +1574,12 @@
15641574
"name": "python",
15651575
"nbconvert_exporter": "python",
15661576
"pygments_lexer": "ipython3",
1567-
"version": "3.9.4"
1577+
"version": "3.7.16"
1578+
},
1579+
"vscode": {
1580+
"interpreter": {
1581+
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
1582+
}
15681583
}
15691584
},
15701585
"nbformat": 4,

README.md

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,34 @@ Interactive tutorials on the DataJoint framework, in Python. Throughout this set
2424
- `.populate()` for automated computation
2525
- `.populate(reserve_jobs=True)` for parallelization
2626

27-
## Getting started
27+
## Interactive Tutorial
2828

29-
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:
29+
The easiest way to learn DataJoint is to use the tutorial notebooks within the included interactive environment configured using [DevContainer](https://containers.dev/).
3030

31-
1. Fork this repository to your GitHub account.
31+
### Launch Environment
3232

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

35-
3. Within the dropdown menu, select the `Codespaces` tab.
35+
- **Cloud-based IDE**: (*recommended*)
36+
- 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...`.
37+
- Build time for a codespace is **~5m**. This is done infrequently and cached for convenience.
38+
- Start time for a codespace is **~30s**. This will pull the built codespace from cache when you need it.
39+
- *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.
40+
- *Tip*: GitHub auto names the codespace but you can rename the codespace so that it is easier to identify later.
41+
- **Local IDE**:
42+
- Ensure you have [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
43+
- Ensure you have [Docker](https://docs.docker.com/get-docker/)
44+
- Ensure you have [VSCode](https://code.visualstudio.com/)
45+
- Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
46+
- `git clone` the codebase repository and open it in VSCode
47+
- Use the `Dev Containers extension` to `Reopen in Container` (More info in the `Getting started` included with the extension)
3648

37-
4. Select the green `Create codespace on main` button.
49+
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`.
3850

39-
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.
51+
### Instructions
4052

41-
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`.
53+
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.
4254

43-
7. Once you are done, GitHub will automatically stop the Codespace after 30 minutes of inactivity or you can manually stop the Codespace.
55+
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.
4456

45-
8. After stopping the Codespace, we recommend deleting the Codespace to save on storage costs, which are free for the first 15 GB-month.
46-
47-
+ 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.
48-
49-
+ **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.
50-
51-
## Run in Local Development Environment
52-
53-
- Install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
54-
55-
- Install [Docker](https://docs.docker.com/get-docker/)
56-
57-
- Install [VSCode](https://code.visualstudio.com/)
58-
59-
- Install the VSCode [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
60-
61-
- `git clone` the codebase repository and open it in VSCode
62-
63-
- Use the `Dev Containers extension` to `Reopen in Container` (More info in the `Getting started` included with the extension.)
64-
65-
- You will know your environment has finished loading once you see a terminal open related to `Running postStartCommand` with a final message: `Done`.
57+
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 commit comments

Comments
 (0)