Skip to content

Commit

Permalink
feat: 김유진 과제제출 (#52)
Browse files Browse the repository at this point in the history
Signed-off-by: 김유진 <eugene70kim@gmail.com>
  • Loading branch information
eugene70 authored Jul 27, 2024
1 parent fb908d6 commit 6b2fe63
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 0 deletions.
1 change: 1 addition & 0 deletions eugene70/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
20 changes: 20 additions & 0 deletions eugene70/Dockerfile
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"]

5 changes: 5 additions & 0 deletions eugene70/charts/Chart.yaml
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
57 changes: 57 additions & 0 deletions eugene70/charts/templates/_helpers.tpl
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 -}}
33 changes: 33 additions & 0 deletions eugene70/charts/templates/deployment.yaml
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
14 changes: 14 additions & 0 deletions eugene70/charts/templates/service.yaml
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 }}
17 changes: 17 additions & 0 deletions eugene70/charts/values.yaml
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: {}
6 changes: 6 additions & 0 deletions eugene70/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module my-web-service

go 1.16

require (
)
1 change: 1 addition & 0 deletions eugene70/go.sum
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=
28 changes: 28 additions & 0 deletions eugene70/main.go
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)
}
}

0 comments on commit 6b2fe63

Please sign in to comment.