Skip to content

Commit 96ff1cb

Browse files
updates to add config to deployments
1 parent 2001194 commit 96ff1cb

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ services:
1010
- ./c#/src/:/work/
1111
ports:
1212
- 5000:5000
13-
golang: #docker run -it -v ${PWD}:/go/src/work -p 5001:5000 -p 2345:2345 --security-opt "seccomp:unconfined" aimvector/golang:1.0.0
13+
golang: #docker run -it -v ${PWD}:/go/src/work -v ${PWD}/golang/configs/:/configs -p 5001:5000 -p 2345:2345 --security-opt "seccomp:unconfined" aimvector/golang:1.0.0
1414
container_name: golang
1515
image: aimvector/golang:1.0.0
1616
build:
1717
context: ./golang
1818
target: prod
1919
volumes:
20+
- ./golang/configs:/configs/
2021
- ./golang/src/:/go/src/work/
2122
ports:
2223
- 5001:5000

golang/configs/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"environment" : "dev"
3+
}

golang/src/main.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,39 @@ import (
66
//our web server that will host the mock
77
"github.com/buaazp/fasthttprouter"
88
"github.com/valyala/fasthttp"
9+
"os"
10+
"io/ioutil"
911
)
1012

13+
var configuration []byte
14+
1115
func Response(ctx *fasthttp.RequestCtx) {
1216
fmt.Fprintf(ctx, "Hello")
1317
}
1418

1519
func Status(ctx *fasthttp.RequestCtx) {
1620
fmt.Fprintf(ctx, "ok")
1721
}
22+
23+
func ReadConfig(){
24+
fmt.Println("reading config...")
25+
config, e := ioutil.ReadFile("/configs/config.json")
26+
if e != nil {
27+
fmt.Printf("Error reading config file: %v\n", e)
28+
os.Exit(1)
29+
}
30+
configuration = config
31+
fmt.Println("config loaded!")
32+
33+
}
34+
1835
func main() {
1936

2037
fmt.Println("starting...")
21-
38+
ReadConfig()
2239
router := fasthttprouter.New()
2340
router.GET("/", Response)
2441
router.GET("/status", Status)
2542

2643
log.Fatal(fasthttp.ListenAndServe(":5000", router.Handler))
27-
}
44+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: example-config
5+
data:
6+
config.json: |
7+
{
8+
"environment" : "dev"
9+
}
10+
# kubectl create configmap example-config --from-file ./golang/configs/config.json

kubernetes/deployments/deployment.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ spec:
3030
cpu: "50m"
3131
limits:
3232
memory: "256Mi"
33-
cpu: "500m"
33+
cpu: "500m"
34+
volumeMouts:
35+
- name: config-volume
36+
mountPath: /configs/
37+
volumes:
38+
- name: config-volume
39+
configMap:
40+
name: example-config #name of our configmap object

0 commit comments

Comments
 (0)