Skip to content

Commit 162d8db

Browse files
committed
Merge branch 'dev' into models
2 parents d68aeb6 + 83e7d07 commit 162d8db

File tree

9 files changed

+95
-4
lines changed

9 files changed

+95
-4
lines changed

.env

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
STORAGE_HOST=localhost
22
STORAGE_PORT=5432
33
STORAGE_DBUSER=postgres
4-
STORAGE_DBPASSWORD="1772"
4+
STORAGE_DBPASSWORD=1772
55
STORAGE_HANDLERNAME=postgresql
66
STORAGE_URL=mongodb://localhost:27017
77
STORAGE_DATABASE=go_lms
8-
ADDRESS=0.0.0.0:3000
8+
ADDRESS=0.0.0.0:3000
9+
REDIS_HOST=redis

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.14
2+
3+
WORKDIR /Go-LMS
4+
5+
COPY go.mod ./
6+
7+
RUN go mod tidy
8+
9+
RUN go mod download
10+
11+
RUN go get github.com/githubnemo/CompileDaemon
12+
13+
ENTRYPOINT export STORAGE_HOST=db && CompileDaemon --build="go build cmd/graphql/main.go" --command="./main"

configs/db.config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ func LoadConfig() (*AppConfig, error) {
3939
if err != nil {
4040
return nil, err
4141
}
42-
if conf.Storage == (Storage{}) {
42+
if conf.Storage.Host == "db" || conf.Storage == (Storage{}) {
4343
err = godotenv.Load()
4444
if err != nil {
4545
return nil, err
4646
}
47+
4748
storage := Storage{
4849
HandlerName: os.Getenv("STORAGE_HANDLERNAME"),
4950
Host: os.Getenv("STORAGE_HOST"),
@@ -53,6 +54,11 @@ func LoadConfig() (*AppConfig, error) {
5354
Dbuser: os.Getenv("STORAGE_DBUSER"),
5455
Dbpassword: os.Getenv("STORAGE_DBPASSWORD"),
5556
}
57+
// If running in docker-compose, we should check if STORAGE_HOST was set.
58+
if conf.Storage.Host == "db" {
59+
storage.Host = conf.Storage.Host
60+
}
61+
5662
tls := TLS{
5763
Key: os.Getenv("TLS_KEY"),
5864
Crt: os.Getenv("TLS_CRT"),

configs/server.config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var CFG struct {
2525
MaxmemoryPolicy string `envconfig:"MAXMEMORY_POLICY"`
2626
}
2727
DB struct {
28-
Host string `default:"127.0.0.1:5433" envconfig:"DB_HOST"`
28+
Host string `default:"127.0.0.1:5433" envconfig:"STORAGE_HOST"`
2929
User string `default:"postgres" envconfig:"DB_HOST"`
3030
Pass string `default:"postgres" envconfig:"DB_PASS" json:"-"`
3131
Database string `default:"shared" envconfig:"DATABASE"`

docker-compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
build:
6+
context: ./postgres
7+
args:
8+
- POSTGRES_DB=${STORAGE_DATABASE}
9+
- POSTGRES_USER=${STORAGE_DBUSER}
10+
- POSTGRES_PASSWORD=${STORAGE_DBPASSWORD}
11+
ports:
12+
- "127.0.0.1:5432:5432"
13+
environment:
14+
- POSTGRES_DB=${STORAGE_DATABASE}
15+
- POSTGRES_USER=${STORAGE_DBUSER}
16+
- POSTGRES_PASSWORD=${STORAGE_DBPASSWORD}
17+
networks:
18+
- pupilgo
19+
redis:
20+
image: "redis:alpine"
21+
restart: unless-stopped
22+
networks:
23+
- pupilgo
24+
backend:
25+
build: .
26+
ports:
27+
- "8000:3000"
28+
restart: unless-stopped
29+
depends_on:
30+
- db
31+
- redis
32+
volumes:
33+
- ./:/Go-LMS
34+
environment:
35+
REDIS_URL: redis:6379
36+
networks:
37+
- pupilgo
38+
frontend:
39+
build: ./user-interface
40+
command: npm run start
41+
ports:
42+
- "3000:3000"
43+
depends_on:
44+
- backend
45+
volumes:
46+
- /user-interface/node_modules
47+
- ./user-interface:/user-interface
48+
networks:
49+
- pupilgo
50+
stdin_open: true
51+
52+
networks:
53+
pupilgo:

docs/assets/go-lms-uml.png

559 KB
Loading

postgres/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM postgres:12.3
2+
3+
ARG POSTGRES_DB
4+
ARG POSTGRES_USER
5+
ARG POSTGRES_PASSWORD
6+
7+
COPY load-extensions.sh /docker-entrypoint-initdb.d

postgres/load-extensions.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
psql -v ON_ERROR_STOP=1 --dbname "$POSTGRES_DB" --username "$POSTGRES_USER" <<EOF
2+
create extension "uuid-ossp";
3+
select * FROM pg_extension;
4+
EOF

user-interface/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:14.4
2+
3+
WORKDIR /user-interface/
4+
5+
COPY package.json ./
6+
7+
RUN npm install

0 commit comments

Comments
 (0)