Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding the configmap template to the helm deployment template #382

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
9 changes: 2 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
vendor/
.idea/
/pkg/deployments/deployTypes/
/pkg/workflows/workflow/
.DS_Store
draft
langtest
Dockerfile
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
charts/
37 changes: 14 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
FROM golang:1.22-alpine

WORKDIR /draft

RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
RUN apk add py3-pip

RUN python3 -m venv az-cli-env
RUN az-cli-env/bin/pip install --upgrade pip
RUN az-cli-env/bin/pip install --upgrade setuptools
RUN az-cli-env/bin/pip install --upgrade azure-cli
RUN az-cli-env/bin/pip install --upgrade setuptools
RUN az-cli-env/bin/az --version

ENV PATH "$PATH:/draft/az-cli-env/bin"

RUN apk add github-cli

COPY . ./
RUN make go-generate

RUN go mod download
ENTRYPOINT ["go"]
FROM golang:1.18 AS builder
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
ENV PORT 80
EXPOSE 80

WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -v -o app-binary

FROM gcr.io/distroless/static-debian12
WORKDIR /app
COPY --from=builder /build/app-binary .
CMD ["/app/app-binary"]
4 changes: 2 additions & 2 deletions pkg/config/draftconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (d *DraftConfig) GetVariableExampleValues() map[string][]string {
}

// Returns a map of variable names to values used in Gotemplate
func (d *DraftConfig) GetVariableMap() map[string]string {
variableMap := make(map[string]string)
func (d *DraftConfig) GetVariableMap() map[string]interface{} {
variableMap := make(map[string]interface{})
for _, variable := range d.Variables {
variableMap[variable.Name] = variable.Value
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/osutil/osutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func CopyDirWithTemplates(
return nil
}

func replaceGoTemplateVariables(fileSys fs.FS, srcPath string, variableMap map[string]string) ([]byte, error) {
func replaceGoTemplateVariables(fileSys fs.FS, srcPath string, variableMap map[string]interface{}) ([]byte, error) {
file, err := fs.ReadFile(fileSys, srcPath)
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions pkg/osutil/osutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
name string
fileSys fs.FS
srcPath string
variableMap map[string]string
variableMap map[string]interface{}
expected string
expectedError bool
}{
Expand All @@ -227,7 +227,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}}!")},
},
srcPath: "template.txt",
variableMap: map[string]string{"Name": "Joe"},
variableMap: map[string]interface{}{"Name": "Joe"},
expected: "Hello, Joe!",
expectedError: false,
},
Expand All @@ -237,7 +237,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}}!")},
},
srcPath: "template.txt",
variableMap: map[string]string{},
variableMap: map[string]interface{}{},
expected: "",
expectedError: true,
},
Expand All @@ -247,7 +247,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}}!")},
},
srcPath: "nonexistent.txt",
variableMap: map[string]string{"Name": "Joe"},
variableMap: map[string]interface{}{"Name": "Joe"},
expected: "",
expectedError: true,
},
Expand All @@ -257,7 +257,7 @@ func TestReplaceGoTemplateVariables(t *testing.T) {
"template.txt": &fstest.MapFile{Data: []byte("Hello, {{.Name}} and {{.Place}}!")},
},
srcPath: "template.txt",
variableMap: map[string]string{"Name": "Joe"},
variableMap: map[string]interface{}{"Name": "Joe"},
expected: "",
expectedError: true,
},
Expand Down
6 changes: 6 additions & 0 deletions template/deployments/helm/charts/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
envVariables: {{ print "{{ .Values.envVariables }}" }}
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions template/deployments/helm/charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ spec:
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
envFrom:
- configMapRef:
name: envvars-configmap
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
5 changes: 4 additions & 1 deletion template/deployments/helm/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ tolerations: []

affinity: {}

generatorLabel: {{.GENERATORLABEL}}
generatorLabel: {{.GENERATORLABEL}}

# environment variables will be read from the configmap.yaml
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
envVariables:
7 changes: 7 additions & 0 deletions template/deployments/kustomize/base/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
{{ .ENVVARIABLES }}

5 changes: 4 additions & 1 deletion template/deployments/kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ spec:
image: {{.IMAGENAME}}:{{.IMAGETAG}}
imagePullPolicy: Always
ports:
- containerPort: {{.PORT}}
- containerPort: {{.PORT}}
envFrom:
- configMapRef:
name: envvars-configmap
3 changes: 2 additions & 1 deletion template/deployments/kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
- service.yaml
- configmap.yaml
6 changes: 6 additions & 0 deletions template/deployments/kustomize/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ variables:
disablePrompt: true
value: "draft"
description: "the label to identify who generated the resource"
- name: "ENVVARIABLES"
type: "map"
kind: "environmentVariables"
description: "environment variables for the application"
default:
value: key1=value1
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
{{ .ENVVARIABLES }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ spec:
spec:
containers:
- name: {{.APPNAME}}
image: {{.IMAGENAME}}:{{.IMAGETAG}}
image: {{.IMAGENAME}}:{{.IMAGETAG}}
envFrom:
- configMapRef:
name: envvars-configmap
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ resources:
- ../../base
patchesStrategicMerge:
- deployment.yaml
- service.yaml
- service.yaml
- configmap.yaml
6 changes: 6 additions & 0 deletions template/deployments/manifests/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ variables:
disablePrompt: true
value: "draft"
description: "the label to identify who generated the resource"
- name: "ENVVARIABLES"
type: "map"
kind: "environmentVariables"
description: "environment variables for the application"
default:
value: key1=value1
6 changes: 6 additions & 0 deletions template/deployments/manifests/manifests/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: envvars-configmap
data:
Vidya2606 marked this conversation as resolved.
Show resolved Hide resolved
{{ .ENVVARIABLES }}
5 changes: 4 additions & 1 deletion template/deployments/manifests/manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ spec:
image: {{.IMAGENAME}}:{{.IMAGETAG}}
imagePullPolicy: Always
ports:
- containerPort: {{.PORT}}
- containerPort: {{.PORT}}
envFrom:
- configMapRef:
name: envvars-configmap
Loading