Skip to content

Commit 5d98bb1

Browse files
committed
created a useful dev container
1 parent 1623861 commit 5d98bb1

File tree

14 files changed

+783
-164
lines changed

14 files changed

+783
-164
lines changed

.env

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

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dev:
2+
docker compose --file docker/docker-compose.dev.yml up --build --remove-orphans
3+
4+
prod:
5+
docker compose --file docker/docker-compose.yml up --build --remove-orphans --detach
6+
7+
down:
8+
docker compose down
9+
10+
File renamed without changes.

Dockerfile renamed to docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.90.0 AS base
1+
FROM rust:1.91.0 AS base
22

33
FROM base AS server-builder
44
WORKDIR /server

docker/dev.Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM rust:1.91.0
2+
WORKDIR /server
3+
COPY server/Cargo.lock server/Cargo.toml ./
4+
COPY lib /lib
5+
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release && rm -rf src
6+
COPY server/src ./src
7+
COPY server/migrations ./migrations
8+
RUN touch src/main.rs
9+
EXPOSE 3000
10+
CMD ["bash", "-c", "cargo run"]
11+

docker/docker-compose.dev.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: open-erase
2+
services:
3+
backend:
4+
container_name: backend
5+
image: backend
6+
env_file: .env
7+
build:
8+
context: ../.
9+
dockerfile: docker/dev.Dockerfile
10+
ports:
11+
- "3000:3000"
12+
restart: always
13+
depends_on:
14+
- open-erase-db
15+
16+
17+
web:
18+
container_name: web
19+
image: web
20+
build:
21+
context: ../.
22+
dockerfile: docker/web-dev.Dockerfile
23+
ports:
24+
- "8080:8080"
25+
volumes:
26+
- ../web:/web
27+
restart: always
28+
depends_on:
29+
- backend
30+
31+
open-erase-db:
32+
container_name: open-erase-db
33+
image: postgres:18
34+
restart: always
35+
env_file: .env
36+
environment:
37+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
38+
POSTGRES_DB: ${POSTGRES_DB}
39+
ports:
40+
- "5432:5432"
41+
volumes:
42+
- db:/var/lib/postgresql
43+
healthcheck:
44+
test: ["CMD-SHELL", "pg_isready -U postgres"]
45+
interval: 5s
46+
timeout: 5s
47+
retries: 5
48+
49+
volumes:
50+
db:
51+
driver: local
File renamed without changes.
File renamed without changes.

docker/web-dev.Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM rust:1.91.0
2+
RUN rustup target add wasm32-unknown-unknown
3+
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
4+
RUN cargo binstall trunk wasm-bindgen-cli
5+
WORKDIR /web
6+
COPY lib /lib
7+
COPY web ./
8+
EXPOSE 8080
9+
CMD ["bash", "-c", "trunk serve"]

server/src/routes/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ const LOGOUT_PATH: &str = "/logout";
3737
const REFRESH_PATH: &str = "/refresh";
3838
const USERS_PATH: &str = "/users";
3939

40-
const STATIC_ASSETS_PATH: &str = "/dist";
41-
const INDEX_HTML_PATH: &str = "/dist/index.html";
40+
const STATIC_ASSETS_PATH: &str = "/web/dist";
41+
const INDEX_HTML_PATH: &str = "/web/dist/index.html";
4242

4343
pub fn app(state: AppState) -> Router {
44-
Router::new()
44+
let router = Router::new()
4545
.merge(api_router(state.clone()))
46-
.fallback_service(web_service())
4746
.method_not_allowed_fallback(method_not_allowed_fallback)
4847
.layer(
4948
ServiceBuilder::new()
@@ -68,7 +67,13 @@ pub fn app(state: AppState) -> Router {
6867
.layer(TimeoutLayer::new(Duration::from_secs(5)))
6968
.layer(middleware::from_fn(log)),
7069
)
71-
.with_state(state)
70+
.with_state(state);
71+
72+
#[cfg(not(debug_assertions))]
73+
{
74+
let router = router.fallback_service(web_service());
75+
}
76+
router
7277
}
7378

7479
pub fn api_router(state: AppState) -> Router<AppState> {
@@ -109,6 +114,7 @@ fn access_token_auth_router(state: AppState) -> Router<AppState> {
109114
.layer(middleware::from_fn_with_state(state, validate_access_token))
110115
}
111116

117+
#[cfg(not(debug_assertions))]
112118
fn web_service() -> ServeDir<ServeFile> {
113119
ServeDir::new(STATIC_ASSETS_PATH).fallback(ServeFile::new(INDEX_HTML_PATH))
114120
}

0 commit comments

Comments
 (0)