Skip to content

Commit 6629601

Browse files
authored
Merge pull request #1107 from kenkoooo/feature/docker-compose
まともに使える docker-compose
2 parents 9057154 + 4e003c4 commit 6629601

File tree

16 files changed

+219
-204
lines changed

16 files changed

+219
-204
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,89 @@ env:
99
CARGO_TERM_COLOR: always
1010
RUST_BACKTRACE: 1
1111
RUST_TEST_THREADS: 1
12+
SQL_URL: postgres://db_user:db_pass@localhost:5432/test_db
1213

1314
jobs:
1415
backend_test:
1516
name: Run backend tests
1617
runs-on: ubuntu-latest
17-
18+
defaults:
19+
run:
20+
working-directory: ./atcoder-problems-backend
21+
1822
services:
19-
postgres:
23+
postgres:
2024
image: postgres
2125
env:
22-
POSTGRES_PASSWORD: pass
23-
POSTGRES_USER: kenkoooo
24-
POSTGRES_DB: test
25-
# Set health checks to wait until postgres has started
26+
POSTGRES_USER: db_user
27+
POSTGRES_PASSWORD: db_pass
28+
POSTGRES_DB: test_db
29+
POSTGRES_INITDB_ARGS: "--encoding=UTF8"
2630
options: >-
2731
--health-cmd pg_isready
2832
--health-interval 10s
2933
--health-timeout 5s
3034
--health-retries 5
3135
ports:
32-
# Maps tcp port 5432 on service container to the host
3336
- 5432:5432
34-
37+
3538
steps:
3639
- uses: actions/checkout@v2
40+
41+
- name: Cache cargo registry
42+
uses: actions/cache@v2
43+
with:
44+
path: |
45+
~/.cargo/git
46+
~/.cargo/registry/cache
47+
~/.cargo/registry/index
48+
./atcoder-problems-backend/target
49+
key: ${{ runner.os }}-cargo-${{ hashFiles('atcoder-problems-backend/Cargo.lock') }}
50+
51+
- name: Setup Postgresql
52+
run: psql ${SQL_URL} < ../config/database-definition.sql
53+
3754
- name: Setup
3855
run: rustup component add rustfmt
56+
3957
- name: Check format
40-
working-directory: ./atcoder-problems-backend
4158
run: cargo fmt --all -- --check
59+
4260
- name: Build
43-
working-directory: ./atcoder-problems-backend
4461
run: cargo build --verbose
62+
4563
- name: Run tests
46-
working-directory: ./atcoder-problems-backend
47-
env:
48-
SQL_URL: postgresql://kenkoooo:pass@localhost:5432/test
4964
run: cargo test --verbose --workspace -- --test-threads=1
5065

5166
frontend_test:
5267
name: Run frontend tests
5368
runs-on: ubuntu-latest
69+
defaults:
70+
run:
71+
working-directory: ./atcoder-problems-frontend
72+
5473
steps:
55-
- name: Setup
56-
run: sudo apt install libgconf-2-4
5774
- uses: actions/checkout@v2
5875
- name: Use Node.js
5976
uses: actions/setup-node@v1
77+
78+
- name: Cache node_modules
79+
uses: actions/cache@v2
80+
with:
81+
path: |
82+
~/.cache/Cypress
83+
./atcoder-problems-frontend/node_modules
84+
key: ${{ runner.os }}-cargo-${{ hashFiles('atcoder-problems-frontend/yarn.lock') }}
85+
6086
- name: Install dependencies
61-
working-directory: ./atcoder-problems-frontend
6287
run: yarn
6388
- name: build
64-
working-directory: ./atcoder-problems-frontend
6589
run: yarn build
6690
- name: test
67-
working-directory: ./atcoder-problems-frontend
6891
run: yarn test
6992
- name: lint
70-
working-directory: ./atcoder-problems-frontend
7193
run: yarn lint
7294
- name: Integration test
73-
working-directory: ./atcoder-problems-frontend
7495
run: |
7596
yarn prepare-ci
7697
yarn start:ci &

atcoder-problems-backend/.rustfmt.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

atcoder-problems-backend/Cargo.lock

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

atcoder-problems-backend/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ reqwest = { version = "0.11", features = ["json"] }
2929

3030
async-trait = "0.1"
3131

32-
anyhow = "1.0.32"
32+
anyhow = "1.0"
3333

3434
[dev-dependencies]
3535

3636
[workspace]
37-
members = ["sql-client", "atcoder-client"]
37+
members = ["sql-client", "atcoder-client"]

atcoder-problems-backend/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
FROM rust:1.57.0 AS development
2+
RUN rustup component add rustfmt
3+
RUN rustup component add clippy
4+
15
FROM rust:1.57.0 AS builder
26

37
WORKDIR /app
@@ -25,7 +29,7 @@ ADD ./atcoder-client ./atcoder-client
2529
RUN cargo clean --release -p atcoder-client -p sql-client
2630
RUN cargo build --release
2731

28-
FROM rust:1.57.0
32+
FROM rust:1.57.0 AS production
2933
COPY --from=builder /app/target/release/batch_update /usr/bin/batch_update
3034
COPY --from=builder /app/target/release/crawl_all_submissions /usr/bin/crawl_all_submissions
3135
COPY --from=builder /app/target/release/crawl_for_virtual_contests /usr/bin/crawl_for_virtual_contests
@@ -37,3 +41,7 @@ COPY --from=builder /app/target/release/delta_update /usr/bin/del
3741
COPY --from=builder /app/target/release/dump_json /usr/bin/dump_json
3842
COPY --from=builder /app/target/release/fix_invalid_submissions /usr/bin/fix_invalid_submissions
3943
COPY --from=builder /app/target/release/run_server /usr/bin/run_server
44+
45+
46+
RUN apt-get update && apt-get install -y awscli postgresql-client
47+
ADD ./scripts/sql-backup.sh /usr/bin/sql-backup.sh

atcoder-problems-backend/README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Below are the list of files you need to modify:
3838
## Build
3939

4040
```bash
41-
cd atcoder-problems-backend/
42-
cargo build
41+
docker-compose up -d
42+
docker-compose exec backend-development cargo build
4343
```
4444

4545
## Run
@@ -70,13 +70,8 @@ cargo run --bin fix_invalid_submissions
7070
## Test
7171

7272
```bash
73-
# If you don't set up PostgreSQL in your local environment,
74-
# you need to run the following lines to run a PostgreSQL Docker container for testing.
75-
docker-compose up -d postgresql
76-
export SQL_URL=postgres://kenkoooo:pass@localhost:5432/test
77-
78-
# Run all the tests
79-
cargo test --workspace -- --test-threads=1
73+
docker-compose up -d
74+
docker-compose exec backend-development cargo test --workspace -- --test-threads=1
8075
```
8176

8277
## Format
@@ -86,6 +81,6 @@ Please make sure that your change is formatted before sending a pull request.
8681
You can format the code base with `cargo fmt` like the following:
8782

8883
```bash
89-
cd atcoder-problems-backend/
90-
cargo fmt
84+
docker-compose up -d
85+
docker-compose exec backend-development cargo fmt
9186
```

atcoder-problems-backend/docker-compose.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
psql ${SQL_URL} -c "\copy submissions TO './submissions.csv' WITH (FORMAT CSV, HEADER)"
4+
gzip submissions.csv
5+
aws s3 cp submissions.csv.gz s3://kenkoooo/submissions.csv.gz --acl public-read

atcoder-problems-backend/sql-client/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ publish = false
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
sqlx = { version = "0.5.9", features = ["postgres", "runtime-tokio-rustls"] }
11+
sqlx = { version = "0.5.10", features = ["postgres", "runtime-tokio-rustls"] }
1212
async-trait = "0.1.52"
1313
serde = { version = "1.0", features = ["derive"] }
1414
uuid = { version = "0.8", features = ["serde", "v4"] }
15-
anyhow = "1.0.51"
15+
anyhow = "1.0"
1616
tokio = { version = "1.15", features = ["macros"] }
1717
regex = "1"
1818
chrono = "0.4"

atcoder-problems-backend/src/server/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub(crate) mod virtual_contest;
1313

1414
use actix_web::{http::header, web, App, HttpResponseBuilder, HttpServer};
1515
pub use auth::{Authentication, GitHubAuthentication, GitHubUserResponse};
16+
pub use services::config_services;
1617

1718
const LOG_TEMPLATE: &str = r#"{"method":"%{method}xi", "url":"%U", "status":%s, "duration":%T}"#;
1819

@@ -50,7 +51,7 @@ impl MakeCors for HttpResponseBuilder {
5051
}
5152
}
5253

53-
pub(crate) struct AppData<A> {
54+
pub struct AppData<A> {
5455
pub(crate) authentication: A,
5556
pub(crate) pg_pool: sql_client::PgPool,
5657
}
@@ -65,7 +66,7 @@ impl<A: Clone> Clone for AppData<A> {
6566
}
6667

6768
impl<A> AppData<A> {
68-
fn new(pg_pool: sql_client::PgPool, authentication: A) -> Self {
69+
pub fn new(pg_pool: sql_client::PgPool, authentication: A) -> Self {
6970
Self {
7071
authentication,
7172
pg_pool,

0 commit comments

Comments
 (0)