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

[WIP] feat: devcontainer with codespaces #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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": [
]
}
},

// Forwards ports
"forwardPorts": [
8080
],
"portsAttributes": {
"8080": {
"label": "Adminer",
"onAutoForward": "notify"
}
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": [
"bash .devcontainer/scripts/postCreateCommand.sh"
],

// Container Env
"containerEnv": {
"MYSQL_HOST": "mysql",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "root"
},

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
4 changes: 4 additions & 0 deletions .devcontainer/scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pnpm i
socat TCP4-LISTEN:8080,reuseaddr,fork TCP:adminer:8080 &
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lerna-debug.log*

.npmrc
package-lock.json
pnpm-lock.yaml

config/config.prod.ts
config/**/*.js
Expand Down
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ WORKDIR /usr/src/app
# Install app dependencies
COPY . .

RUN npm install -g npminstall --registry=https://registry.npmmirror.com \
# NPM Mirror
# npm install -g npminstall --registry=https://registry.npmmirror.com
# apk add --no-cache socat \
RUN apt-get update \
&& apt-get -y install socat \
&& npm install -g npminstall \
&& npminstall -c \
&& npm run tsc

Expand Down
52 changes: 37 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
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
depends_on:
- mysql
- redis
networks:
- cnpm

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
# 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
restart: always
volumes:
- cnpm-redis:/data
ports:
- 6379:6379
- 6379
networks:
- cnpm

Expand All @@ -16,7 +41,7 @@ services:
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_ROOT_PASSWORD: root
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
# MYSQL_DATABASE: 'cnpmcore_unittest'
MYSQL_USER: user
Expand All @@ -25,33 +50,30 @@ services:
- cnpm-mysql:/var/lib/mysql
# - ./conf.d/mysql/:/etc/mysql/conf.d
# - ./init.d/mysql/:/docker-entrypoint-initdb.d
- ./sql:/docker-entrypoint-initdb.d/sql
- ./prepare-database.sh:/docker-entrypoint-initdb.d/init.sh
ports:
- 3306:3306
- 3306
networks:
- cnpm

# database explorer
phpmyadmin:
image: phpmyadmin
adminer:
image: adminer
restart: always
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: user
MYSQL_PASSWORD: pass
PMA_HOST: 'mysql'
ADMINER_DEFAULT_DB_HOST: 'mysql'
depends_on:
- mysql
ports:
- 8080:80
- 8080
networks:
- cnpm
depends_on:
- mysql

volumes:
cnpm-redis:
cnpm-mysql:


networks:
cnpm:
name: cnpm
Expand Down
2 changes: 1 addition & 1 deletion test/TestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class TestUtil {
host: process.env.MYSQL_HOST || '127.0.0.1',
port: process.env.MYSQL_PORT || 3306,
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PASSWORD,
password: process.env.MYSQL_PASSWORD || '',
multipleStatements: true,
};
}
Expand Down
Loading