Skip to content

Commit

Permalink
ci: typecheck with a live postgres instance
Browse files Browse the repository at this point in the history
  • Loading branch information
vohoanglong0107 committed May 20, 2024
1 parent 79221e5 commit b03d47b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
DATABASE_URL: postgres://bors:bors@localhost/bors
services:
postgres:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_USER: bors
POSTGRES_PASSWORD: bors
POSTGRES_DB: bors
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -24,6 +40,12 @@ jobs:
override: true
components: clippy, rustfmt

- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features native-tls,postgres

- name: Run sqlx migrate
run: sqlx migrate run

- uses: Swatinem/rust-cache@v1

- name: Check
Expand Down Expand Up @@ -52,6 +74,20 @@ jobs:
docker:
name: Test Docker
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_USER: bors
POSTGRES_PASSWORD: bors
POSTGRES_DB: bors
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM rust:1.76 as base

ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

RUN cargo install cargo-chef
RUN cargo install cargo-chef && \
cargo install sqlx-cli --no-default-features --features native-tls,postgres

FROM base as planner

Expand All @@ -12,15 +13,19 @@ RUN cargo chef prepare --recipe-path recipe.json

FROM base as build

# require a running postgres instance on the host
ENV DATABASE_URL=postgres://bors:bors@host.docker.internal/bors

WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json

RUN cargo chef cook --release --recipe-path recipe.json
RUN cargo sqlx migrate run

COPY Cargo.toml .
COPY Cargo.lock .
COPY src src
COPY database database
COPY migrations migrations

RUN cargo build --release

Expand Down

0 comments on commit b03d47b

Please sign in to comment.