Skip to content

Commit 2a46848

Browse files
feat(auth): auto migrations run
1 parent cd2614b commit 2a46848

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

deploy/helm/auth/templates/deployment.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ spec:
1414
spec:
1515
imagePullSecrets:
1616
- name: j11er-docker-registry
17+
initContainers:
18+
- name: migrations
19+
image: {{ .Values.app.image.tag }}
20+
imagePullPolicy: IfNotPresent
21+
envFrom:
22+
- configMapRef:
23+
name: auth-backend-env-config
24+
command: ["/bin/sh"]
25+
args: ["/opt/service/auth/run-migrations.sh"]
26+
volumeMounts:
27+
- name: bash-script-clickhouse
28+
mountPath: /opt/service/auth/
29+
subPath: run-migrations.sh
1730
containers:
1831
- name: auth-backend
1932
image: {{ .Values.app.image.tag }}
@@ -32,3 +45,7 @@ spec:
3245
requests:
3346
cpu: 100m
3447
memory: 256Mi
48+
volumes:
49+
- name: bash-script-migrations
50+
configMap:
51+
name: bash-script-migrations
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
kind: ConfigMap
2+
apiVersion: v1
3+
metadata:
4+
name: bash-script-migrations
5+
data:
6+
run-migrations.sh: |-
7+
#!/bin/sh
8+
9+
printenv
10+
echo $(ls)
11+
apk --no-cache add curl
12+
curl -fsSL https://raw.githubusercontent.com/pressly/goose/master/install.sh | GOOSE_INSTALL=$HOME/.goose sh -s v3.20.0
13+
14+
set GOOSE_DBSTRING=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable
15+
goose -dir migrations/postgres postgres up

service/auth/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
# builder stage
12
FROM golang:1.22.4-alpine as builder
23

3-
ENV CGO_ENABLED=0 \
4-
GOOS=linux \
5-
GOARCH=amd64
4+
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
65

76
WORKDIR /opt
87

@@ -15,9 +14,12 @@ RUN go mod download
1514
RUN go build -o app/main service/auth/cmd/app/main.go
1615

1716

17+
# runtime stage
1818
FROM scratch as runtime
1919

2020
WORKDIR /opt/service/auth
2121

2222
COPY --from=builder /opt/app/main /main
23+
COPY --from=builder /opt/service/auth/migrations /migrations
24+
2325
ENTRYPOINT ["/main"]

0 commit comments

Comments
 (0)