Skip to content

Commit a0f6106

Browse files
committed
Move migrations to "chloria-backend" workspace. Add "chloria-api" package.
1 parent 21d3bb5 commit a0f6106

File tree

15 files changed

+97
-14
lines changed

15 files changed

+97
-14
lines changed

.github/workflows/api.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: api
2+
on:
3+
push:
4+
branches:
5+
- distribution
6+
paths:
7+
- chloria-backend/chloria-api/**
8+
- chloria-backend/Dockerfile.dist-api
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Login to Docker Hub
14+
uses: docker/login-action@v3
15+
with:
16+
username: metalwhaledev
17+
password: ${{ secrets.DOCKERHUB_TOKEN }}
18+
- name: Build and push
19+
uses: docker/build-push-action@v6
20+
with:
21+
context: "{{defaultContext}}:chloria-backend"
22+
file: Dockerfile.dist-api
23+
push: true
24+
tags: metalwhaledev/chloria-api:0.1.0

chloria-backend/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chloria-backend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
22

3-
members = ["chloria-job"]
3+
members = ["chloria-api", "chloria-job"]
44
resolver = "2"

chloria-backend/Dockerfile.dist-api

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Build
2+
FROM rust:1.84.0-bookworm AS build
3+
4+
COPY . /usr/src/chloria-backend/
5+
6+
WORKDIR /usr/src/chloria-backend/
7+
8+
RUN cargo install diesel_cli@2.2.7 --no-default-features --features postgres
9+
RUN cargo build --release --package chloria-api
10+
11+
# Distribution
12+
FROM debian:bookworm-20250203-slim
13+
14+
RUN apt update -y && \
15+
apt install -y libpq5 ca-certificates
16+
17+
COPY --from=build /usr/local/cargo/bin/diesel /bin/diesel
18+
COPY --from=build /usr/src/chloria-backend/target/release/chloria-api /bin/chloria-api
19+
COPY ./migrations /usr/src/migrations
20+
21+
# Ref: https://github.com/diesel-rs/diesel/blob/v2.2.7/diesel_cli/src/migrations/mod.rs#L287
22+
ENV MIGRATION_DIRECTORY /usr/src/migrations

chloria-backend/Dockerfile.dist-job

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@ FROM debian:bookworm-20250203-slim
1414
RUN apt update -y && \
1515
apt install -y libpq5 ca-certificates
1616

17-
COPY --from=build /usr/local/cargo/bin/diesel /bin/diesel
1817
COPY --from=build /usr/src/chloria-backend/target/release/chloria-job /bin/chloria-job
19-
COPY ./chloria-job/migrations /usr/src/chloria-job/migrations
20-
21-
WORKDIR /usr/src/chloria-job/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "chloria-api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
diesel = { version = "2.2.7", features = ["postgres"] }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod schema;
2+
3+
fn main() {
4+
println!("Hello, world!");
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @generated automatically by Diesel CLI.
2+
3+
diesel::table! {
4+
news (id) {
5+
id -> Int4,
6+
source_name -> Text,
7+
article_id -> Text,
8+
link -> Nullable<Text>,
9+
title -> Nullable<Text>,
10+
short_text -> Nullable<Text>,
11+
long_text -> Nullable<Text>,
12+
image_path -> Nullable<Text>,
13+
published_time -> Nullable<Timestamptz>,
14+
created_at -> Timestamptz,
15+
updated_at -> Timestamptz,
16+
}
17+
}

chloria-backend/chloria-job/diesel.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

chloria-backend/diesel.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# For documentation on how to configure this file,
2+
# see https://diesel.rs/guides/configuring-diesel-cli
3+
4+
[print_schema.job]
5+
file = "chloria-job/src/schema.rs"
6+
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
7+
filter = { only_tables = ["news"] }
8+
9+
[print_schema.api]
10+
file = "chloria-api/src/schema.rs"
11+
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
12+
13+
[migrations_directory]
14+
dir = "/usr/src/chloria/chloria-backend/migrations"

0 commit comments

Comments
 (0)