Skip to content

Commit 76e2b31

Browse files
authored
Merge pull request #2 from hjungwoo01/master
Initialize Repo
2 parents 2f3e767 + 27829e1 commit 76e2b31

File tree

24 files changed

+537
-1
lines changed

24 files changed

+537
-1
lines changed

.github/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: ci
2+
on:
3+
push:
4+
branches: [ "main" ]
5+
pull_request:
6+
jobs:
7+
build-and-test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-go@v5
12+
with:
13+
go-version: "1.22"
14+
- name: Test all services
15+
run: |
16+
for d in services/*; do
17+
echo "==> Testing $d"
18+
(cd "$d" && go test ./...)
19+
done
20+
21+
docker-build:
22+
runs-on: ubuntu-latest
23+
needs: build-and-test
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: docker/setup-buildx-action@v3
27+
- name: Build images (no push)
28+
run: |
29+
for d in services/*; do
30+
name=$(basename "$d")
31+
docker build -t peerprep/$name:ci "$d"
32+
done

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Binaries
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
*.test
8+
*.out
9+
bin/
10+
dist/
11+
12+
# Go
13+
vendor/
14+
**/*.local

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/QUdQy4ix)
22
# CS3219 Project (PeerPrep) - AY2526S1
3-
## Group: Gxx
3+
## Group: G21
4+
5+
## Quick start (local)
6+
7+
```bash
8+
docker compose -f deploy/docker-compose.yaml up --build
9+
```
10+
11+
Services:
12+
- user: http://localhost:8081
13+
- question: http://localhost:8082
14+
- match: http://localhost:8083
15+
- collab: http://localhost:8084
16+
17+
MongoDB: mongodb://localhost:27017
18+
Redis: redis://localhost:6379
19+
20+
## Structure
21+
- services/<svc> : Go microservice with chi router and health endpoints
22+
- deploy/docker-compose.yaml : local dev
23+
- .github/workflows/ci.yml : minimal CI (test + build)
24+
425

526
### Note:
627
- You are required to develop individual microservices within separate folders within this repository.

deploy/docker-compose.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
services:
2+
mongo:
3+
image: mongo:7
4+
ports: ["27017:27017"]
5+
volumes: [mongo-data:/data/db]
6+
redis:
7+
image: redis:7
8+
ports: ["6379:6379"]
9+
10+
user:
11+
build: ../services/user
12+
environment:
13+
- PORT=8080
14+
- MONGO_URI=mongodb://mongo:27017
15+
- JWT_PUBLIC_KEY=dev
16+
depends_on: [mongo]
17+
ports: ["8081:8080"]
18+
19+
question:
20+
build: ../services/question
21+
environment:
22+
- PORT=8080
23+
- MONGO_URI=mongodb://mongo:27017
24+
depends_on: [mongo]
25+
ports: ["8082:8080"]
26+
27+
match:
28+
build: ../services/match
29+
environment:
30+
- PORT=8080
31+
- REDIS_URL=redis://redis:6379
32+
- MONGO_URI=mongodb://mongo:27017
33+
depends_on: [redis, mongo]
34+
ports: ["8083:8080"]
35+
36+
collab:
37+
build: ../services/collab
38+
environment:
39+
- PORT=8080
40+
- MONGO_URI=mongodb://mongo:27017
41+
depends_on: [mongo]
42+
ports: ["8084:8080"]
43+
44+
volumes:
45+
mongo-data:

services/collab/.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.git
2+
.gitignore
3+
.vscode
4+
.idea
5+
6+
bin
7+
dist
8+
*.out
9+
*.test
10+
11+
.DS_Store
12+
13+
node_modules
14+
venv

services/collab/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.22 AS build
2+
WORKDIR /app
3+
4+
COPY go.mod ./
5+
RUN go mod download
6+
7+
COPY . .
8+
RUN go mod tidy
9+
10+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/app ./cmd/server
11+
12+
FROM gcr.io/distroless/base-debian12
13+
WORKDIR /
14+
COPY --from=build /out/app /app
15+
USER 65532:65532
16+
ENV PORT=8080
17+
EXPOSE 8080
18+
ENTRYPOINT ["/app"]

services/collab/cmd/server/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
"os"
7+
"time"
8+
9+
"github.com/go-chi/chi/v5"
10+
"github.com/go-chi/chi/v5/middleware"
11+
"go.uber.org/zap"
12+
)
13+
14+
func registerRoutes(r *chi.Mux, logger *zap.Logger) {
15+
// F4.* stubs
16+
r.Post("/api/v1/session/start", func(w http.ResponseWriter, r *http.Request) {
17+
w.Write([]byte(`{"status":"session_started_stub"}`))
18+
})
19+
r.Post("/api/v1/session/end", func(w http.ResponseWriter, r *http.Request) {
20+
w.Write([]byte(`{"status":"session_ended_stub"}`))
21+
})
22+
}
23+
24+
func main() {
25+
logger, _ := zap.NewProduction()
26+
defer logger.Sync()
27+
28+
r := chi.NewRouter()
29+
r.Use(middleware.RequestID, middleware.RealIP, middleware.Logger, middleware.Recoverer, middleware.Timeout(60*time.Second))
30+
31+
r.Get("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("ok")) })
32+
registerRoutes(r, logger)
33+
34+
port := os.Getenv("PORT")
35+
if port == "" {
36+
port = "8080"
37+
}
38+
addr := ":" + port
39+
log.Printf("collab-svc listening on %s", addr)
40+
log.Fatal(http.ListenAndServe(addr, r))
41+
}

services/collab/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module peerprep/collab
2+
3+
go 1.22
4+
5+
require (
6+
github.com/go-chi/chi/v5 v5.0.12
7+
go.uber.org/zap v1.27.0
8+
)
9+
10+
require go.uber.org/multierr v1.10.0 // indirect

services/collab/go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
4+
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
8+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
9+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
10+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
11+
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
12+
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
13+
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
14+
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
15+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
16+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

services/match/.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.git
2+
.gitignore
3+
.vscode
4+
.idea
5+
6+
bin
7+
dist
8+
*.out
9+
*.test
10+
11+
.DS_Store
12+
13+
node_modules
14+
venv

0 commit comments

Comments
 (0)