├── version.txt ├── README.md ├── go.mod ├── Dockerfile ├── k8s ├── prod │ ├── kustomization.yaml │ ├── kustomization.yaml.tmpl │ ├── deployment.yaml │ └── deployment.yaml.tmpl ├── stage │ ├── kustomization.yaml │ ├── kustomization.yaml.tmpl │ ├── deployment.yaml │ └── deployment.yaml.tmpl └── dev │ ├── kustomization.yaml │ ├── kustomization.yaml.tmpl │ ├── deployment.yaml │ └── deployment.yaml.tmpl ├── deploy ├── stage.yaml ├── prod.yaml ├── pipeline.yaml └── pipeline.yaml.tmpl ├── skaffold.yaml ├── skaffold.yaml.tmpl └── main.go /version.txt: -------------------------------------------------------------------------------- 1 | v1 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # app-template 2 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module example.com/golang 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | FROM golang:1 16 | WORKDIR /app 17 | COPY * ./ 18 | RUN go build -o golang-template 19 | CMD ["/app/golang-template"] 20 | -------------------------------------------------------------------------------- /k8s/prod/kustomization.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bases: 16 | - ../../../kustomize-base/golang 17 | patches: 18 | - deployment.yaml 19 | namePrefix: "demo-app-" 20 | commonLabels: 21 | app: demo-app 22 | role: backend 23 | -------------------------------------------------------------------------------- /k8s/stage/kustomization.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bases: 16 | - ../../../kustomize-base/golang 17 | patches: 18 | - deployment.yaml 19 | commonLabels: 20 | app: demo-app 21 | role: backend 22 | namePrefix: demo-app- 23 | -------------------------------------------------------------------------------- /k8s/prod/kustomization.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bases: 16 | - ../../../kustomize-base/golang 17 | patches: 18 | - deployment.yaml 19 | namePrefix: "${APP_NAME}-" 20 | commonLabels: 21 | app: ${APP_NAME} 22 | role: backend 23 | -------------------------------------------------------------------------------- /k8s/stage/kustomization.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bases: 16 | - ../../../kustomize-base/golang 17 | patches: 18 | - deployment.yaml 19 | commonLabels: 20 | app: ${APP_NAME} 21 | role: backend 22 | namePrefix: ${APP_NAME}- 23 | -------------------------------------------------------------------------------- /k8s/dev/kustomization.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bases: 16 | - ../../../kustomize-base/golang 17 | patches: 18 | - deployment.yaml 19 | namePrefix: "demo-app-" # App name (dash) 20 | commonLabels: 21 | app: demo-app # App name for selectors 22 | role: backend 23 | -------------------------------------------------------------------------------- /deploy/stage.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: deploy.cloud.google.com/v1beta1 16 | kind: Target 17 | metadata: 18 | name: stage 19 | annotations: {} 20 | labels: {} 21 | description: stage 22 | gke: 23 | cluster: projects/PROJECT_ID/locations/us-west2-a/clusters/stage -------------------------------------------------------------------------------- /k8s/dev/kustomization.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bases: 16 | - ../../../kustomize-base/golang 17 | patches: 18 | - deployment.yaml 19 | namePrefix: "${APP_NAME}-" # App name (dash) 20 | commonLabels: 21 | app: ${APP_NAME} # App name for selectors 22 | role: backend 23 | -------------------------------------------------------------------------------- /deploy/prod.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: deploy.cloud.google.com/v1beta1 16 | kind: Target 17 | metadata: 18 | name: prod 19 | annotations: {} 20 | labels: {} 21 | description: prod 22 | requireApproval: false 23 | gke: 24 | cluster: projects/PROJECT_ID/locations/us-central1-a/clusters/prod 25 | -------------------------------------------------------------------------------- /deploy/pipeline.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: deploy.cloud.google.com/v1beta1 16 | kind: DeliveryPipeline 17 | metadata: 18 | name: demo-app 19 | labels: 20 | app: demo-app 21 | description: delivery pipeline 22 | serialPipeline: 23 | stages: 24 | - targetId: stage 25 | profiles: 26 | - stage 27 | - targetId: prod 28 | profiles: 29 | - prod -------------------------------------------------------------------------------- /deploy/pipeline.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: deploy.cloud.google.com/v1beta1 16 | kind: DeliveryPipeline 17 | metadata: 18 | name: ${APP_NAME} 19 | labels: 20 | app: ${APP_NAME} 21 | description: delivery pipeline 22 | serialPipeline: 23 | stages: 24 | - targetId: stage 25 | profiles: 26 | - stage 27 | - targetId: prod 28 | profiles: 29 | - prod -------------------------------------------------------------------------------- /k8s/prod/deployment.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | kind: Deployment 16 | apiVersion: apps/v1 17 | metadata: 18 | name: app 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - name: app 24 | image: demo-app 25 | resources: 26 | requests: 27 | cpu: 25m 28 | memory: 64Mi 29 | limits: 30 | cpu: 100m 31 | memory: 256Mi 32 | env: 33 | - name: ENVIRONMENT 34 | value: prod 35 | -------------------------------------------------------------------------------- /k8s/prod/deployment.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | kind: Deployment 16 | apiVersion: apps/v1 17 | metadata: 18 | name: app 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - name: app 24 | image: ${APP_NAME} 25 | resources: 26 | requests: 27 | cpu: 25m 28 | memory: 64Mi 29 | limits: 30 | cpu: 100m 31 | memory: 256Mi 32 | env: 33 | - name: ENVIRONMENT 34 | value: prod 35 | -------------------------------------------------------------------------------- /k8s/stage/deployment.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | kind: Deployment 16 | apiVersion: apps/v1 17 | metadata: 18 | name: app 19 | spec: 20 | replicas: 1 21 | template: 22 | spec: 23 | containers: 24 | - name: app 25 | image: demo-app 26 | resources: 27 | requests: 28 | cpu: 25m 29 | memory: 64Mi 30 | limits: 31 | cpu: 100m 32 | memory: 256Mi 33 | env: 34 | - name: ENVIRONMENT 35 | value: stg 36 | -------------------------------------------------------------------------------- /k8s/stage/deployment.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | kind: Deployment 16 | apiVersion: apps/v1 17 | metadata: 18 | name: app 19 | spec: 20 | replicas: 1 21 | template: 22 | spec: 23 | containers: 24 | - name: app 25 | image: ${APP_NAME} 26 | resources: 27 | requests: 28 | cpu: 25m 29 | memory: 64Mi 30 | limits: 31 | cpu: 100m 32 | memory: 256Mi 33 | env: 34 | - name: ENVIRONMENT 35 | value: stg 36 | -------------------------------------------------------------------------------- /skaffold.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: skaffold/v1beta14 16 | kind: Config 17 | build: 18 | artifacts: 19 | - image: demo-app # Match name in deployment yaml 20 | context: ./ 21 | deploy: 22 | kustomize: 23 | path: k8s/dev 24 | 25 | profiles: 26 | - name: dev 27 | activation: 28 | - command: dev 29 | deploy: 30 | kustomize: 31 | path: k8s/dev 32 | 33 | - name: stage 34 | deploy: 35 | kustomize: 36 | path: k8s/stage 37 | 38 | - name: prod 39 | deploy: 40 | kustomize: 41 | path: k8s/prod 42 | -------------------------------------------------------------------------------- /skaffold.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: skaffold/v1beta14 16 | kind: Config 17 | build: 18 | artifacts: 19 | - image: ${APP_NAME} # Match name in deployment yaml 20 | context: ./ 21 | deploy: 22 | kustomize: 23 | path: k8s/dev 24 | 25 | profiles: 26 | - name: dev 27 | activation: 28 | - command: dev 29 | deploy: 30 | kustomize: 31 | path: k8s/dev 32 | 33 | - name: stage 34 | deploy: 35 | kustomize: 36 | path: k8s/stage 37 | 38 | - name: prod 39 | deploy: 40 | kustomize: 41 | path: k8s/prod 42 | -------------------------------------------------------------------------------- /k8s/dev/deployment.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | kind: Deployment 16 | apiVersion: apps/v1 17 | metadata: 18 | name: app 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - name: app # Must match base value 24 | image: demo-app # Overwrites values from base - Needs to match skaffold artifact 25 | resources: 26 | requests: 27 | cpu: 25m 28 | memory: 64Mi 29 | limits: 30 | cpu: 100m 31 | memory: 256Mi 32 | env: 33 | - name: ENVIRONMENT 34 | value: dev 35 | -------------------------------------------------------------------------------- /k8s/dev/deployment.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | kind: Deployment 16 | apiVersion: apps/v1 17 | metadata: 18 | name: app 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - name: app # Must match base value 24 | image: ${APP_NAME} # Overwrites values from base - Needs to match skaffold artifact 25 | resources: 26 | requests: 27 | cpu: 25m 28 | memory: 64Mi 29 | limits: 30 | cpu: 100m 31 | memory: 256Mi 32 | env: 33 | - name: ENVIRONMENT 34 | value: dev 35 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "log" 20 | "net/http" 21 | "os" 22 | ) 23 | 24 | func main() { 25 | env := os.Getenv("ENVIRONMENT") 26 | port := 8080 27 | log.Printf("Running in environment: %s\n", env) 28 | 29 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 30 | log.Printf("Received request from %s at %s", r.RemoteAddr, r.URL.EscapedPath()) 31 | fmt.Fprint(w, "Hello World!") 32 | }) 33 | http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { 34 | log.Printf("Received health check from %s", r.RemoteAddr) 35 | w.WriteHeader(http.StatusOK) 36 | }) 37 | log.Printf("Starting server on port: %v", port) 38 | log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", port), nil)) 39 | 40 | } 41 | --------------------------------------------------------------------------------