Skip to content

Commit

Permalink
Merge pull request #218 from jackstockley89/helm
Browse files Browse the repository at this point in the history
feat(helm): Update templates
  • Loading branch information
jackstockley89 authored Nov 22, 2022
2 parents 3e4e8f9 + 46e6e52 commit 444f274
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 279 deletions.
34 changes: 21 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
FROM golang:1.17.8-alpine3.15
FROM golang:1.19.3-alpine3.16

RUN apk add git
RUN apk add postgresql-client
ENV \
CGO_ENABLED=0 \
GOOS=linux

RUN go get -u github.com/lib/pq
RUN go get -u github.com/joho/godotenv
RUN apk add postgresql-client

RUN addgroup -g 1000 -S appgroup && \
adduser -u 1000 -S appuser -G appgroup

WORKDIR /app

COPY . .
COPY go.mod /app
COPY go.sum /app
COPY main.go /app
COPY sql /app
COPY static /app
COPY templates /app
COPY .env_db /app
COPY .env_app /app

RUN chown -R appuser:appgroup /app
RUN chown -R appuser:appgroup /go/bin
USER 1000

RUN go mod download

RUN echo ${PGPASSFILE} > /home/appuser/.pgpass && \
chown appuser:appgroup /home/appuser/.pgpass && \
chmod 0600 /home/appuser/.pgpass

RUN chown -R appuser:appgroup /app
RUN chown -R appuser:appgroup /go

USER 1000

# Build the Go app
RUN go build -o main .
RUN go build -ldflags "-s -w" -o /go/bin/cycling_blog -buildvcs=false

# Expose port 8080 to the outside world
EXPOSE 8080

# Command to run the executable
CMD ["./main"]
CMD ["cycling_blog"]
26 changes: 6 additions & 20 deletions helm/cycling-blog/templates/cycling-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
labels:
app: {{ .Values.app_deployment.app }}
spec:
replicas: 1
replicas: {{ .Values.app_deployment.replicas }}
selector:
matchLabels:
app: {{ .Values.app_deployment.app }}
Expand All @@ -29,24 +29,10 @@ spec:
ports:
- containerPort: {{ .Values.app_service.ports.port }}
env:
- name: PGPASSFILE
{{- range .Values.db_env }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: pgpass
key: connect
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: pgpass
key: username
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: pgpass
key: password
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: pgpass
key: db_name

name: {{ .secretName }}
key: {{ .key }}
{{- end }}
63 changes: 63 additions & 0 deletions helm/cycling-blog/templates/cycling-db-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.cycling_blog_db_create.name }}
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.cycling_blog_db_create.app }}
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": post-install
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": {{ .Values.annotations.hookDeletePolicy }}
spec:
template:
spec:
containers:
- name: {{ .Values.cycling_blog_db_create.app }}
image: {{ .Values.app_deployment.template.containers.image }}
imagePullPolicy: {{ .Values.cycling_blog_db_create.template.containers.imagePullPolicy }}
command: ["psql"]
args: ["-h", "$(CYCLING_BLOG_DB_SERVICE_SERVICE_HOST)", "-U", "$(POSTGRES_USER)", "-d", "$(POSTGRES_DB)", "-w", "-a", "-f", "sql/create_table.sql"]
env:
{{- range .Values.db_env }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: {{ .secretName }}
key: {{ .key }}
{{- end }}
restartPolicy: {{ .Values.cycling_blog_db_create.template.restartPolicy }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.cycling_blog_db_insert.name }}
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.cycling_blog_db_insert.app }}
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": post-install
"helm.sh/hook-weight": "10"
"helm.sh/hook-delete-policy": {{ .Values.annotations.hookDeletePolicy }}
spec:
template:
spec:
containers:
- name: {{ .Values.cycling_blog_db_insert.app }}
image: {{ .Values.app_deployment.template.containers.image }}
imagePullPolicy: {{ .Values.cycling_blog_db_insert.template.containers.imagePullPolicy }}
command: ["psql"]
args: ["-h", "$(CYCLING_BLOG_DB_SERVICE_SERVICE_HOST)", "-U", "$(POSTGRES_USER)", "-d", "$(POSTGRES_DB)", "-w", "-a", "-f", "sql/table_insert.sql"]
env:
{{- range .Values.db_env }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: {{ .secretName }}
key: {{ .key }}
{{- end }}
restartPolicy: {{ .Values.cycling_blog_db_insert.template.restartPolicy }}
26 changes: 6 additions & 20 deletions helm/cycling-blog/templates/cycling-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,10 @@ spec:
ports:
- containerPort: {{ .Values.db_service.ports.port }}
env:
- name: POSTGRES_USER
valueFrom:
{{- range .Values.db_env }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: pgpass
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: pgpass
key: password
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: pgpass
key: db_name
- name: HOSTNAME
valueFrom:
secretKeyRef:
name: pgpass
key: hostname

name: {{ .secretName }}
key: {{ .key }}
{{- end }}
44 changes: 0 additions & 44 deletions helm/cycling-blog/templates/db-create-job.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions helm/cycling-blog/templates/db-insert-job.yaml

This file was deleted.

Binary file modified helm/cycling-blog/values-dev.yaml
Binary file not shown.
Binary file modified helm/cycling-blog/values-local.yaml
Binary file not shown.
Binary file modified helm/cycling-blog/values-stg.yaml
Binary file not shown.
Binary file modified helm/cycling-blog/values-test.yaml
Binary file not shown.
Loading

0 comments on commit 444f274

Please sign in to comment.