-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 김유진 <eugene70kim@gmail.com>
- Loading branch information
Showing
10 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Dockerfile | ||
FROM golang:1.16 as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /my-web-service | ||
|
||
FROM scratch | ||
|
||
COPY --from=builder /my-web-service /my-web-service | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["/my-web-service"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v2 | ||
name: my-web-service | ||
description: A Helm chart for my web service | ||
type: application | ||
version: 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "helper.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name for the chart. | ||
*/}} | ||
{{- define "helper.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create labels common for all resources. | ||
*/}} | ||
{{- define "helper.labels" -}} | ||
helm.sh/chart: {{ include "helper.chart" . }} | ||
{{ include "helper.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
{{- if .Values.nameOverride }} | ||
app.kubernetes.io/name: {{ .Values.nameOverride | quote }} | ||
{{- else }} | ||
app.kubernetes.io/name: {{ include "helper.name" . | quote }} | ||
{{- end }} | ||
app.kubernetes.io/instance: {{ .Release.Name | quote }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service | quote }} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create labels specific for selector. | ||
*/}} | ||
{{- define "helper.selectorLabels" -}} | ||
app.kubernetes.io/instance: {{ .Release.Name | quote }} | ||
app.kubernetes.io/name: {{ include "helper.name" . | quote }} | ||
{{- end -}} | ||
|
||
{{/* | ||
Expand the chart name. | ||
*/}} | ||
{{- define "helper.chart" -}} | ||
{{ .Chart.Name }}-{{ .Chart.Version }} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "helper.fullname" . }} | ||
labels: | ||
{{- include "helper.labels" . | nindent 4 }} | ||
spec: | ||
replicas: {{ .Values.replicaCount }} | ||
selector: | ||
matchLabels: | ||
{{- include "helper.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
labels: | ||
{{- include "helper.selectorLabels" . | nindent 8 }} | ||
spec: | ||
containers: | ||
- name: {{ .Chart.Name }} | ||
image: "{{ .Values.image.name }}" | ||
ports: | ||
- containerPort: {{ .Values.service.port }} | ||
readinessProbe: | ||
httpGet: | ||
path: /healthcheck | ||
port: {{ .Values.service.port }} | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
livenessProbe: | ||
httpGet: | ||
path: /healthcheck | ||
port: {{ .Values.service.port }} | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ include "helper.fullname" . }} | ||
labels: | ||
{{- include "helper.labels" . | nindent 4 }} | ||
spec: | ||
type: {{ .Values.service.type }} | ||
ports: | ||
- nodePort: {{ .Values.service.nodePort }} | ||
port: {{ .Values.service.port }} | ||
targetPort: {{ .Values.service.targetPort }} | ||
selector: | ||
{{- include "helper.selectorLabels" . | nindent 4 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
replicaCount: 1 | ||
|
||
image: | ||
name: eugene70/my-web-service | ||
tag: 1.0.0 | ||
pullPolicy: IfNotPresent | ||
|
||
service: | ||
type: NodePort | ||
nodePort: 30080 | ||
port: 8080 | ||
targetPort: 8080 | ||
|
||
ingress: | ||
enabled: false | ||
|
||
resources: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module my-web-service | ||
|
||
go 1.16 | ||
|
||
require ( | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/api/v1/", func(w http.ResponseWriter, r *http.Request) { | ||
githubUsername := r.URL.Path[len("/api/v1/"):] | ||
fmt.Fprintf(w, "Hello, %s!", githubUsername) | ||
}) | ||
|
||
http.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "OK") | ||
}) | ||
|
||
port := "8080" | ||
if fromEnv := os.Getenv("PORT"); fromEnv != "" { | ||
port = fromEnv | ||
} | ||
|
||
fmt.Printf("Starting server on port %s\n", port) | ||
if err := http.ListenAndServe(":"+port, nil); err != nil { | ||
fmt.Printf("Error starting server: %s\n", err) | ||
} | ||
} |