From 37109c9ddec7094a55ff56e0ac6dcc3edfa694a5 Mon Sep 17 00:00:00 2001 From: Drew Yang Date: Thu, 26 Sep 2024 17:03:48 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20update=20devcontainer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/Dockerfile | 36 ++++++------------------------- .devcontainer/devcontainer.json | 24 +++++++++++++++------ .devcontainer/docker-compose.yaml | 18 +++++++++------- docker-compose.yml | 8 +++---- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 48d2de2..8eb2619 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6425d12..b8d7a20 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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" ] } } diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml index d5af8ab..cca3951 100644 --- a/.devcontainer/docker-compose.yaml +++ b/.devcontainer/docker-compose.yaml @@ -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: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 07b50c5..2f8cca9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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