diff --git a/.gitignore b/.gitignore index e43408b..0b9d991 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ logs/ *.out # Temp files (hot reload) -tmp_app/ \ No newline at end of file +tmp_app/ + +docker/db-data/ +docker/redis-data/ diff --git a/Makefile b/Makefile index 9d21567..77767e5 100644 --- a/Makefile +++ b/Makefile @@ -54,4 +54,7 @@ docs: install ## Generate the swagger docs swag init --parseDependency --parseInternal -g ./cmd/backend/main.go bot: ## Run the bot - ./script/run.sh dev bot \ No newline at end of file + ./script/run.sh dev bot + +prod-up: ## Start the container for production + ./script/run.sh prod start diff --git a/cmd/backend/main.go b/cmd/backend/main.go index a1aadda..f256533 100644 --- a/cmd/backend/main.go +++ b/cmd/backend/main.go @@ -3,14 +3,16 @@ package main import ( "bikefest/docs" "bikefest/pkg/bootstrap" + "bikefest/pkg/model" "bikefest/pkg/router" "bikefest/pkg/service" "fmt" - "github.com/hibiken/asynq" - "github.com/hibiken/asynqmon" "net/http" "net/http/httputil" + "github.com/hibiken/asynq" + "github.com/hibiken/asynqmon" + "github.com/gin-gonic/gin" swaggerfiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" @@ -79,6 +81,9 @@ func main() { AsynqService: asynqService, } + // Migration + app.Conn.AutoMigrate(&model.User{}, &model.Event{}, &model.PsychoTest{}) + // Init routes router.RegisterRoutes(app, services) diff --git a/docker/docker-compose.prod.yaml b/docker/docker-compose.prod.yaml new file mode 100644 index 0000000..3675cb2 --- /dev/null +++ b/docker/docker-compose.prod.yaml @@ -0,0 +1,58 @@ +version: "3.7" + +services: + backend: + image: ghcr.io/gdsc-ncku/bike-festival-2024-backend-backend:v1.0.0 + restart: always + pull_policy: always + env_file: + - ../.env.prod + + ports: + - 8000:8000 + networks: + - bike-networks + depends_on: + - db + - redis + + notifier: + image: ghcr.io/gdsc-ncku/bike-festival-2024-backend-notifier:v1.0.0 + restart: always + pull_policy: always + env_file: + - ../.env.prod + networks: + - bike-networks + depends_on: + - db + - redis + db: + image: postgres:latest + restart: always + environment: + POSTGRES_DATABASE: ${APP_DB_DATABASE} + POSTGRES_USER: ${APP_DB_USERNAME} + POSTGRES_PASSWORD: ${APP_DB_PASSWORD} + # ports: + # - "5432:5432" + networks: + - bike-networks + volumes: + - ./db-data:/var/lib/postgresql/data + + redis: + image: redis:latest + restart: always + environment: + TZ: ${APP_SERVER_TIMEZONE} + ports: + - ${APP_REDIS_PORT}:6379 + networks: + - bike-networks + volumes: + - ./redis-data:/data + +networks: + bike-networks: + driver: bridge diff --git a/script/run.sh b/script/run.sh index d9e87b9..e8f93ee 100755 --- a/script/run.sh +++ b/script/run.sh @@ -44,7 +44,7 @@ case "$mode" in exit 0 ;; - dev|stage|test) + dev|stage|test|prod) # All actions for these modes are handled in the next switch case block ;;