Skip to content

Commit dbdd7a6

Browse files
committed
Docker WIP (not working)
1 parent 4c0665a commit dbdd7a6

21 files changed

+202
-1928
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/.env

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/bzPrOe11)
22
# CS3219 Project (PeerPrep) - AY2425S1
3-
## Group: Gxx
3+
## Group: G14
44

55
### Note:
66
- You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice.

backend/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MONGODB_URI=mongodb+srv://<user>:<password>@<collection>.<name>.mongodb.net/?retryWrites=true&w=majority&appName=<appname>
2+
PORT=:9090
3+
CORS_ORIGIN=http://localhost:3000

backend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
questionDB.env
1+
.env
22
log

backend/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.23
4+
5+
# Set destination for COPY
6+
WORKDIR /backend
7+
8+
# Download Go modules
9+
# TODO: don't include the .env file in the COPY
10+
# TODO: multistage build
11+
COPY go.mod go.sum ./
12+
RUN go mod download
13+
14+
# Copy the source code. Note the slash at the end, as explained in
15+
# https://docs.docker.com/reference/dockerfile/#copy
16+
COPY . .
17+
18+
# Build
19+
RUN CGO_ENABLED=0 GOOS=linux go build -o /backend/app
20+
21+
# Optional:
22+
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
23+
# But we can document in the Dockerfile what ports
24+
# the application is going to listen on by default.
25+
# https://docs.docker.com/reference/dockerfile/#expose
26+
EXPOSE 9090
27+
28+
# Run
29+
CMD ["/backend/app"]

backend/database/initialise_database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func InitialiseDB() (*mongo.Client, error) {
1515
// Load environment variables
16-
err := godotenv.Load("questionDB.env")
16+
err := godotenv.Load(".env")
1717

1818
if err != nil {
1919
log.Fatal("Error loading environment variables: " + err.Error())

backend/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
func main() {
2222
//initialise logger file and directory if they do not exist
2323

24-
err := godotenv.Load("questionDB.env")
24+
err := godotenv.Load(".env")
2525
if err != nil {
2626
log.Fatal("Error loading environment variables: " + err.Error())
2727
}

backend/transport/health.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package transport
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"net/http"
6+
"peerprep/common"
7+
)
8+
9+
func HealthCheck(logger *common.Logger) gin.HandlerFunc {
10+
return func(ctx *gin.Context) {
11+
ctx.JSON(http.StatusOK, gin.H{"Status": "healthy"})
12+
logger.Log.Info("Health check successful")
13+
}
14+
}

backend/transport/question_http_requests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func SetAllEndpoints(router *gin.Engine, db *database.QuestionDB, logger *common
1818
router.GET("/questions/solve/:id", GetQuestionWithLogger(db, logger))
1919
router.DELETE("/questions/delete/:id", DeleteQuestionWithLogger(db, logger))
2020
router.PUT("/questions/replace/:id", ReplaceQuestionWithLogger(db, logger))
21+
router.GET("/health", HealthCheck(logger))
2122
}
2223

2324
// enable CORS for the frontend

compose.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
services:
2+
peerprep:
3+
build: peerprep
4+
env_file:
5+
- peerprep/.env
6+
ports:
7+
- "3000:3000"
8+
extra_hosts:
9+
- "host.docker.internal:host-gateway"
10+
11+
develop:
12+
watch:
13+
- action: sync
14+
path: peerprep
15+
target: /frontend
16+
17+
user-service:
18+
build: user-service
19+
volumes:
20+
- /app/node_modules
21+
env_file:
22+
- user-service/.env
23+
extra_hosts:
24+
- "host.docker.internal:host-gateway"
25+
ports:
26+
- "3001:3001"
27+
develop:
28+
watch:
29+
- action: rebuild
30+
path: user-service
31+
target: /user-service
32+
33+
34+
backend:
35+
build: backend
36+
env_file:
37+
- backend/.env
38+
ports:
39+
- "9090:9090"
40+
develop:
41+
watch:
42+
- action: rebuild
43+
path: backend
44+
target: backend/app
45+
46+
# mongo:
47+
# image: "mongo:latest"
48+
# ports:
49+
# - "27017:27017"

0 commit comments

Comments
 (0)