Skip to content

Commit

Permalink
refactor(devcontainer): network
Browse files Browse the repository at this point in the history
  • Loading branch information
uonr committed Dec 26, 2023
1 parent 14ecb1f commit d27222e
Show file tree
Hide file tree
Showing 8 changed files with 725 additions and 149 deletions.
3 changes: 0 additions & 3 deletions .devcontainer/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
POSTGRES_USER=boluo
POSTGRES_PASSWORD=boluo
PGADMIN_DEFAULT_EMAIL=[email protected]
PGADMIN_DEFAULT_PASSWORD=boluo
PGADMIN_LISTEN_PORT=4841
MINIO_ROOT_USER=boluo
MINIO_ROOT_PASSWORD=boluo-development
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or with the host.
"forwardPorts": [3000, 4841, 9000, 9090, 8080],
"forwardPorts": ["app:3000", "app:3100", "app:8080", "pgadmin:4841", "store:9000", "store:9090"],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "cp .env.local.example .env.local && direnv allow",

Expand Down
36 changes: 16 additions & 20 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ version: '3.8'

services:
app:
depends_on:
- db
- db-test
- redis
- store
build:
context: ..
dockerfile: .devcontainer/Dockerfile
context: .
dockerfile: Dockerfile

volumes:
- ../..:/workspaces:cached
Expand All @@ -13,10 +18,6 @@ services:
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# 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
Expand All @@ -35,6 +36,8 @@ services:
db-test:
image: postgres:latest
restart: unless-stopped
ports:
- 127.0.0.1:36002:5432
volumes:
- ../apps/server/schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro
environment:
Expand All @@ -50,18 +53,16 @@ services:
- db
- db-test
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
- PGADMIN_LISTEN_PORT=${PGADMIN_LISTEN_PORT}
- PGADMIN_CONFIG_SERVER_MODE=FALSE
- PGADMIN_DEFAULT_EMAIL=[email protected]
- PGADMIN_DEFAULT_PASSWORD=8932rhku32rhui
- PGADMIN_LISTEN_PORT=4841
- PGADMIN_CONFIG_SERVER_MODE=False
- PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED=False
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
network_mode: service:db

store:
image: quay.io/minio/minio
restart: unless-stopped
network_mode: service:db
volumes:
- minio-data:/data
environment:
Expand All @@ -72,22 +73,17 @@ services:

store-init:
image: quay.io/minio/mc
network_mode: service:db
depends_on:
- store
entrypoint: >
/bin/sh -c "
sleep 10;
/usr/bin/mc config host add devminio http://127.0.0.1:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD};
/usr/bin/mc rm -r --force devminio/boluo;
/usr/bin/mc mb devminio/boluo;
/usr/bin/mc anonymous set public devminio/boluo;
/usr/bin/mc config host add dev http://store:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD};
/usr/bin/mc mb dev/boluo;
/usr/bin/mc anonymous set public dev/boluo;
exit 0;
"
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
volumes:
nix-store:
postgres-data:
minio-data:
2 changes: 1 addition & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BACKEND_URL=http://127.0.0.1:3000
SECRET=SOME_SECRET
S3_ACCESS_KEY_ID=boluo
S3_SECRET_ACCESS_KEY=boluo-development
S3_ENDPOINT_URL=http://127.0.0.1:9000
S3_ENDPOINT_URL=http://store:9000
S3_BUCKET_NAME=boluo

PUBLIC_MEDIA_URL=http://127.0.0.1:9000/boluo
Loading

0 comments on commit d27222e

Please sign in to comment.