feat(migration) add migration

This commit is contained in:
lumither committed 2025-10-13 14:36:21 -04:00
1 parent 02e7166fcb
commit 3a4af1ae8d
9 files changed
+84 -22

No files matched your search

+17 -3
View File
@@ -3,7 +3,21 @@ ifeq ($(ARCH), arm64)
ARCH := aarch64 ARCH := aarch64
endif endif
.PHONY: up .PHONY: all
clean: all:up
echo "todo"
.PHONY: build
build:
ARCH=$(ARCH) docker compose -f prod.compose.yaml build
.PHONY: up
up:
ARCH=$(ARCH) docker compose -f prod.compose.yaml up -d
.PHONY: down
down:
ARCH=$(ARCH) docker compose -f prod.compose.yaml down
.PHONY: rm
rm:
ARCH=$(ARCH) docker compose -f prod.compose.yaml rm
+14 -13
View File
@@ -1,16 +1,17 @@
use chrono::Utc; // use chrono::Utc;
use git2::Repository; // use git2::Repository;
fn main() { fn main() {
let repo = Repository::open("../..").expect("failed to open repository"); // let repo = Repository::open("../..").expect("failed to open repository");
let commit = repo // let commit = repo
.head() // .head()
.expect("failed to get HEAD") // .expect("failed to get HEAD")
.peel_to_commit() // .peel_to_commit()
.expect("failed to get HEAD commit"); // .expect("failed to get HEAD commit");
let hash = commit.id().to_string(); // let hash = commit.id().to_string();
let utc_timestamp = Utc::now().date_naive().format("%Y%m%d").to_string(); // let utc_timestamp = Utc::now().date_naive().format("%Y%m%d").to_string();
let pkg_version = env!("CARGO_PKG_VERSION"); // let pkg_version = env!("CARGO_PKG_VERSION");
let build_id = format!("{}:{}@{}", pkg_version, &hash[..8], utc_timestamp); // let build_id = format!("{}:{}@{}", pkg_version, &hash[..8], utc_timestamp);
println!("cargo:rustc-env=BUILD_ID={}", build_id); // println!("cargo:rustc-env=BUILD_ID={}", build_id);
println!("cargo:rustc-env=BUILD_ID=undefined");
} }
+2 -2
View File
@@ -5,6 +5,6 @@ RUN ["cargo", "build", "-r"]
FROM gcr.io/distroless/cc AS production FROM gcr.io/distroless/cc AS production
ARG ARCH ARG ARCH
COPY --from=builder /app/target/release/api_server ./api_server COPY --from=builder /app/target/release/server ./server
COPY --from=builder /usr/lib/${ARCH}-linux-gnu/libz.so.1 /usr/lib/${ARCH}-linux-gnu/ COPY --from=builder /usr/lib/${ARCH}-linux-gnu/libz.so.1 /usr/lib/${ARCH}-linux-gnu/
ENTRYPOINT ["./api_server"] ENTRYPOINT ["./server"]
+8
View File
@@ -0,0 +1,8 @@
.PHONY:all
all: standalone
.PHONY: standalone
standalone:
npm run build
cp -r public .next/standalone/ && cp -r .next/static .next/standalone/.next/
+1 -1
View File
@@ -8,7 +8,7 @@ const nextConfig = {
}, },
{ {
protocol: 'https', protocol: 'https',
hostname: 'pic.re' hostname: 'cdn.jsdelivr.net'
} }
] ]
}, },
+1 -1
View File
@@ -1,4 +1,4 @@
export const SITE_CONFIG = { export const SITE_CONFIG = {
name: 'Atelier Lumiaethor', name: 'Atelier Lumiaethor',
desc: '' desc: 'In pursuit of absolute simplicity and ultimate sophistication'
}; };
File renamed without changes.
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
set -e
PGPASSFILE="/root/.pgpass"
echo "postgres:5432:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > "$PGPASSFILE"
chmod 600 "$PGPASSFILE"
echo "waiting for postgres"
until pg_isready -h postgres -U "$POSTGRES_USER" -d "$POSTGRES_DB"; do
echo "retrying, sleep 2s"
sleep 2
done
echo "db ready, running migrations"
for file in /migrations/*.sql; do
echo "applying $file"
psql -h postgres -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f "$file"
done
echo "migration complete"
+23 -2
View File
@@ -14,7 +14,7 @@ services:
backend: backend:
depends_on: depends_on:
- postgres - migrate
build: build:
context: ./backend context: ./backend
dockerfile: ../container/release/backend.containerfile dockerfile: ../container/release/backend.containerfile
@@ -29,10 +29,31 @@ services:
dns: dns:
- 1.1.1.1 - 1.1.1.1
migrate:
image: postgres:17
depends_on:
postgres:
condition: service_healthy
env_file:
- ./.env
- ./.env.local
volumes:
- ./migration/ddl:/migrations:ro
- ./migration/migration.sh:/migration.sh:ro
entrypoint: [ "/bin/sh", "/migration.sh" ]
postgres: postgres:
image: postgres:16.3 image: postgres:17
ports: ports:
- "5432:5432" - "5432:5432"
env_file: env_file:
- ./.env - ./.env
- ./.env.local - ./.env.local
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB" ]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s