+55
docker/postgres/migration.Dockerfile
+55
docker/postgres/migration.Dockerfile
···
1
+
FROM rust:1 AS chef
2
+
# We only pay the installation cost once,
3
+
# it will be cached from the second build onwards
4
+
RUN cargo install cargo-chef
5
+
WORKDIR /workspace
6
+
7
+
8
+
FROM chef AS planner
9
+
COPY crates .
10
+
RUN cargo chef prepare --recipe-path recipe.json
11
+
12
+
FROM chef AS builder
13
+
ARG CRATE_NAME
14
+
COPY --from=planner /workspace/recipe.json recipe.json
15
+
# Build dependencies - this is the caching Docker layer!
16
+
RUN cargo chef cook --release --recipe-path recipe.json
17
+
# Build application
18
+
COPY crates .
19
+
RUN cargo build --release --bin ${CRATE_NAME}
20
+
21
+
# We do not need the Rust toolchain to run the binary!
22
+
FROM debian:trixie-slim AS runtime
23
+
ARG CRATE_NAME
24
+
COPY ./connectors/fluvio_profile.toml /home/${CRATE_NAME}/.fluvio/config
25
+
COPY --from=builder /workspace/target/release/${CRATE_NAME} /usr/local/bin/app
26
+
ENTRYPOINT ["/usr/local/bin/app"]
27
+
28
+
29
+
FROM rust:1 AS chef
30
+
# We only pay the installation cost once,
31
+
# it will be cached from the second build onwards
32
+
RUN cargo install cargo-chef
33
+
WORKDIR /workspace
34
+
35
+
FROM chef AS planner
36
+
COPY crates .
37
+
RUN cargo chef prepare --recipe-path recipe.json
38
+
39
+
FROM chef AS builder
40
+
ARG CRATE_NAME
41
+
COPY --from=planner /workspace/recipe.json recipe.json
42
+
# Build dependencies - this is the caching Docker layer!
43
+
RUN cargo chef cook --release --recipe-path recipe.json
44
+
# Build application
45
+
COPY crates .
46
+
RUN cargo build --release --bin ${CRATE_NAME}
47
+
48
+
FROM debian:trixie-slim AS runtime
49
+
ARG CRATE_NAME
50
+
# Gah, time in my docker vm is wrong
51
+
RUN apt-get update -o Acquire::Max-FutureTime=31536000 --allow-insecure-repositories --allow-releaseinfo-change-suite &&\
52
+
apt-get install -y postgresql-client && \
53
+
apt-get clean && \
54
+
rm -rf /var/lib/apt/lists/*
55
+
COPY --from=builder /workspace/target/release/${CRATE_NAME} app
+48
helm/ott/templates/pg_migration.yaml
+48
helm/ott/templates/pg_migration.yaml
···
1
+
apiVersion: batch/v1
2
+
kind: Job
3
+
metadata:
4
+
name: migration-pg
5
+
annotations:
6
+
"helm.sh/hook": post-install,post-upgrade
7
+
"helm.sh/hook-weight": "5"
8
+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
9
+
spec:
10
+
backoffLimit: 3
11
+
template:
12
+
spec:
13
+
restartPolicy: Never
14
+
containers:
15
+
- name: db-init
16
+
image: "{{ .Values.postgresql.migration_image_fqn }}"
17
+
imagePullPolicy: IfNotPresent
18
+
env:
19
+
- name: DATABASE_USER
20
+
valueFrom:
21
+
secretKeyRef:
22
+
name: postgres-superuser
23
+
key: username
24
+
- name: DATABASE_PASSWORD
25
+
valueFrom:
26
+
secretKeyRef:
27
+
name: postgres-superuser
28
+
key: password
29
+
- name: DATABASE_URL
30
+
value: "postgres://$(DATABASE_USER):$(DATABASE_PASSWORD)@postgres-rw.default.svc.cluster.local:5432"
31
+
command:
32
+
- /bin/sh
33
+
- -c
34
+
- |
35
+
echo "Waiting for database to be ready..."
36
+
for i in {1..30}; do
37
+
if pg_isready -h $DATABASE_URL; then
38
+
echo "Database is ready!"
39
+
break
40
+
fi
41
+
echo "Attempt $i/30: Database not ready yet, waiting..."
42
+
sleep 10
43
+
done
44
+
45
+
echo "Setting up migration"
46
+
./app
47
+
48
+
echo "Database initialization completed!"
+2
helm/ott/values.yaml
+2
helm/ott/values.yaml
+18
-2
skaffold.yaml
+18
-2
skaffold.yaml
···
4
4
name: ott
5
5
build:
6
6
artifacts:
7
+
#
8
+
# Database images
9
+
#
7
10
- image: loaded-pg
8
11
context: docker/postgres
9
12
docker:
10
13
dockerfile: Dockerfile
14
+
- image: migration-pg
15
+
context: .
16
+
docker:
17
+
dockerfile: docker/postgres/migration.Dockerfile
18
+
buildArgs:
19
+
CRATE_NAME: "ott-db-migration"
20
+
21
+
#
22
+
# CONNECTORS
23
+
#
11
24
- image: posts-connector
12
25
context: connectors
13
26
docker:
···
22
35
CONFIG_FILE: "likes-config.yaml"
23
36
24
37
38
+
#
39
+
# The actual main services
40
+
#
25
41
- image: ott-embed
26
42
context: .
27
43
docker:
28
44
dockerfile: docker/rust-service/Dockerfile
29
45
buildArgs:
30
46
CRATE_NAME: "ott-embed"
31
-
32
47
- image: ott-filter
33
48
context: .
34
49
docker:
35
50
dockerfile: docker/rust-service/Dockerfile
36
51
buildArgs:
37
52
CRATE_NAME: "ott-filter"
38
-
39
53
- image: ott-xrpc
40
54
context: .
41
55
docker:
42
56
dockerfile: docker/rust-service/Dockerfile
43
57
buildArgs:
44
58
CRATE_NAME: "ott-xrpc"
59
+
45
60
46
61
tagPolicy:
47
62
envTemplate:
···
70
85
valuesFiles:
71
86
- helm/ott/values.yaml
72
87
setValueTemplates:
88
+
postgresql.migration_image_fqn: "{{.IMAGE_FULLY_QUALIFIED_migration_pg}}"
73
89
deployments[0].image.fqn: "{{.IMAGE_FULLY_QUALIFIED_likes_connector}}"
74
90
deployments[1].image.fqn: "{{.IMAGE_FULLY_QUALIFIED_posts_connector}}"
75
91
deployments[2].image.fqn: "{{.IMAGE_FULLY_QUALIFIED_ott_filter}}"