Skip to content

Commit b49c5c9

Browse files
metalwhalesontdhust
authored andcommitted
Move migrations to "chloria-backend" workspace. Add "chloria-api" package.
1 parent 00f416f commit b49c5c9

File tree

17 files changed

+132
-14
lines changed

17 files changed

+132
-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

.github/workflows/migration.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: migration
2+
on:
3+
push:
4+
branches:
5+
- distribution
6+
paths:
7+
- chloria-backend/migrations/**
8+
- chloria-backend/Dockerfile.dist-migration
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-migration
23+
push: true
24+
tags: metalwhaledev/chloria-migration: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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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
16+
17+
COPY --from=build /usr/src/chloria-backend/target/release/chloria-api /bin/chloria-api

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Build
2+
FROM rust:1.84.0-bookworm AS build
3+
4+
RUN cargo install diesel_cli@2.2.7 --no-default-features --features postgres
5+
6+
# Distribution
7+
FROM debian:bookworm-20250203-slim
8+
9+
RUN apt update -y && \
10+
apt install -y libpq5
11+
12+
COPY --from=build /usr/local/cargo/bin/diesel /bin/diesel
13+
COPY ./migrations /usr/src/migrations
14+
15+
# Ref: https://github.com/diesel-rs/diesel/blob/v2.2.7/diesel_cli/src/migrations/mod.rs#L287
16+
ENV MIGRATION_DIRECTORY /usr/src/migrations
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+
}

0 commit comments

Comments
 (0)