Skip to content

Commit

Permalink
ci(docker): use docker compose yaml anchor values and extension fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed Mar 24, 2022
1 parent 786937f commit ff8b222
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 123 deletions.
8 changes: 6 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
"extensions": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "lokalise.i18n-ally"],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 3100, 3200, 5432],
"forwardPorts": [80, 5432],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm install",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
"remoteUser": "node",

"features": {
"docker-from-docker": "latest"
}
}
21 changes: 8 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Global
# Shared
TZ=UTC
PUBLIC_URL=http://localhost
PUBLIC_SERVER_URL=http://localhost/api
PUBLIC_GOOGLE_CLIENT_ID=

# Server
SECRET_KEY=
PUBLIC_URL=http://<SERVER-IP>
POSTGRES_HOST=localhost
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DATABASE=postgres
POSTGRES_SSL_CERT=
Expand All @@ -20,12 +22,5 @@ SENDGRID_FORGOT_PASSWORD_TEMPLATE_ID=
SENDGRID_FROM_NAME=
SENDGRID_FROM_EMAIL=

# Client
PUBLIC_URL=http://<SERVER-IP>
PUBLIC_SERVER_URL=http://<SERVER-IP>/api
PUBLIC_GOOGLE_CLIENT_ID=

# Postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DATABASE=postgres
# Flags
PUBLIC_FLAG_DISABLE_SIGNUPS=false
71 changes: 0 additions & 71 deletions docker-compose.dev.yml

This file was deleted.

72 changes: 38 additions & 34 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
version: '3'

x-env-shared: &env-shared
environment:
- TZ=UTC
- PUBLIC_URL=http://localhost
- PUBLIC_SERVER_URL=http://localhost/api
- PUBLIC_GOOGLE_CLIENT_ID=

x-env-server: &env-server
environment:
- SECRET_KEY=
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DATABASE=postgres
- POSTGRES_SSL_CERT=
- JWT_SECRET=
- JWT_EXPIRY_TIME=604800
- PUBLIC_GOOGLE_CLIENT_ID=
- GOOGLE_CLIENT_SECRET=
- GOOGLE_API_KEY=
- SENDGRID_API_KEY=
- SENDGRID_FORGOT_PASSWORD_TEMPLATE_ID=
- SENDGRID_FROM_NAME=
- SENDGRID_FROM_EMAIL=

x-env-flags: &env-flags
environment:
- PUBLIC_FLAG_DISABLE_SIGNUPS=false

services:
postgres:
image: postgres:14.2-alpine
container_name: postgres
ports:
- 5432:5432
environment:
- POSTGRES_USER="postgres"
- POSTGRES_PASSWORD="postgres"
- POSTGRES_DATABASE="postgres"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres" ]
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
start_period: 15s
interval: 30s
timeout: 30s
start_period: 15s
retries: 3
restart: always

Expand All @@ -35,32 +59,15 @@ services:
server:
image: amruthpillai/reactive-resume:server-latest
container_name: server
environment:
- TZ="UTC"
- SECRET_KEY=""
- PUBLIC_URL="http://<SERVER-IP>"
- POSTGRES_HOST="postgres"
- POSTGRES_PORT="5432"
- POSTGRES_USERNAME="postgres"
- POSTGRES_PASSWORD="postgres"
- POSTGRES_DATABASE="postgres"
- POSTGRES_SSL_CERT=""
- JWT_SECRET=""
- JWT_EXPIRY_TIME="604800"
- PUBLIC_GOOGLE_CLIENT_ID=""
- GOOGLE_CLIENT_SECRET=""
- GOOGLE_API_KEY=""
- SENDGRID_API_KEY="" # Optional
- SENDGRID_FORGOT_PASSWORD_TEMPLATE_ID="" # Optional
- SENDGRID_FROM_NAME="" # Optional
- SENDGRID_FROM_EMAIL="" # Optional
<<: *env-shared
<<: *env-server
depends_on:
- traefik
- postgres
labels:
- traefik.enable=true
- traefik.http.routers.server.entrypoints=web
- traefik.http.routers.server.rule=Host(`<SERVER-IP>`) && PathPrefix(`/api/`)
- traefik.http.routers.server.rule=Host(`localhost`) && PathPrefix(`/api/`)
- traefik.http.routers.server.middlewares=server-stripprefix
- traefik.http.middlewares.server-stripprefix.stripprefix.prefixes=/api
- traefik.http.middlewares.server-stripprefix.stripprefix.forceslash=true
Expand All @@ -69,17 +76,14 @@ services:
client:
image: amruthpillai/reactive-resume:client-latest
container_name: client
environment:
- TZ="UTC"
- PUBLIC_URL="http://<SERVER-IP>"
- PUBLIC_SERVER_URL="http://<SERVER-IP>/api"
- PUBLIC_GOOGLE_CLIENT_ID=""
<<: *env-shared
<<: *env-flags
depends_on:
- traefik
- server
labels:
- traefik.enable=true
- traefik.http.routers.client.rule=Host(`<SERVER-IP>`)
- traefik.http.routers.client.rule=Host(`localhost`)
- traefik.http.routers.client.entrypoints=web
restart: always

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/source-code/env-vars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This URL is used when export PDF functionality is used within the app and has to
**Default Value:** `5432`
**Description:** Port of the PostgreSQL Server

### `POSTGRES_USERNAME`
### `POSTGRES_USER`

**Required**: `yes`
**Default Value:** `postgres`
Expand Down
2 changes: 1 addition & 1 deletion server/src/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const validationSchema = Joi.object({
// Database
POSTGRES_HOST: Joi.string().required(),
POSTGRES_PORT: Joi.number().default(5432),
POSTGRES_USERNAME: Joi.string().required(),
POSTGRES_USER: Joi.string().required(),
POSTGRES_PASSWORD: Joi.string().required(),
POSTGRES_DATABASE: Joi.string().required(),
POSTGRES_SSL_CERT: Joi.string().allow(''),
Expand Down
2 changes: 1 addition & 1 deletion server/src/config/database.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { registerAs } from '@nestjs/config';
export default registerAs('postgres', () => ({
host: process.env.POSTGRES_HOST,
port: parseInt(process.env.POSTGRES_PORT, 10) || 5432,
username: process.env.POSTGRES_USERNAME,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DATABASE,
certificate: process.env.POSTGRES_SSL_CERT,
Expand Down

0 comments on commit ff8b222

Please sign in to comment.