updates to add config to deployments

This commit is contained in:
marcel-dempers 2019-09-12 03:47:31 +00:00
parent 20011946e7
commit 96ff1cb1f8
5 changed files with 42 additions and 4 deletions

View File

@ -10,13 +10,14 @@ services:
- ./c#/src/:/work/
ports:
- 5000:5000
golang: #docker run -it -v ${PWD}:/go/src/work -p 5001:5000 -p 2345:2345 --security-opt "seccomp:unconfined" aimvector/golang:1.0.0
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
container_name: golang
image: aimvector/golang:1.0.0
build:
context: ./golang
target: prod
volumes:
- ./golang/configs:/configs/
- ./golang/src/:/go/src/work/
ports:
- 5001:5000

View File

@ -0,0 +1,3 @@
{
"environment" : "dev"
}

View File

@ -6,8 +6,12 @@ import (
//our web server that will host the mock
"github.com/buaazp/fasthttprouter"
"github.com/valyala/fasthttp"
"os"
"io/ioutil"
)
var configuration []byte
func Response(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello")
}
@ -15,13 +19,26 @@ func Response(ctx *fasthttp.RequestCtx) {
func Status(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "ok")
}
func ReadConfig(){
fmt.Println("reading config...")
config, e := ioutil.ReadFile("/configs/config.json")
if e != nil {
fmt.Printf("Error reading config file: %v\n", e)
os.Exit(1)
}
configuration = config
fmt.Println("config loaded!")
}
func main() {
fmt.Println("starting...")
ReadConfig()
router := fasthttprouter.New()
router.GET("/", Response)
router.GET("/status", Status)
log.Fatal(fasthttp.ListenAndServe(":5000", router.Handler))
}
}

View File

@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: example-config
data:
config.json: |
{
"environment" : "dev"
}
# kubectl create configmap example-config --from-file ./golang/configs/config.json

View File

@ -30,4 +30,11 @@ spec:
cpu: "50m"
limits:
memory: "256Mi"
cpu: "500m"
cpu: "500m"
volumeMouts:
- name: config-volume
mountPath: /configs/
volumes:
- name: config-volume
configMap:
name: example-config #name of our configmap object