Skip to content

Commit

Permalink
Dockerize development environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
clems4ever committed Jan 9, 2020
1 parent f34a4f6 commit 5c1220e
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Run the following commands
go run cmd/go-graphkb/main.go start

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


Expand Down
21 changes: 21 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ -z "$OLD_PS1" ]; then
OLD_PS1="$PS1"
export PS1="(graphkb) $PS1"
fi

if [ $(id -u) = 0 ]; then
echo "Cannot run as root, defaulting to UID 1000"
export USER_ID=1000
else
export USER_ID=$(id -u)
fi

if [ $(id -g) = 0 ]; then
echo "Cannot run as root, defaulting to GID 1000"
export GROUP_ID=1000
else
export GROUP_ID=$(id -g)
fi

8 changes: 4 additions & 4 deletions cmd/go-graphkb/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
port: 8090
tls_key: keys/server.key
tls_cert: keys/server.crt
port: 8080
# tls_key: cmd/go-graphkb/keys/server.key
# tls_cert: cmd/go-graphkb/keys/server.crt

mariadb:
username: graphkb
password: password
host:
host: db
database: graphkb

sources:
Expand Down
2 changes: 1 addition & 1 deletion cmd/importer-csv/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
graphkb:
url: "https://localhost:8090"
url: "http://localhost:8080"
auth_token: "token_auth_for_csv_importer"
skip_verify: true

Expand Down
33 changes: 31 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,40 @@ services:
MYSQL_DATABASE: graphkb
MYSQL_USER: graphkb
MYSQL_PASSWORD: password
volumes:
- /var/lib/go-graphkb:/var/lib/mysql
## Uncomment to persist database on host disk
# volumes:
# - /var/lib/go-graphkb:/var/lib/mysql

adminer:
image: adminer
restart: always
ports:
- 8090:8080

frontend:
build:
context: docker
dockerfile: Dockerfile.frontend
args:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
command: "sh -c 'npm ci && npm run start'"
working_dir: "/app"
volumes:
- ./web:/app
ports:
- 3000:3000

graphkb:
build:
context: docker
dockerfile: Dockerfile.graphkb
args:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
entrypoint: "./scripts/graphkb-entrypoint.sh"
working_dir: "/app"
volumes:
- .:/app
ports:
- 8080:8080
9 changes: 9 additions & 0 deletions docker/Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:12-alpine

ARG USER_ID
ARG GROUP_ID

RUN deluser node && \
addgroup --gid ${GROUP_ID} dev && \
adduser --uid ${USER_ID} -G dev -D dev
USER dev
9 changes: 9 additions & 0 deletions docker/Dockerfile.graphkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.13-alpine

ARG USER_ID
ARG GROUP_ID

RUN addgroup --gid ${GROUP_ID} dev && \
adduser --uid ${USER_ID} -G dev -D dev

USER dev
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ go 1.13
require (
github.com/abbot/go-http-auth v0.4.0
github.com/antlr/antlr4 v0.0.0-20200103163232-691acdc23f1f
github.com/cespare/reflex v0.2.0 // indirect
github.com/cheggaaa/pb v2.0.7+incompatible
github.com/deckarep/golang-set v1.7.1
github.com/go-sql-driver/mysql v1.5.0
github.com/golang-collections/go-datastructures v0.0.0-20150211160725-59788d5eb259
github.com/gorilla/mux v1.7.3
github.com/hashicorp/consul/api v1.3.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/ogier/pflag v0.0.1 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.3.0
Expand Down
64 changes: 15 additions & 49 deletions go.sum

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,15 @@ func StartServer(database knowledge.GraphDB, schemaPersistor schema.Persistor,
bindInterface := fmt.Sprintf(":%d", viper.GetInt32("port"))
fmt.Printf("Listening on %s\n", bindInterface)

err := http.ListenAndServeTLS(bindInterface, viper.GetString("tls_cert"),
viper.GetString("tls_key"), r)
var err error
if viper.GetString("tls_cert") != "" {
fmt.Println("Server is using TLS, the connection is secure")
err = http.ListenAndServeTLS(bindInterface, viper.GetString("tls_cert"),
viper.GetString("tls_key"), r)
} else {
fmt.Println("[WARNING] Server is NOT using TLS, the connection is not secure")
err = http.ListenAndServe(bindInterface, r)
}
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions scripts/graphkb-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

go get github.com/cespare/reflex

reflex -r '\.go|\.yml' -s -- sh -c "go run cmd/go-graphkb/main.go --config cmd/go-graphkb/config.yml listen"
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
"last 1 safari version"
]
},
"proxy": "http://localhost:8090"
}
"proxy": "http://graphkb:8080"
}

0 comments on commit 5c1220e

Please sign in to comment.