adding environment variables
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
certbot/
|
||||
.env
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
@@ -13,7 +15,17 @@ import (
|
||||
)
|
||||
|
||||
func connectToPostgreSQL() (*gorm.DB, error) {
|
||||
dsn := "user=postgres password=password dbname=db host=localhost port=5432 sslmode=disable"
|
||||
user := os.Getenv("POSTGRES_USER")
|
||||
password := os.Getenv("POSTGRES_PASSWORD")
|
||||
dbname := os.Getenv("POSTGRES_DB")
|
||||
host := os.Getenv("POSTGRES_HOST")
|
||||
port := os.Getenv("DB_PORT")
|
||||
|
||||
dsn := fmt.Sprintf(
|
||||
"user=%s password=%s dbname=%s host=%s port=%s sslmode=disable",
|
||||
user, password, dbname, host, port,
|
||||
)
|
||||
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -47,15 +59,19 @@ func main() {
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
h := handlers.Handler{DB: db}
|
||||
store := handlers.Store{DB: db}
|
||||
|
||||
r.GET("/posts", h.GetPosts)
|
||||
r.POST("/posts", h.CreatePost)
|
||||
r.PUT("/posts/:id", h.UpdatePost)
|
||||
r.GET("/posts", store.GetPosts)
|
||||
r.POST("/posts", store.CreatePost)
|
||||
r.PUT("/posts/:id", store.UpdatePost)
|
||||
|
||||
r.GET("/spotify", store.ListeningTo)
|
||||
r.POST("/spotify", store.SendSong)
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"message": "Hello World"})
|
||||
})
|
||||
|
||||
r.Run()
|
||||
port := os.Getenv("PORT")
|
||||
r.Run(fmt.Sprintf(":%s", port))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ services:
|
||||
container_name: nginx
|
||||
restart: unless-stopped
|
||||
image: nginx
|
||||
networks:
|
||||
- app-network
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
@@ -19,6 +21,8 @@ services:
|
||||
- ./certbot/conf:/etc/letsencrypt
|
||||
- ./certbot/www:/var/www/certbot
|
||||
command: certonly --webroot -w /var/www/certbot --email adam.a.french@outlook.com -d adam-french.co.uk --agree-tos
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
backend:
|
||||
build:
|
||||
@@ -26,16 +30,22 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
container_name: backend
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8080:8080
|
||||
# ports:
|
||||
# - "${BACKEND_PORT}:8080"
|
||||
depends_on:
|
||||
- db
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
db:
|
||||
image: postgres:16
|
||||
container_name: db
|
||||
container_name: "${POSTGRES_HOST}"
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_DB: db
|
||||
ports:
|
||||
- 5432:5432
|
||||
POSTGRES_USER: "${POSTGRES_USER}"
|
||||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
||||
POSTGRES_DB: "${POSTGRES_DB}"
|
||||
# ports:
|
||||
# - "${DB_PORT}:5432"
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
Reference in New Issue
Block a user