-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from slowlydev/feature/dockerize-and-health-c…
…heck Ffeature/dockerize-and-health-check
- Loading branch information
Showing
10 changed files
with
149 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM rust:1-alpine as build | ||
|
||
WORKDIR /usr/src/app | ||
COPY . . | ||
COPY ./.sqlx . | ||
|
||
RUN apk add --no-cache musl-dev pkgconfig openssl libressl-dev | ||
ENV SQLX_OFFLINE true | ||
RUN cargo build --release | ||
|
||
FROM alpine | ||
|
||
COPY --from=build /usr/src/app/target/release/api-backend /usr/local/bin/api-backend | ||
|
||
CMD ["api-backend"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use axum::{http::StatusCode, response::IntoResponse}; | ||
|
||
pub async fn check() -> Result<impl IntoResponse, StatusCode> { | ||
Ok(StatusCode::OK) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM node:20-alpine AS base | ||
|
||
WORKDIR /app | ||
COPY package*.json ./ | ||
COPY yarn.lock ./ | ||
|
||
|
||
RUN corepack enable yarn | ||
|
||
RUN yarn install --frozen-lockfile | ||
|
||
COPY . . | ||
|
||
RUN yarn build | ||
|
||
FROM node:20-alpine AS runtime | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=base /app/.next ./.next | ||
COPY --from=base /app/node_modules ./node_modules | ||
COPY --from=base /app/package.json ./package.json | ||
COPY --from=base /app/public ./public | ||
|
||
ENV NODE_ENV=production | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["yarn", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.git | ||
.results | ||
scripts | ||
*dockerfile* | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
version: "3" | ||
|
||
services: | ||
dash: | ||
build: ./dash/ | ||
ports: | ||
- 3000:3000 | ||
restart: always | ||
profiles: | ||
- full | ||
depends_on: | ||
- api-backend | ||
- live-backend | ||
environment: | ||
- NEXT_PUBLIC_LIVE_SOCKET_URL=http://live-backend:4000 | ||
- NEXT_PUBLIC_API_URL=http://api-backend:4001 | ||
|
||
api-backend: | ||
build: ./api-backend/ | ||
ports: | ||
- 4001:4001 | ||
restart: always | ||
profiles: | ||
- full | ||
- backends | ||
environment: | ||
- BACKEND_ADDRESS=127.0.0.1:4001 | ||
- LOG_LEVEL=info | ||
|
||
live-backend: | ||
build: ./live-backend/ | ||
ports: | ||
- 4000:4000 | ||
restart: always | ||
profiles: | ||
- full | ||
- backends | ||
depends_on: | ||
- timescaledb | ||
environment: | ||
- DATABASE_URL=postgres://postgres:password@timescaledb:5432/postgres | ||
- RUST_LOG="live_backend=trace,debug,info" | ||
- BACKEND_ADDRESS=0.0.0.0:4000 | ||
- ORIGIN=http://localhost:3000 | ||
|
||
timescaledb: | ||
image: timescale/timescaledb:latest-pg16 | ||
ports: | ||
- 5432:5432 | ||
restart: always | ||
profiles: | ||
- full | ||
- backends | ||
environment: | ||
- POSTGRES_PASSWORD=password |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM rust:1-alpine as build | ||
|
||
WORKDIR /usr/src/app | ||
COPY . . | ||
COPY ./.sqlx . | ||
|
||
RUN apk add --no-cache musl-dev pkgconfig openssl libressl-dev | ||
ENV SQLX_OFFLINE true | ||
RUN cargo build --release | ||
|
||
FROM alpine | ||
|
||
COPY --from=build /usr/src/app/target/release/live-backend /usr/local/bin/live-backend | ||
|
||
CMD ["live-backend"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; | ||
use serde_json::json; | ||
|
||
use super::AppState; | ||
|
||
pub async fn check(State(state): State<Arc<AppState>>) -> Result<impl IntoResponse, StatusCode> { | ||
let db_connected = sqlx::query("SELECT 1").fetch_one(&state.db).await.is_ok(); | ||
|
||
if db_connected { | ||
Ok((StatusCode::OK, Json(json!({ "db": true })))) | ||
} else { | ||
Ok(( | ||
StatusCode::SERVICE_UNAVAILABLE, | ||
Json(json!({ "db": false })), | ||
)) | ||
} | ||
} |