Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JOH-37] Migrate from Config to Envs #28

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APP_PORT=3001
APP_ENV=development

SERVICE_AUTH=localhost:3002
SERVICE_BACKEND=localhost:3003
SERVICE_FILE=localhost:3004
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test:
go tool cover -html=coverage.out -o coverage.html

server:
go run ./src/.
. ./tools/export-env.sh ; go run ./src/.

mock-gen:
mockgen -source ./src/pkg/service/auth/auth.service.go -destination ./src/mocks/service/auth/auth.mock.go
Expand Down
23 changes: 0 additions & 23 deletions config/auth/config.example.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions config/backend/config.example.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions config/config.example.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions config/file/config.example.yaml

This file was deleted.

119 changes: 119 additions & 0 deletions docker-compose-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
version: "3.9"

services:
gateway:
container_name: johnjud-gateway
restart: unless-stopped
build: .
ports:
- 3001:3001
environment:
- APP_PORT=3001
- APP_ENV=development
- SERVICE_AUTH=auth:3002
- SERVICE_BACKEND=backend:3003
- SERVICE_FILE=file:3004
networks:
- johnjud-local
local-auth:
image: ghcr.io/isd-sgcu/johnjud-auth
container_name: auth
depends_on:
- local-db
- local-cache
restart: unless-stopped
environment:
- APP_PORT=3004
- APP_ENV=production
- APP_SECRET=secret
- DB_URL=postgres://root:root@local-db:5432/johnjud_db
- JWT_SECRET=secret
- JWT_EXPIRES_IN=3600
- JWT_REFRESH_TOKEN_TTL=604800
- JWT_ISSUER=issuer
- JWT_RESET_TOKEN_TTL=900
- REDIS_HOST=localhost
- REDIS_PORT=6379
- REDIS_PASSWORD=
- AUTH_CLIENT_URL=http://localhost:3000
- SENDGRID_API_KEY=api_key
- SENDGRID_NAME=johnjud
- [email protected]
networks:
- johnjud-local
- database
ports:
- "3002:3002"

local-backend:
image: ghcr.io/isd-sgcu/johnjud-backend
container_name: backend
depends_on:
- local-db
- local-cache
restart: unless-stopped
environment:
- APP_PORT=3003
- APP_ENV=production
- DB_URL=postgres://root:root@local-db:5432/johnjud_db
- SERVICE_FILE=file:3004
networks:
- johnjud-local
- database
ports:
- "3003:3003"

local-file:
image: ghcr.io/isd-sgcu/johnjud-file
container_name: file
depends_on:
- local-db
- local-cache
restart: unless-stopped
environment:
- APP_PORT=3004
- APP_ENV=production
- DB_URL=postgres://root:root@local-db:5432/johnjud_db
- BUCKET_ENDPOINT=BUCKET_ENDPOINT
- BUCKET_ACCESS_KEY=BUCKET_ACCESS_KEY
- BUCKET_SECRET_KEY=BUCKET_SECRET_KEY
- BUCKET_NAME=johnjud-pet-images
- BUCKET_USE_SSL=false
networks:
- johnjud-local
- database
ports:
- "3004:3004"

local-db:
image: postgres:15.1-alpine3.17
container_name: local-db
restart: unless-stopped
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: johnjud_db
networks:
- database
volumes:
- ./volumes/postgres:/var/lib/postgresql/data
ports:
- "5432:5432"

local-cache:
image: redis:7.2.3-alpine
container_name: local-cache
restart: unless-stopped
environment:
REDIS_HOST: localhost
ALLOW_EMPTY_PASSWORD: "yes"
networks:
- database
ports:
- "6379:6379"

networks:
johnjud-local:
name: johnjud-local
database:
name: database
37 changes: 31 additions & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ services:
- local-db
- local-cache
restart: unless-stopped
environment:
- APP_PORT=3004
- APP_ENV=development
- APP_SECRET=secret
- DB_URL=postgres://root:root@local-db:5432/johnjud_db
- JWT_SECRET=secret
- JWT_EXPIRES_IN=3600
- JWT_REFRESH_TOKEN_TTL=604800
- JWT_ISSUER=issuer
- JWT_RESET_TOKEN_TTL=900
- REDIS_HOST=localhost
- REDIS_PORT=6379
- REDIS_PASSWORD=
- AUTH_CLIENT_URL=http://localhost:3000
- SENDGRID_API_KEY=api_key
- SENDGRID_NAME=johnjud
- [email protected]
networks:
- johnjud-local
- database
volumes:
- ./config/auth:/app/config
ports:
- "3002:3002"

Expand All @@ -23,11 +38,14 @@ services:
- local-db
- local-cache
restart: unless-stopped
environment:
- APP_PORT=3003
- APP_ENV=development
- DB_URL=postgres://root:root@local-db:5432/johnjud_db
- SERVICE_FILE=file:3004
networks:
- johnjud-local
- database
volumes:
- ./config/backend:/app/config
ports:
- "3003:3003"

Expand All @@ -38,11 +56,18 @@ services:
- local-db
- local-cache
restart: unless-stopped
environment:
- APP_PORT=3004
- APP_ENV=production
- DB_URL=postgres://root:root@local-db:5432/johnjud_db
- BUCKET_ENDPOINT=BUCKET_ENDPOINT
- BUCKET_ACCESS_KEY=BUCKET_ACCESS_KEY
- BUCKET_SECRET_KEY=BUCKET_SECRET_KEY
- BUCKET_NAME=johnjud-pet-images
- BUCKET_USE_SSL=false
networks:
- johnjud-local
- database
volumes:
- ./config/file:/app/config
ports:
- "3004:3004"

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ require (
github.com/golang/mock v1.6.0
github.com/google/uuid v1.5.0
github.com/isd-sgcu/johnjud-go-proto v0.5.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.18.1
github.com/stretchr/testify v1.8.4
github.com/swaggo/swag v1.16.2
google.golang.org/grpc v1.60.1
Expand Down
9 changes: 2 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/isd-sgcu/johnjud-go-proto v0.2.2 h1:TOAmbwy/I+8/J5LPZH0ZN7lSLczBiZe1fs88gH8XrhY=
github.com/isd-sgcu/johnjud-go-proto v0.2.2/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4=
github.com/isd-sgcu/johnjud-go-proto v0.3.1 h1:WyWfzl+5nWOw3AmINtcTfojg4CJh8ZRNbZC6qA//OXU=
github.com/isd-sgcu/johnjud-go-proto v0.3.1/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4=
github.com/isd-sgcu/johnjud-go-proto v0.5.0 h1:GgqRzWjya5p1yhfU/kpX8i4WL42+qT2TkyXZmssH6B4=
github.com/isd-sgcu/johnjud-go-proto v0.5.0/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down Expand Up @@ -112,7 +108,6 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand Down Expand Up @@ -141,8 +136,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM=
github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
Expand Down
4 changes: 2 additions & 2 deletions src/app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type IGuard interface {
}

func NewAPIv1(r *FiberRouter, conf config.App) *fiber.App {
if conf.Debug {
if conf.IsDevelopment() {
r.Use(logger.New(logger.Config{Next: func(c *fiber.Ctx) bool {
return c.Path() == "/v1/"
}}))
Expand All @@ -32,7 +32,7 @@ func NewAPIv1(r *FiberRouter, conf config.App) *fiber.App {
app := fiber.New(fiber.Config{
StrictRouting: true,
AppName: "JohnJud API",
EnablePrintRoutes: conf.Debug,
EnablePrintRoutes: conf.IsDevelopment(),
})

app.Mount("/v1", r.App)
Expand Down
Loading
Loading