Skip to content

Commit fe2a9a2

Browse files
committed
Add postgres-db to deployment
See extra instructions in readme
1 parent be7d515 commit fe2a9a2

File tree

6 files changed

+93
-49
lines changed

6 files changed

+93
-49
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
# Example
22

3+
## Launch
4+
5+
```bash
6+
docker compose up
7+
```
8+
9+
App will be accessible on port 8080
10+
11+
### Launch development environment
12+
13+
In `vscode` use the task labeled `dev`.
14+
15+
### Launch in debug mode
16+
17+
TODO, WIP
18+
319
## Using workspaces
420

521
Most commands can be launched for each workspace by using `--workspaces|-ws`
622

23+
Examples:
24+
725
```bash
8-
npm i -ws
9-
npm install --workspaces
26+
npm i --workspaces
27+
npm ci -ws
28+
npm run build -ws --if-present
29+
npm run test -ws --if-present
30+
npm run clean -ws --include-workspace-root --if-present
1031
```
32+
33+
Or in a specific workspace
34+
35+
```bash
36+
npm i --workspace=backend
37+
npm ci -w=backend --omit=dev
38+
npm run start --workspace=backend
39+
```
40+
41+
Use auto-reload with

compose.debug.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# TODO: Make this auto-reloadable and expose debug ports to the outside world
2+
services:
3+
frontend: {}
4+
backend: {}
5+
db:
6+
ports:
7+
- 5432:5432

compose.yaml

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
# database or a cache. For examples, see the Awesome Compose repository:
99
# https://github.com/docker/awesome-compose
1010
services:
11+
12+
frontend:
13+
build:
14+
context: .
15+
target: frontend
16+
environment:
17+
BACKEND_URL: http://backend:3000
18+
PORT: 8080
19+
depends_on:
20+
- backend
21+
ports:
22+
- 8080:8080
1123
backend:
1224
build:
1325
context: .
@@ -17,45 +29,36 @@ services:
1729
PORT: 3000
1830
ports:
1931
- 3000:3000
20-
frontend:
21-
build:
22-
context: .
23-
target: frontend
32+
depends_on:
33+
db:
34+
condition: service_healthy
35+
secrets:
36+
- db-password
37+
healthcheck:
38+
test: ["CMD", "curl --fail http://localhost:3000/health"]
39+
interval: 10s
40+
timeout: 5s
41+
retries: 5
42+
db:
43+
image: postgres:17-alpine
44+
restart: always
45+
user: postgres
46+
secrets:
47+
- db-password
48+
volumes:
49+
- db-data:/var/lib/postgresql/data
2450
environment:
25-
BACKEND_URL: http://backend:3000
26-
PORT: 8080
27-
ports:
28-
- 8080:8080
29-
30-
# The commented out section below is an example of how to define a PostgreSQL
31-
# database that your application can use. `depends_on` tells Docker Compose to
32-
# start the database before your application. The `db-data` volume persists the
33-
# database data between container restarts. The `db-password` secret is used
34-
# to set the database password. You must create `db/password.txt` and add
35-
# a password of your choosing to it before running `docker-compose up`.
36-
# depends_on:
37-
# db:
38-
# condition: service_healthy
39-
# db:
40-
# image: postgres
41-
# restart: always
42-
# user: postgres
43-
# secrets:
44-
# - db-password
45-
# volumes:
46-
# - db-data:/var/lib/postgresql/data
47-
# environment:
48-
# - POSTGRES_DB=example
49-
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
50-
# expose:
51-
# - 5432
52-
# healthcheck:
53-
# test: [ "CMD", "pg_isready" ]
54-
# interval: 10s
55-
# timeout: 5s
56-
# retries: 5
57-
# volumes:
58-
# db-data:
59-
# secrets:
60-
# db-password:
61-
# file: db/password.txt
51+
- POSTGRES_DB=example
52+
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
53+
expose:
54+
- 5432
55+
healthcheck:
56+
test: [ "CMD", "pg_isready" ]
57+
interval: 10s
58+
timeout: 5s
59+
retries: 5
60+
volumes:
61+
db-data:
62+
secrets:
63+
db-password:
64+
file: db/password.txt

db/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.txt

eslint.config.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ export default [
102102
'no-console': error,
103103
'@typescript-eslint/return-await': ['error', 'always'],
104104
'no-unused-vars': off,
105-
'@typescript-eslint/no-unused-vars': error,
105+
'@typescript-eslint/no-unused-vars': [
106+
'error',
107+
{ ignoreRestSiblings: true },
108+
],
106109
eqeqeq: [error, 'smart'],
107110
'no-else-return': [
108111
error,
@@ -136,8 +139,7 @@ export default [
136139
// patterns: TEST_ONLY_IMPORTS.map(dep => `${dep}/*`),
137140
// },
138141
// ],
139-
'@typescript-eslint/explicit-member-accessibility': warn,
140-
'@typescript-eslint/no-explicit-any': warn,
142+
...any_rules('warn'),
141143
'@typescript-eslint/explicit-function-return-type': off,
142144
// '@typescript-eslint/no-var-requires': off,
143145
'@typescript-eslint/no-empty-function': off,

react-frontend-express-backend.code-workspace

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
"source.removeUnusedImports": "never",
4444
},
4545
"editor.formatOnSaveMode": "modificationsIfAvailable",
46-
"[javascript,typescript,jsonc,json]": {
47-
"editor.indentSize": "tabSize",
48-
"editor.tabSize": 2,
46+
"editor.indentSize": "tabSize",
47+
"editor.tabSize": 2,
48+
"[javascript,typescript,typescriptreact,javascriptreact,jsonc,json]": {
4949
"editor.defaultFormatter": "esbenp.prettier-vscode",
5050
"editor.formatOnSaveMode": "modificationsIfAvailable",
5151
},

0 commit comments

Comments
 (0)