reduce docker image size down to 183MB, add support for linux/arm64

This commit is contained in:
FrenchGithubUser
2025-10-06 15:55:46 +02:00
parent a0ad914d61
commit ef8f839d67
5 changed files with 32 additions and 18 deletions

View File

@@ -57,6 +57,6 @@ jobs:
# target:
# platforms: linux/amd64
platforms: linux/amd64,linux/arm64
# comment-enable: true

View File

@@ -43,6 +43,10 @@ COPY ./frontend .
RUN --mount=type=cache,target=/root/.npm \
npm ci --verbose --no-audit
# don't include any frontend custom config
RUN rm -f .env
# This should be npm run build
RUN npx vite build
@@ -50,17 +54,8 @@ FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN apt-get update && apt-get install -y libssl-dev openssl curl pkg-config ca-certificates nginx postgresql tini gcc
# install sqlx-cli to handle database migrations
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN cargo install sqlx-cli
COPY ./backend/migrations/ /migrations
COPY ./docker/initdb.sh /
RUN chmod +x /initdb.sh
RUN apt-get update && apt-get install --no-install-recommends -y libssl-dev openssl curl pkg-config ca-certificates nginx tini
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=builder_backend /usr/local/bin/dasharr_backend /usr/local/bin
@@ -75,7 +70,6 @@ EXPOSE 80
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["sh", "-c", "\
cd / && /initdb.sh && \
cd /usr/local/bin/ && ./dasharr_backend & \
nginx -g 'daemon off;' & \
wait"]

View File

@@ -12,15 +12,18 @@
RUST_LOG="info,sqlx=info"
# port on which the api will be listening
# if using docker, do not change it, everything goes through nginx
# which redirects api calls to this port
# if using docker, DO NOT CHANGE IT, everything goes through nginx (port 80 in the container)
# which redirects api calls (everything on /api) to this port
WEB_SERVER_PORT=8080
POSTGRES_USER=dasharr
POSTGRES_PASSWORD=password
POSTGRES_HOST=localhost
# if using regular installation:
# POSTGRES_HOST=localhost
# if using docker:
# POSTGRES_HOST=db
POSTGRES_HOST=db
POSTGRES_PORT=5432
POSTGRES_DB=dasharr

View File

@@ -1,5 +1,8 @@
use sqlx::{PgPool, postgres::PgPoolOptions};
use std::borrow::{Borrow, BorrowMut};
use std::{
borrow::{Borrow, BorrowMut},
ops::Deref,
};
pub struct ConnectionPool(PgPool);
@@ -30,3 +33,10 @@ impl BorrowMut<PgPool> for ConnectionPool {
&mut self.0
}
}
impl Deref for ConnectionPool {
type Target = PgPool;
fn deref(&self) -> &Self::Target {
&self.0
}
}

View File

@@ -5,6 +5,8 @@ use dasharr::{
scheduler::run_periodic_tasks,
};
use envconfig::Envconfig;
use std::borrow::Borrow;
use std::ops::Deref;
use std::{env, sync::Arc};
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
@@ -22,6 +24,11 @@ async fn main() -> std::io::Result<()> {
.expect("db connection couldn't be established"),
);
sqlx::migrate!("./migrations")
.run(pool.deref().borrow())
.await
.expect("Failed to run database migrations!");
let arc = Data::new(Dasharr::new(Arc::clone(&pool), env.clone()));
let web_server_port = env::var("WEB_SERVER_PORT").expect("WEB_SERVER_PORT must be set");