Skip to content

Commit

Permalink
feat: devcontainer with codespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and thonatos committed Nov 7, 2023
1 parent 072e146 commit d664062
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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": [
]
}
},

"forwardPorts": [
"phpmyadmin:80"
],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm i",
"containerEnv": {
"MYSQL_HOST": "mysql"
},

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
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
46 changes: 37 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
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

# links:
# - redis
# - mysql
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 +45,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 @@ -26,7 +55,7 @@ services:
# - ./conf.d/mysql/:/etc/mysql/conf.d
# - ./init.d/mysql/:/docker-entrypoint-initdb.d
ports:
- 3306:3306
- 3306
networks:
- cnpm

Expand All @@ -35,23 +64,22 @@ services:
image: phpmyadmin
restart: always
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_ROOT_PASSWORD: root
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: user
MYSQL_PASSWORD: pass
PMA_HOST: 'mysql'
depends_on:
- mysql
ports:
- 8080:80
- 80
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

0 comments on commit d664062

Please sign in to comment.