diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..cab8412e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.22 as base + +WORKDIR /app + +COPY . . + +RUN go mod download + +RUN go build -o main . + +FROM gcr.io/distroless/base + +COPY --from=base /app/main . + +COPY --from=base /app/static ./static + +EXPOSE 8080 + +CMD [ "./main" ] \ No newline at end of file diff --git a/README.md b/README.md index 21c7f3eb3..f0d3e6ad2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ This is a simple website written in Golang. It uses the `net/http` package to serve HTTP requests. +## Installing Go on your machine + +Download and install Go for your respective OS from `https://go.dev/doc/install` + ## Running the server To run the server, execute the following command: diff --git a/k8s/manifests/deployment.yaml b/k8s/manifests/deployment.yaml new file mode 100644 index 000000000..aa66e1aae --- /dev/null +++ b/k8s/manifests/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + replicas: 1 + selector: + matchLabels: + app: go-web-app + template: + metadata: + labels: + app: go-web-app + spec: + containers: + - name: go-web-app + image: joethomas97/go-web-app:v1 + ports: + - containerPort: 8080 diff --git a/k8s/manifests/ingress.yaml b/k8s/manifests/ingress.yaml new file mode 100644 index 000000000..39122ef40 --- /dev/null +++ b/k8s/manifests/ingress.yaml @@ -0,0 +1,20 @@ +# Ingress resource for the application +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: go-web-app + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx + rules: + - host: go-web-app.local + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: go-web-app + port: + number: 80 diff --git a/k8s/manifests/service.yaml b/k8s/manifests/service.yaml new file mode 100644 index 000000000..2b934c27b --- /dev/null +++ b/k8s/manifests/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + selector: + app: go-web-app + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: ClusterIP \ No newline at end of file