Skip to content

Commit 6870184

Browse files
sanakRedmine Patch Meetup
authored andcommitted
devcontainerのDB設定周りの変更 (#84)
* Adjust docker-compose.yml MySQL settings and expose PostgreSQL/MySQL ports * Adjust SQLTools MySQL driver and connections
1 parent 87a960f commit 6870184

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.devcontainer/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ SELENIUM_PORT_1=4444
33
SELENIUM_PORT_2=5900
44
MAILCATCHER_PORT=1080
55
RAILS_DB_ADAPTER=postgresql
6+
POSTGRES_PORT=5433
7+
MYSQL_PORT=3307

.devcontainer/devcontainer.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"kaiwood.endwise",
1717
"mtxr.sqltools",
1818
"mtxr.sqltools-driver-pg",
19+
"mtxr.sqltools-driver-mysql",
1920
"ms-vsliveshare.vsliveshare"
2021
],
2122
"settings": {
@@ -30,9 +31,19 @@
3031
"driver": "PostgreSQL",
3132
"name": "app_development",
3233
"database": "app_development",
33-
"username": "db_user",
34-
"password": "password"
35-
}
34+
"username": "postgres",
35+
"password": "postgres"
36+
},
37+
{
38+
"previewLimit": 50,
39+
"server": "mysqldb",
40+
"port": 3306,
41+
"driver": "MySQL",
42+
"name": "app_development",
43+
"database": "app_development",
44+
"username": "root",
45+
"password": "password"
46+
},
3647
]
3748
}
3849
}

.devcontainer/docker-compose.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ services:
1010
environment:
1111
POSTGRES_USER: postgres
1212
POSTGRES_PASSWORD: postgres
13+
ports:
14+
- $POSTGRES_PORT:5432
1315

1416
# MySQL
1517
# mysqldb:
1618
# image: mysql:5
19+
# platform: linux/amd64
1720
# restart: on-failure:5
1821
# environment:
1922
# MYSQL_ROOT_PASSWORD: password
20-
# MYSQL_PASSWORD: password
21-
# MYSQL_USER: db_user
23+
# ports:
24+
# - $MYSQL_PORT:3306
2225

2326
app:
2427
build:
@@ -33,13 +36,22 @@ services:
3336
# Optional Node.js version to install
3437
NODE_VERSION: "14"
3538
environment:
39+
# PostgreSQL
3640
RAILS_DB_ADAPTER: postgresql
3741
RAILS_DB_HOST: postgresdb
3842
RAILS_DB: app
3943
RAILS_DB_USERNAME: postgres
4044
RAILS_DB_PASSWORD: postgres
4145
RAILS_DB_ENCODING: utf8
4246
RAILS_ENV: development
47+
# # MySQL
48+
# RAILS_DB_ADAPTER: mysql2
49+
# RAILS_DB_HOST: mysqldb
50+
# RAILS_DB: app
51+
# RAILS_DB_USERNAME: root
52+
# RAILS_DB_PASSWORD: password
53+
# RAILS_DB_ENCODING: utf8mb4
54+
# RAILS_ENV: development
4355
env_file: .env
4456
tty: true
4557
ports:

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ SELENIUM_PORT_2=5900
7070
MAILCATCHER_PORT=1080
7171
# mysqlやsqlite3に変えても良い。mysqlの場合、.devcontainer/docker-compose.ymlのMySQL関連のコメントアウトを外す
7272
RAILS_DB_ADAPTER=postgresql
73+
# postgres、mysqlのホスト側への公開ポート。ホスト側で既に使っている場合は変える
74+
POSTGRES_PORT=5433
75+
MYSQL_PORT=3307
7376
```
7477

7578
* VScodeに拡張機能[Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)をインストール

0 commit comments

Comments
 (0)