Skip to content

Commit d664062

Browse files
atian25thonatos
authored andcommitted
feat: devcontainer with codespaces
1 parent 072e146 commit d664062

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

.devcontainer/devcontainer.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Update the VARIANT arg in docker-compose.yml to pick a Node.js version
2+
{
3+
"name": "Node.js && Redis && MySQL",
4+
"dockerComposeFile": "../docker-compose.yml",
5+
"service": "app",
6+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
7+
8+
// Configure tool-specific properties.
9+
"customizations": {
10+
// Configure properties specific to VS Code.
11+
"vscode": {
12+
// Add the IDs of extensions you want installed when the container is created.
13+
"extensions": [
14+
]
15+
}
16+
},
17+
18+
"forwardPorts": [
19+
"phpmyadmin:80"
20+
],
21+
22+
// Use 'postCreateCommand' to run commands after the container is created.
23+
"postCreateCommand": "pnpm i",
24+
"containerEnv": {
25+
"MYSQL_HOST": "mysql"
26+
},
27+
28+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
29+
"remoteUser": "node"
30+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ lerna-debug.log*
88

99
.npmrc
1010
package-lock.json
11+
pnpm-lock.yaml
1112

1213
config/config.prod.ts
1314
config/**/*.js

docker-compose.yml

+37-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
version: '3.6'
1+
version: '3.8'
22
services:
3+
app:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
volumes:
8+
- ../..:/workspaces:cached
9+
10+
# Overrides default command so things don't shut down after the process ends.
11+
command: sleep infinity
12+
13+
# links:
14+
# - redis
15+
# - mysql
16+
depends_on:
17+
- mysql
18+
- redis
19+
networks:
20+
- cnpm
21+
22+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
23+
# networks:
24+
# - cnpm
25+
26+
# Uncomment the next line to use a non-root user for all processes.
27+
# user: node
28+
29+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
30+
# (Adding the "ports" property to this file will not forward from a Codespace.)
31+
332
redis:
433
image: redis:6-alpine
534
# command: redis-server --appendonly yes --requirepass cnpm
635
restart: always
736
volumes:
837
- cnpm-redis:/data
938
ports:
10-
- 6379:6379
39+
- 6379
1140
networks:
1241
- cnpm
1342

@@ -16,7 +45,7 @@ services:
1645
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
1746
restart: always
1847
environment:
19-
MYSQL_ROOT_PASSWORD:
48+
MYSQL_ROOT_PASSWORD: root
2049
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
2150
# MYSQL_DATABASE: 'cnpmcore_unittest'
2251
MYSQL_USER: user
@@ -26,7 +55,7 @@ services:
2655
# - ./conf.d/mysql/:/etc/mysql/conf.d
2756
# - ./init.d/mysql/:/docker-entrypoint-initdb.d
2857
ports:
29-
- 3306:3306
58+
- 3306
3059
networks:
3160
- cnpm
3261

@@ -35,23 +64,22 @@ services:
3564
image: phpmyadmin
3665
restart: always
3766
environment:
38-
MYSQL_ROOT_PASSWORD:
67+
MYSQL_ROOT_PASSWORD: root
3968
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
4069
MYSQL_USER: user
4170
MYSQL_PASSWORD: pass
4271
PMA_HOST: 'mysql'
72+
depends_on:
73+
- mysql
4374
ports:
44-
- 8080:80
75+
- 80
4576
networks:
4677
- cnpm
47-
depends_on:
48-
- mysql
4978

5079
volumes:
5180
cnpm-redis:
5281
cnpm-mysql:
5382

54-
5583
networks:
5684
cnpm:
5785
name: cnpm

test/TestUtil.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class TestUtil {
4949
host: process.env.MYSQL_HOST || '127.0.0.1',
5050
port: process.env.MYSQL_PORT || 3306,
5151
user: process.env.MYSQL_USER || 'root',
52-
password: process.env.MYSQL_PASSWORD,
52+
password: process.env.MYSQL_PASSWORD || '',
5353
multipleStatements: true,
5454
};
5555
}

0 commit comments

Comments
 (0)