feat(infra): add a pg db to compose file # Changes Made - Added Postgres in docker Compose file - Started working on server # Details The server does not speak with the db yet, db was only added to compose file
Brijesh brijesh@wawdhane.com
Fri, 10 May 2024 19:15:09 +0530
13 files changed,
94 insertions(+),
20 deletions(-)
A
.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml
A
.idea/k3yst0n3.iml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?> +<module type="WEB_MODULE" version="4"> + <component name="Go" enabled="true" /> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
A
.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/k3yst0n3.iml" filepath="$PROJECT_DIR$/.idea/k3yst0n3.iml" /> + </modules> + </component> +</project>
A
.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project>
M
Dockerfile
→
Dockerfile
@@ -13,7 +13,7 @@ # Copy the source from the current directory to the workspace
COPY . . # Build the Go app -RUN go build -o main . +RUN go build -o main server/main.go # Expose port 4000 to the outside world EXPOSE 4000
M
docker-compose.yaml
→
docker-compose.yaml
@@ -1,8 +1,24 @@
services: + postgres: + image: postgres:latest + environment: + - POSTGRES_DB=keystone_db + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 30s + timeout: 5s + retries: 5 + ports: + - '5432:5432' + volumes: + - postgres_volume:/var/lib/postgresql/data minio: - hostname: minio image: quay.io/minio/minio:latest command: server --console-address ":9001" /data + restart: always ports: - "9000:9000" - "9001:9001"@@ -11,19 +27,21 @@ - "9000"
- "9001" healthcheck: test: ["CMD", "mc", "ready", "local"] - interval: 5s + interval: 30s timeout: 5s retries: 5 volumes: - - data-1:/data + - minio_volume:/data k3yst0n3: hostname: k3yst0n3 build: . depends_on: + - postgres - minio ports: - 4000:4000 volumes: - data-1: + postgres_volume: + minio_volume:
M
go.mod
→
go.mod
@@ -3,6 +3,7 @@
go 1.22.2 require ( + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/labstack/echo/v4 v4.12.0 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mattn/go-colorable v0.1.13 // indirect@@ -13,4 +14,5 @@ golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect + golang.org/x/time v0.5.0 // indirect )
M
go.sum
→
go.sum
@@ -1,3 +1,5 @@
+github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=@@ -21,3 +23,5 @@ golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
A
handlers/server.go
@@ -0,0 +1,16 @@
+package handlers + +import ( + "net/http" + + "github.com/labstack/echo/v4" +) + +func HealthCHeckHandler(c echo.Context) error { + return c.JSON( + http.StatusOK, + map[string]string{ + "status": "ok", + }, + ) +}
D
k3yst0n3
D
main.go
@@ -1,15 +0,0 @@
-package main - -import ( - "fmt" - "net/http" -) - -func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, World!") - }) - - fmt.Println("Server is running on port 4000") - http.ListenAndServe(":4000", nil) -}
A
server/main.go
@@ -0,0 +1,15 @@
+package main + +import ( + "k3yst0n3/handlers" + + "github.com/labstack/echo/v4" +) + +func main() { + e := echo.New() + + e.GET("/health", handlers.HealthCHeckHandler) + + e.Logger.Fatal(e.Start(":4000")) +}