Skip to content

Commit e9b24bf

Browse files
committed
refactor(coprocessor): fix db-migration misconfigs
1 parent 8213faa commit e9b24bf

24 files changed

+75
-52
lines changed

.github/workflows/coprocessor-docker-build-db-migration.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- published
1111

1212
concurrency:
13-
group: fhevm-db-migration-${{ github.ref_name }}
13+
group: db-migration-${{ github.ref_name }}
1414
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
1515

1616
jobs:
@@ -30,8 +30,8 @@ jobs:
3030
filters: |
3131
db-migration-files:
3232
- .github/workflows/coprocessor-docker-build-db-migration.yml
33-
- coprocessor/fhevm-engine/fhevm-db/**
34-
docker-fhevm-db-migration:
33+
- coprocessor/fhevm-engine/db-migration/**
34+
docker-db-migration:
3535
needs: check-changes
3636
if: ${{ needs.check-changes.outputs.changes-db-migration-files == 'true' || github.event_name == 'release' }}
3737
uses: zama-ai/ci-templates/.github/workflows/docker_common.yml@44333c96991d6747e0bef6a3308bfd98b20390f8 # main
@@ -48,5 +48,5 @@ jobs:
4848
push_image: true
4949
image-name: "fhevm/coprocessor/db-migration"
5050
generate-dev-image: false
51-
docker-file: "fhevm-engine/fhevm-db/Dockerfile"
51+
docker-file: "fhevm-engine/db-migration/Dockerfile"
5252
arm-build: true

coprocessor/fhevm-engine/coprocessor/docker-compose.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ services:
2222
container_name: db-migration
2323
build:
2424
context: ../../.
25-
dockerfile: fhevm-engine/fhevm-db/Dockerfile
25+
dockerfile: fhevm-engine/db-migration/Dockerfile
2626
environment:
2727
DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor
2828
TENANT_API_KEY: "a1503fb6-d79b-4e9e-826d-44cf262f3e05"
2929
ACL_CONTRACT_ADDRESS: "0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2"
3030
INPUT_VERIFIER_ADDRESS: "0x69dE3158643e738a0724418b21a35FAA20CBb1c5"
31+
command:
32+
- /initialize_db.sh
33+
healthcheck:
34+
test: ["CMD-SHELL", "psql --version"]
35+
interval: 15s
36+
timeout: 5s
37+
retries: 1
38+
start_period: 5s
3139
volumes:
3240
- ../fhevm-keys:/fhevm-keys
3341
depends_on:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Stage 1: Build DB Migration
2+
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.85.0 AS builder
3+
4+
USER root
5+
6+
# Install sqlx-cli
7+
RUN cargo install sqlx-cli --version 0.7.2 \
8+
--no-default-features --features postgres --locked
9+
10+
# Copy migrations and initialization script
11+
COPY fhevm-engine/ /fhevm-engine
12+
COPY proto/ /proto/
13+
COPY fhevm-engine/db-migration/initialize_db.sh /initialize_db.sh
14+
COPY fhevm-engine/db-migration/migrations /migrations
15+
16+
WORKDIR /fhevm-engine
17+
# Build utils binary
18+
# Currently, this utils is used only for keys converting.
19+
# Later on, it will be extended to replace initialize_db.sh completely
20+
RUN mkdir /fhevm-keys && \
21+
cargo fetch && \
22+
SQLX_OFFLINE=true cargo build --release -p coprocessor --bin utils
23+
24+
# Stage 2: Runtime image
25+
FROM cgr.dev/chainguard/glibc-dynamic:latest AS runtime
26+
27+
COPY --from=builder /lib/ /lib/
28+
COPY --from=builder /bin/ /bin/
29+
COPY --from=builder /usr/lib/ /usr/lib/
30+
COPY --from=builder /usr/bin/ /usr/bin/
31+
COPY --from=builder /usr/libexec/ /usr/libexec/
32+
COPY --from=builder /etc/group /etc/group
33+
COPY --from=builder /etc/passwd /etc/passwd
34+
COPY --from=builder --chown=fhevm:fhevm /home/fhevm /home/fhevm
35+
COPY --from=builder --chown=fhevm:fhevm /app /app
36+
37+
COPY --from=builder --chown=fhevm:fhevm /fhevm-engine/target/release/utils /usr/local/bin/utils
38+
COPY --from=builder --chown=fhevm:fhevm /usr/local/cargo/bin/sqlx /usr/local/bin/sqlx
39+
COPY --from=builder --chown=fhevm:fhevm /initialize_db.sh /initialize_db.sh
40+
COPY --from=builder --chown=fhevm:fhevm /migrations /migrations
41+
COPY --from=builder --chown=fhevm:fhevm /fhevm-keys /fhevm-keys
42+
43+
USER fhevm:fhevm
44+
45+
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}"
46+
47+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
48+
CMD psql --version || exit 1
49+
50+
ENTRYPOINT ["/bin/bash", "-c"]
File renamed without changes.

coprocessor/fhevm-engine/fhevm-db/migrations/20240722111257_coprocessor.sql renamed to coprocessor/fhevm-engine/db-migration/migrations/20240722111257_coprocessor.sql

File renamed without changes.

coprocessor/fhevm-engine/fhevm-db/migrations/20250205000000_drop_output_type_in_computations.sql renamed to coprocessor/fhevm-engine/db-migration/migrations/20250205000000_drop_output_type_in_computations.sql

File renamed without changes.

coprocessor/fhevm-engine/fhevm-db/migrations/20250205130209_create_pbs_computations_table.sql renamed to coprocessor/fhevm-engine/db-migration/migrations/20250205130209_create_pbs_computations_table.sql

File renamed without changes.

coprocessor/fhevm-engine/fhevm-db/migrations/20250207092623_verify_proofs.sql renamed to coprocessor/fhevm-engine/db-migration/migrations/20250207092623_verify_proofs.sql

File renamed without changes.

coprocessor/fhevm-engine/fhevm-db/migrations/20250212082040_create_sns_keys_columns.sql renamed to coprocessor/fhevm-engine/db-migration/migrations/20250212082040_create_sns_keys_columns.sql

File renamed without changes.

coprocessor/fhevm-engine/fhevm-db/migrations/20250217133315_add_table_blocks_valid.sql renamed to coprocessor/fhevm-engine/db-migration/migrations/20250217133315_add_table_blocks_valid.sql

File renamed without changes.

0 commit comments

Comments
 (0)