Skip to content

Commit 7d46f8c

Browse files
authored
Fixes dev containers connecting to other services on the host. (#46)
1 parent cd1a2ee commit 7d46f8c

File tree

9 files changed

+36
-23
lines changed

9 files changed

+36
-23
lines changed

.devcontainer/.env.default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IDENTITY_PROVIDER_HOST=your.identity.domain.path.com

.devcontainer/devcontainer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"typescript.referencesCodeLens.enabled": true,
3131
"typescript.implementationsCodeLens.enabled": true,
3232
"editor.codeActionsOnSave": {
33-
"source.organizeImports": true,
34-
"source.fixAll": true
33+
"source.organizeImports": "always",
34+
"source.fixAll": "always"
3535
},
3636
"editor.formatOnSave": true,
3737
"typescript.format.semicolons": "insert",
@@ -40,8 +40,6 @@
4040
}
4141
}
4242
},
43-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
44-
// "forwardPorts": [3000, 27017],
4543
// Use 'postCreateCommand' to run commands after the container is created.
4644
"postCreateCommand": "yarn install && yarn postinstall"
4745
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.

.devcontainer/docker-compose.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ services:
1313
# Overrides default command so things don't shut down after the process ends.
1414
command: sleep infinity
1515

16-
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
17-
network_mode: service:db
16+
network_mode: host
17+
extra_hosts:
18+
- '${IDENTITY_PROVIDER_HOST:-localhost}:host-gateway'
19+
- 'dev-redis:172.20.0.3'
20+
- 'dev-db:172.20.0.2'
1821

19-
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
20-
# (Adding the "ports" property to this file will not forward from a Codespace.)
22+
depends_on:
23+
- db
24+
- redis
2125

2226
db:
2327
image: mariadb:latest
@@ -26,11 +30,22 @@ services:
2630
restart: unless-stopped
2731
volumes:
2832
- mysqldata:/var/lib/mysql
33+
networks:
34+
devcontainer-network:
35+
ipv4_address: 172.20.0.2
2936
redis:
3037
image: redis:latest
3138
restart: unless-stopped
32-
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
33-
network_mode: service:db
39+
networks:
40+
devcontainer-network:
41+
ipv4_address: 172.20.0.3
42+
43+
networks:
44+
devcontainer-network:
45+
driver: bridge
46+
ipam:
47+
config:
48+
- subnet: 172.20.0.0/16
3449

3550
volumes:
3651
mysqldata:

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
nodeLinker: node-modules
22

3-
npmRegistryServer: "https://registry.yarnpkg.com"
3+
npmRegistryServer: 'https://registry.yarnpkg.com'
44

55
yarnPath: .yarn/releases/yarn-4.2.2.cjs

local-development/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ services:
2424
volumes:
2525
- mysqldata:/var/lib/mysql
2626
ports:
27-
- "127.0.0.1:3306:3306"
27+
- '127.0.0.1:3306:3306'
2828
expose:
29-
- "127.0.0.1:3306"
29+
- '127.0.0.1:3306'
3030
redis:
3131
image: redis:latest
3232
restart: unless-stopped
3333
# # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
3434
# network_mode: service:db
3535
ports:
36-
- "127.0.0.1:6379:6379"
36+
- '127.0.0.1:6379:6379'
3737
expose:
38-
- "127.0.0.1:6379"
38+
- '127.0.0.1:6379'
3939

4040
volumes:
41-
mysqldata:
41+
mysqldata:

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
2020
"setup:env": "node scripts/setup-env.js",
2121
"bootstrap": "node scripts/bootstrap.js",
22-
"dev:all": "concurrently --names \"wiki,auth-wiki,todo,auth-todo\" --prefix-colors \"blue,magenta,green,red\" --output-path logs/dev-all.log \"yarn dev:wiki\" \"yarn auth:wiki\" \"yarn dev:todo\" \"yarn auth:todo\"",
23-
"open:apps": "node scripts/open-apps.js"
22+
"dev:all": "concurrently --names \"wiki,auth-wiki,todo,auth-todo\" --prefix-colors \"blue,magenta,green,red\" --output-path logs/dev-all.log \"yarn dev:wiki\" \"yarn auth:wiki\" \"yarn dev:todo\" \"yarn auth:todo\""
2423
},
2524
"author": "",
2625
"license": "ISC",

packages/authorization-server/.env.wiki.default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AUTH_SERVER_PORT="5000"
22
AUTH_SERVER="http://localhost:5000"
33
COOKIE_SECRET="secret"
44
AUTH_INTERACTION_COOKIE_SECRET="secret key one"
5-
REDIS_SERVER="redis://localhost:6379"
5+
REDIS_SERVER="redis://dev-redis:6379"
66
# The resource server that uses this AS
77
APP_RESOURCE="http://localhost:3000/"
88

packages/todo0/.env.default

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
55
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
66

7-
TODO_DATABASE_URL="mysql://root:avocado@localhost:3306/todo"
7+
TODO_DATABASE_URL="mysql://root:avocado@dev-db:3306/todo"
88
COOKIE_SECRET="secret"
99

1010
AUTH_SERVER="http://localhost:5001"
@@ -13,4 +13,4 @@ TODO_SERVER="http://localhost:3001"
1313
CLIENT1_CLIENT_ID="todo0"
1414
CLIENT1_CLIENT_SECRET="secret"
1515

16-
REDIS_SERVER="redis://localhost:6379"
16+
REDIS_SERVER="redis://dev-redis:6379"

packages/wiki0/.env.default

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
55
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
66

7-
WIKI_DATABASE_URL="mysql://root:avocado@localhost:3306/wiki"
7+
WIKI_DATABASE_URL="mysql://root:avocado@dev-db:3306/wiki"
88
COOKIE_SECRET="secret"
99

1010
AUTH_SERVER="http://localhost:5000"
@@ -17,6 +17,6 @@ CLIENT1_CLIENT_SECRET="secret"
1717
TODO_SERVER="http://localhost:3001"
1818
TODO_AUTH_SERVER="http://localhost:5001"
1919

20-
REDIS_SERVER="redis://localhost:6379"
20+
REDIS_SERVER="redis://dev-redis:6379"
2121
CLIENT2_CLIENT_ID="wiki0-at-todo0"
2222
CLIENT2_CLIENT_SECRET="secret-todo"

0 commit comments

Comments
 (0)