From 1af96b316a9cca07bcd0e3ae8a13d34342f1c6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TZ=20=7C=20=E5=A4=A9=E7=8C=AA?= Date: Thu, 3 Nov 2022 15:05:17 +0000 Subject: [PATCH] feat: devcontainer with codespaces --- .devcontainer/devcontainer.json | 21 +++++++++++++++++++++ Dockerfile | 15 +++++++++++++++ docker-compose.yml | 23 ++++++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..6bd97041 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +// Update the VARIANT arg in docker-compose.yml to pick a Node.js version +{ + "name": "Node.js && Redis && MySQL", + "dockerComposeFile": "../docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "mongodb.mongodb-vscode" + ] + } + }, + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "node" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3e9019ca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:0-16-bullseye + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +RUN su node -c "npm install -g pnpm" + + + diff --git a/docker-compose.yml b/docker-compose.yml index 8340d2cf..1a842f47 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,26 @@ -version: '3.6' +version: '3.8' services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + # network_mode: service:db + networks: + - cnpm + + # Uncomment the next line to use a non-root user for all processes. + # user: node + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + redis: image: redis:6-alpine # command: redis-server --appendonly yes --requirepass cnpm