mirror of
https://github.com/marcel-dempers/docker-development-youtube-series.git
synced 2025-06-04 16:56:56 +00:00
updates to add config to deployments
This commit is contained in:
parent
20011946e7
commit
96ff1cb1f8
@ -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
|
||||
|
3
golang/configs/config.json
Normal file
3
golang/configs/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"environment" : "dev"
|
||||
}
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
10
kubernetes/configmaps/configmap.yaml
Normal file
10
kubernetes/configmaps/configmap.yaml
Normal 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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user