Skip to content

Commit

Permalink
Go templates for core service stack files
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegory committed Dec 13, 2017
1 parent 9c62850 commit e4f9fb8
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 490 deletions.
25 changes: 23 additions & 2 deletions cluster/ampagent/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"strings"
"text/template"
"time"

"docker.io/go-docker"
Expand All @@ -29,6 +30,11 @@ const (
TARGET_CLUSTER = "cluster"
)

type StackVariables struct {
DeploymentMode string
EnableTLS bool
}

type InstallOptions struct {
NoLogs bool
NoMetrics bool
Expand Down Expand Up @@ -144,7 +150,6 @@ func getStackFiles(path string, deploymentMode string) ([]string, error) {
if path == "" {
path = "./stacks"
}
path += "/" + deploymentMode

// a bit more work but we can't just use filepath.Glob
// since we need to match both *.yml and *.yaml
Expand All @@ -153,9 +158,25 @@ func getStackFiles(path string, deploymentMode string) ([]string, error) {
return nil, err
}
stackfiles := []string{}
stackVars := StackVariables{DeploymentMode: deploymentMode, EnableTLS: os.Getenv("AMP_TLS_VERIFY") != ""}
for _, f := range files {
name := f.Name()
if matched, _ := regexp.MatchString("\\.ya?ml$", name); matched {
// first, look for yml.tpl files and transform them to yml files
if matched, _ := regexp.MatchString("\\.ya?ml.tpl$", name); matched {
log.Println("converting template", name, "to yml file")
t := template.Must(template.New(name).Funcs(template.FuncMap{"StringsJoin": strings.Join}).ParseFiles(filepath.Join(path, name)))
if err != nil {
return nil, err
}
ymlFilepath := strings.TrimSuffix(filepath.Join(path, name), ".tpl")
ymlFile, err := os.Create(ymlFilepath)
err = t.Execute(ymlFile, stackVars)
if err != nil {
return nil, err
}
ymlFile.Close()
stackfiles = append(stackfiles, ymlFilepath)
} else if matched, _ := regexp.MatchString("\\.ya?ml$", name); matched {
stackfiles = append(stackfiles, filepath.Join(path, name))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
- etcd-data:/data
environment:
SERVICE_NAME: "etcd"
MIN_SEEDS_COUNT: 3
MIN_SEEDS_COUNT: {{ if eq .DeploymentMode "cluster" }}3{{ else }}1{{ end }}
command:
- "--advertise-client-urls"
- "http://etcd:2379"
Expand All @@ -38,6 +38,7 @@ services:
amp.service.stabilize.timeout: "40s"
deploy:
mode: replicated
{{- if eq .DeploymentMode "cluster" }}
replicas: 3
update_config:
parallelism: 1
Expand All @@ -46,6 +47,9 @@ services:
condition: any
delay: 25s
window: 15s
{{- else }}
replicas: 1
{{- end }}
labels:
io.amp.role: "infrastructure"
io.amp.metrics.port: "2379"
Expand All @@ -61,10 +65,19 @@ services:
environment:
REGISTRATION: ${REGISTRATION:-email}
NOTIFICATIONS: ${NOTIFICATIONS:-true}
{{- if .EnableTLS }}
DOCKER_HOST: "${AMP_HOST:-unix:///var/run/docker.sock}"
DOCKER_TLS_VERIFY: "${AMP_TLS_VERIFY}"
DOCKER_CERT_PATH: "/root/.docker"
{{- end }}
ports:
- "50101:50101"
volumes:
{{- if .EnableTLS }}
- ${AMP_CERT_PATH:-/root/.docker}:/root/.docker:ro
{{- else }}
- "/var/run/docker.sock:/var/run/docker.sock"
{{- end }}
labels:
io.amp.role: "infrastructure"
amp.service.stabilize.delay: "4s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ services:
amp.service.stabilize.timeout: "180s"
amp.service.pull.timeout: "120s"
environment:
{{- if eq .DeploymentMode "cluster" }}
MIN_MASTER_NODES: 2
NETWORK_HOST: "_site_"
UNICAST_HOSTS: "tasks.elasticsearch"
{{- end }}
NETWORK_HOST: "_site_"
JAVA_HEAP_SIZE: "${ES_JAVA_HEAP_SIZE:-1024}"
deploy:
mode: replicated
{{- if eq .DeploymentMode "cluster" }}
replicas: 3
update_config:
parallelism: 1
Expand All @@ -41,6 +44,9 @@ services:
condition: any
delay: 5s
window: 25s
{{- else }}
replicas: 1
{{- end }}
labels:
io.amp.role: "infrastructure"
io.amp.metrics.port: "9200"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ services:
- core
volumes:
- prometheus-data:/prometheus
{{- if .EnableTLS }}
- ${AMP_CERT_PATH:-/root/.docker}:/root/.docker:ro
{{- else }}
- /var/run/docker.sock:/var/run/docker.sock:ro
{{- end }}
environment:
SERVICE_PORTS: 9090
VIRTUAL_HOST: "http://alerts.*,https://alerts.*"
PROMETHEUS_EXTERNAL_URL: "${PROMETHEUS_EXTERNAL_URL:-https://alerts.local.appcelerator.io}"
{{- if .EnableTLS }}
DOCKER_HOST: ${AMP_HOST}
DOCKER_TLS_VERIFY: ${AMP_TLS_VERIFY}
DOCKER_CERT_PATH: "/root/.docker"
{{- end }}
ports:
- "9090:9090"
labels:
Expand Down
File renamed without changes.
224 changes: 0 additions & 224 deletions cluster/ampagent/stacks/cluster/03-metrics.yml

This file was deleted.

Loading

0 comments on commit e4f9fb8

Please sign in to comment.