Skip to content

Commit 51f2597

Browse files
reduce docker image size down to 183MB, add support for linux/arm64
1 parent a0ad914 commit 51f2597

5 files changed

Lines changed: 32 additions & 18 deletions

File tree

.github/workflows/docker-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ jobs:
5757

5858
# target:
5959

60-
# platforms: linux/amd64
60+
platforms: linux/amd64,linux/arm64
6161

6262
# comment-enable: true

Dockerfile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,19 @@ COPY ./frontend .
4343

4444
RUN --mount=type=cache,target=/root/.npm \
4545
npm ci --verbose --no-audit
46+
47+
# don't include any frontend custom config
48+
RUN rm .env
49+
4650
# This should be npm run build
4751
RUN npx vite build
4852

4953
FROM debian:bookworm-slim AS runtime
5054

5155
WORKDIR /app
5256

53-
RUN apt-get update && apt-get install -y libssl-dev openssl curl pkg-config ca-certificates nginx postgresql tini gcc
54-
55-
# install sqlx-cli to handle database migrations
56-
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
57-
ENV PATH="/root/.cargo/bin:${PATH}"
58-
RUN cargo install sqlx-cli
59-
60-
COPY ./backend/migrations/ /migrations
61-
62-
COPY ./docker/initdb.sh /
63-
RUN chmod +x /initdb.sh
57+
RUN apt-get update && apt-get install --no-install-recommends -y libssl-dev openssl curl pkg-config ca-certificates nginx tini
58+
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
6459

6560
COPY --from=builder_backend /usr/local/bin/dasharr_backend /usr/local/bin
6661

@@ -75,7 +70,6 @@ EXPOSE 80
7570
ENTRYPOINT ["/usr/bin/tini", "--"]
7671

7772
CMD ["sh", "-c", "\
78-
cd / && /initdb.sh && \
7973
cd /usr/local/bin/ && ./dasharr_backend & \
8074
nginx -g 'daemon off;' & \
8175
wait"]

backend/.env.example

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
RUST_LOG="info,sqlx=info"
1313

1414
# port on which the api will be listening
15-
# if using docker, do not change it, everything goes through nginx
16-
# which redirects api calls to this port
15+
# if using docker, DO NOT CHANGE IT, everything goes through nginx (port 80 in the container)
16+
# which redirects api calls (everything on /api) to this port
1717
WEB_SERVER_PORT=8080
1818

1919
POSTGRES_USER=dasharr
2020
POSTGRES_PASSWORD=password
21-
POSTGRES_HOST=localhost
21+
22+
# if using regular installation:
23+
# POSTGRES_HOST=localhost
2224
# if using docker:
23-
# POSTGRES_HOST=db
25+
POSTGRES_HOST=db
26+
2427
POSTGRES_PORT=5432
2528
POSTGRES_DB=dasharr
2629

backend/src/connection_pool.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use sqlx::{PgPool, postgres::PgPoolOptions};
2-
use std::borrow::{Borrow, BorrowMut};
2+
use std::{
3+
borrow::{Borrow, BorrowMut},
4+
ops::Deref,
5+
};
36

47
pub struct ConnectionPool(PgPool);
58

@@ -30,3 +33,10 @@ impl BorrowMut<PgPool> for ConnectionPool {
3033
&mut self.0
3134
}
3235
}
36+
37+
impl Deref for ConnectionPool {
38+
type Target = PgPool;
39+
fn deref(&self) -> &Self::Target {
40+
&self.0
41+
}
42+
}

backend/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use dasharr::{
55
scheduler::run_periodic_tasks,
66
};
77
use envconfig::Envconfig;
8+
use std::borrow::Borrow;
9+
use std::ops::Deref;
810
use std::{env, sync::Arc};
911
use utoipa::OpenApi;
1012
use utoipa_swagger_ui::SwaggerUi;
@@ -22,6 +24,11 @@ async fn main() -> std::io::Result<()> {
2224
.expect("db connection couldn't be established"),
2325
);
2426

27+
sqlx::migrate!("./migrations")
28+
.run(pool.deref().borrow())
29+
.await
30+
.expect("Failed to run database migrations!");
31+
2532
let arc = Data::new(Dasharr::new(Arc::clone(&pool), env.clone()));
2633

2734
let web_server_port = env::var("WEB_SERVER_PORT").expect("WEB_SERVER_PORT must be set");

0 commit comments

Comments
 (0)