Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ update devcontainer #47

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
FROM python:3.9-slim@sha256:5f0192a4f58a6ce99f732fe05e3b3d00f12ae62e183886bca3ebe3d202686c7f

ENV PATH /usr/local/bin:$PATH
ENV PYTHON_VERSION 3.9.17

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
ARG PY_VER
ARG DISTRO
FROM mcr.microsoft.com/devcontainers/python:${PY_VER}-${DISTRO}

RUN \
# dev setup
apt update && \
apt-get install sudo git gcc 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 && \
pip install --no-cache-dir --upgrade black faker ipykernel pip && \
apt-get clean

# tutorial dependencies
COPY ./requirements.txt /tmp/

RUN \
# tutorial dependencies
pip install --no-cache-dir black faker ipykernel && \
pip install --no-cache-dir -r /tmp/requirements.txt --upgrade && \
rm /tmp/requirements.txt

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

USER vscode
CMD bash -c "sudo rm /var/run/docker.pid; sudo dockerd"
24 changes: 18 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
{
"name": "DataJoint Tutorial",
"dockerComposeFile": "docker-compose.yaml",
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yaml"
],
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
},
"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",
"onCreateCommand": "pip install -q -e .",
"shutdownAction": "stopCompose",
"hostRequirements": {
"cpus": 2,
"memory": "4gb",
"storage": "32gb"
},
"forwardPorts": [
3306
80,
443,
3306,
8080,
9000
],
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"settings": {
"python.pythonPath": "/usr/local/bin/python"
},
"vscode": {
"extensions": [
"ms-python.python@2023.8.0",
"ms-toolsai.jupyter@2023.3.1201040234"
"ms-python.python",
"ms-toolsai.jupyter"
]
}
}
Expand Down
18 changes: 10 additions & 8 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
version: "3"
services:
app:
cpus: 2
mem_limit: 4g
# build: # build context is used when developing locally
# context: ..
# dockerfile: ./.devcontainer/Dockerfile
build: # build context is used when developing locally
context: .
dockerfile: .devcontainer/Dockerfile
args:
- PY_VER=${PY_VER:-3.11}
- DISTRO=${DISTRO:-buster}
image: datajoint/datajoint_tutorials:latest
extra_hosts:
- fakeservices.datajoint.io:127.0.0.1
volumes:
- ..:/workspaces/datajoint-tutorials:cached
- ..:/workspaces:cached
- docker_data:/var/lib/docker # persist docker images
privileged: true # only because of dind
user: root
# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
docker_data:
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# MYSQL_VER=8.0 docker compose up --build
version: "2.4"
services:
db:
restart: always
image: datajoint/mysql:${MYSQL_VER}
image: datajoint/mysql:${MYSQL_VER:-8.0}
environment:
- MYSQL_ROOT_PASSWORD=${DJ_PASS}
ports:
- "3306:3306"
- MYSQL_ROOT_PASSWORD=${DJ_PASS:-simple}
command: mysqld --default-authentication-plugin=mysql_native_password
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
timeout: 15s
Expand Down
Loading