Skip to content

Commit

Permalink
tooling: run migrations in container
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaKeks committed Jan 17, 2024
1 parent c4687a2 commit ce936c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ features = [

[dependencies.utoipa-swagger-ui]
version = "6.0.0"
features = [
"axum",
]
features = ["axum"]

[dependencies.itertools]
workspace = true
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM lukemathwalker/cargo-chef:latest-rust-1.75-slim-bullseye AS chef
WORKDIR /kz

FROM chef AS planner
RUN cargo install --locked --no-default-features --features mysql sqlx-cli
COPY Cargo.toml .
COPY crates crates
COPY src src
Expand Down Expand Up @@ -33,6 +34,9 @@ RUN apt-get update \
&& ln -s /usr/games/steamcmd /bin/steamcmd \
&& steamcmd +quit

COPY docker-entrypoint.sh /docker-entrypoint.sh
COPY --from=planner /usr/local/cargo/bin/sqlx /bin/sqlx
COPY --from=builder /kz/target/release/cs2kz-api /bin/cs2kz-api
COPY ./database/migrations ./migrations

ENTRYPOINT ["/bin/cs2kz-api"]
ENTRYPOINT ["/docker-entrypoint.sh"]
31 changes: 6 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export

DATABASE_PORT ?= "8070"

default:
@make db
@echo "Waiting for the database to spin up..."
@sleep 10s
@make migrations
@make api
api:
@echo "Building API container..."
@docker compose build cs2kz-api
@echo "Running API..."
@docker compose up -d --wait cs2kz-api
@docker compose logs --follow cs2kz-api

db:
@echo "Starting database container..."
Expand Down Expand Up @@ -37,25 +37,6 @@ db-connect-root:
-P $(DATABASE_PORT) \
-D cs2kz

migrations:
@echo "Running migrations..."
@$(if $(shell command -v sqlx 2>/dev/null), make migrations-sqlx, make migrations-shell) \

migrations-sqlx:
@sqlx migrate run \
--source ./database/migrations/ \
--database-url $(DATABASE_URL)

migrations-shell:
./scripts/run-migrations.sh

api:
@echo "Building API container..."
@docker compose build cs2kz-api
@echo "Running API..."
@docker compose up -d --wait cs2kz-api
@docker compose logs --follow cs2kz-api

api-spec:
@echo "Generating OpenAPI docs..."
cargo run --package spec-generator -- --output api-spec.json
Expand Down
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

sqlx migrate run
cs2kz-api

0 comments on commit ce936c6

Please sign in to comment.