Skip to content

Commit b20528a

Browse files
committed
add container image for db-migrations
1 parent 831dd93 commit b20528a

File tree

9 files changed

+61
-31
lines changed

9 files changed

+61
-31
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM migrate/migrate:v4.17.1
2+
3+
COPY ./migrations/* /app/migrations/

06-demo-application/postgresql/Taskfile.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: "3"
22

3+
vars:
4+
# IMAGE_REPO: localhost:5000/devops-directive-kubernetes-course-db-migrator
5+
IMAGE_REPO: sidpalas/devops-directive-kubernetes-course-db-migrator
6+
IMAGE_TAG: foobarbaz
7+
38
tasks:
49
run-postgres:
510
desc: Start postgres container
@@ -12,5 +17,20 @@ tasks:
1217
cmds:
1318
- |
1419
CONTAINER_ID=$(docker ps -q --filter "ancestor=postgres:16.3-alpine")
15-
docker cp ./init.sql $CONTAINER_ID:/tmp/
20+
docker cp ./migrations/init.sql $CONTAINER_ID:/tmp/
1621
docker exec $CONTAINER_ID psql -U "postgres" -f /tmp/init.sql
22+
23+
build-container-image:
24+
desc: Build container image
25+
cmds:
26+
- docker build -t {{.IMAGE_REPO}}{{.IMAGE_TAG}} .
27+
28+
build-container-image-multi-arch:
29+
desc: Build multi-arch container image
30+
cmds:
31+
- |
32+
docker buildx build \
33+
--platform linux/amd64,linux/arm64 \
34+
-t {{.IMAGE_REPO}}:{{.IMAGE_TAG}} \
35+
--push \
36+
.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Delete the table
2+
DROP TABLE public.request;

06-demo-application/postgresql/init.sql renamed to 06-demo-application/postgresql/migrations/000001_create_users_table.up.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,3 @@ CREATE TABLE IF NOT EXISTS public.request (
33
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
44
api_name VARCHAR(10) NOT NULL CHECK (api_name IN ('node', 'go'))
55
);
6-
7-
-- -- Optionally, insert initial data
8-
-- INSERT INTO view (api_name) VALUES ('node');
9-
-- INSERT INTO view (api_name) VALUES ('go');
10-
-- INSERT INTO view (api_name) VALUES ('go');

07-deploying-demo-application/postgresql/Configmap.db-migrations.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
apiVersion: batch/v1
22
kind: Job
33
metadata:
4-
name: migrate-job
4+
name: db-migrator
55
namespace: demo-app
66
spec:
77
template:
88
spec:
99
containers:
1010
- name: migrate
11-
image: migrate/migrate:v4.17.1
11+
image: sidpalas/devops-directive-kubernetes-course-db-migrator:foobarbaz
1212
args:
13-
- -path=/migrations
13+
- -path=/app/migrations
1414
- -database=$(DATABASE_URL)?sslmode=disable
1515
- up
1616
envFrom:
1717
- secretRef:
1818
name: db-password
19-
volumeMounts:
20-
- name: migrations
21-
mountPath: /migrations
2219
restartPolicy: OnFailure
23-
volumes:
24-
- name: migrations
25-
configMap:
26-
name: db-migrations

07-deploying-demo-application/postgresql/Taskfile.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ tasks:
1616
apply-initial-db-migration-job:
1717
desc: "Run init.sql script against the DB"
1818
cmds:
19-
- "kubectl apply -f Configmap.db-migrations.yaml"
2019
- "kubectl apply -f Secret.db-password.yaml"
2120
- "kubectl apply -f Job.db-migrator.yaml"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: db-migrator
5+
namespace: demo-app
6+
annotations:
7+
kluctl.io/hook: pre-deploy
8+
spec:
9+
template:
10+
spec:
11+
containers:
12+
- name: migrate
13+
image: sidpalas/devops-directive-kubernetes-course-db-migrator:{{ apiGolang.version }}
14+
args:
15+
- -path=/app/migrations
16+
- -database=$(DATABASE_URL)?sslmode=disable
17+
- up
18+
envFrom:
19+
- secretRef:
20+
name: db-password
21+
restartPolicy: OnFailure
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ⛔️ DONT PUT SECRET FILES IN VCS
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: db-password
6+
namespace: demo-app
7+
annotations:
8+
kluctl.io/hook: pre-deploy
9+
type: Opaque
10+
stringData:
11+
DATABASE_URL: postgres://postgres:[email protected]:5432/postgres

0 commit comments

Comments
 (0)