Skip to content

Commit 5c1220e

Browse files
committed
Dockerize development environment.
1 parent f34a4f6 commit 5c1220e

File tree

12 files changed

+112
-62
lines changed

12 files changed

+112
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Run the following commands
2121
go run cmd/go-graphkb/main.go start
2222

2323
# In another terminal start the web server with the following
24-
# command to acces the web UI at http://127.0.0.1:8090
24+
# command to acces the web UI at http://127.0.0.1:3000
2525
go run cmd/go-graphkb/main.go listen
2626

2727

bootstrap.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
if [ -z "$OLD_PS1" ]; then
4+
OLD_PS1="$PS1"
5+
export PS1="(graphkb) $PS1"
6+
fi
7+
8+
if [ $(id -u) = 0 ]; then
9+
echo "Cannot run as root, defaulting to UID 1000"
10+
export USER_ID=1000
11+
else
12+
export USER_ID=$(id -u)
13+
fi
14+
15+
if [ $(id -g) = 0 ]; then
16+
echo "Cannot run as root, defaulting to GID 1000"
17+
export GROUP_ID=1000
18+
else
19+
export GROUP_ID=$(id -g)
20+
fi
21+

cmd/go-graphkb/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
port: 8090
2-
tls_key: keys/server.key
3-
tls_cert: keys/server.crt
1+
port: 8080
2+
# tls_key: cmd/go-graphkb/keys/server.key
3+
# tls_cert: cmd/go-graphkb/keys/server.crt
44

55
mariadb:
66
username: graphkb
77
password: password
8-
host:
8+
host: db
99
database: graphkb
1010

1111
sources:

cmd/importer-csv/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
graphkb:
2-
url: "https://localhost:8090"
2+
url: "http://localhost:8080"
33
auth_token: "token_auth_for_csv_importer"
44
skip_verify: true
55

docker-compose.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,40 @@ services:
1313
MYSQL_DATABASE: graphkb
1414
MYSQL_USER: graphkb
1515
MYSQL_PASSWORD: password
16-
volumes:
17-
- /var/lib/go-graphkb:/var/lib/mysql
16+
## Uncomment to persist database on host disk
17+
# volumes:
18+
# - /var/lib/go-graphkb:/var/lib/mysql
1819

1920
adminer:
2021
image: adminer
2122
restart: always
23+
ports:
24+
- 8090:8080
25+
26+
frontend:
27+
build:
28+
context: docker
29+
dockerfile: Dockerfile.frontend
30+
args:
31+
USER_ID: ${USER_ID}
32+
GROUP_ID: ${GROUP_ID}
33+
command: "sh -c 'npm ci && npm run start'"
34+
working_dir: "/app"
35+
volumes:
36+
- ./web:/app
37+
ports:
38+
- 3000:3000
39+
40+
graphkb:
41+
build:
42+
context: docker
43+
dockerfile: Dockerfile.graphkb
44+
args:
45+
USER_ID: ${USER_ID}
46+
GROUP_ID: ${GROUP_ID}
47+
entrypoint: "./scripts/graphkb-entrypoint.sh"
48+
working_dir: "/app"
49+
volumes:
50+
- .:/app
2251
ports:
2352
- 8080:8080

docker/Dockerfile.frontend

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:12-alpine
2+
3+
ARG USER_ID
4+
ARG GROUP_ID
5+
6+
RUN deluser node && \
7+
addgroup --gid ${GROUP_ID} dev && \
8+
adduser --uid ${USER_ID} -G dev -D dev
9+
USER dev

docker/Dockerfile.graphkb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.13-alpine
2+
3+
ARG USER_ID
4+
ARG GROUP_ID
5+
6+
RUN addgroup --gid ${GROUP_ID} dev && \
7+
adduser --uid ${USER_ID} -G dev -D dev
8+
9+
USER dev

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ go 1.13
55
require (
66
github.com/abbot/go-http-auth v0.4.0
77
github.com/antlr/antlr4 v0.0.0-20200103163232-691acdc23f1f
8+
github.com/cespare/reflex v0.2.0 // indirect
89
github.com/cheggaaa/pb v2.0.7+incompatible
910
github.com/deckarep/golang-set v1.7.1
1011
github.com/go-sql-driver/mysql v1.5.0
1112
github.com/golang-collections/go-datastructures v0.0.0-20150211160725-59788d5eb259
1213
github.com/gorilla/mux v1.7.3
13-
github.com/hashicorp/consul/api v1.3.0
14+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
15+
github.com/mattn/go-colorable v0.0.9 // indirect
16+
github.com/mattn/go-isatty v0.0.3 // indirect
17+
github.com/ogier/pflag v0.0.1 // indirect
1418
github.com/spf13/cobra v0.0.5
1519
github.com/spf13/viper v1.6.1
1620
github.com/stretchr/testify v1.3.0

go.sum

Lines changed: 15 additions & 49 deletions
Large diffs are not rendered by default.

internal/server/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,15 @@ func StartServer(database knowledge.GraphDB, schemaPersistor schema.Persistor,
364364
bindInterface := fmt.Sprintf(":%d", viper.GetInt32("port"))
365365
fmt.Printf("Listening on %s\n", bindInterface)
366366

367-
err := http.ListenAndServeTLS(bindInterface, viper.GetString("tls_cert"),
368-
viper.GetString("tls_key"), r)
367+
var err error
368+
if viper.GetString("tls_cert") != "" {
369+
fmt.Println("Server is using TLS, the connection is secure")
370+
err = http.ListenAndServeTLS(bindInterface, viper.GetString("tls_cert"),
371+
viper.GetString("tls_key"), r)
372+
} else {
373+
fmt.Println("[WARNING] Server is NOT using TLS, the connection is not secure")
374+
err = http.ListenAndServe(bindInterface, r)
375+
}
369376
if err != nil {
370377
log.Fatal(err)
371378
}

0 commit comments

Comments
 (0)