From 5f00fa41eb84fc9d79d1f7fa1c43f0afbd2e7451 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Fri, 18 Oct 2024 13:39:58 -0500 Subject: [PATCH 1/3] Add in `docker-compose` files --- .gitignore | 1 + dkr/app.dockerfile | 23 +++++++++++++++++++++++ docker-compose.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 dkr/app.dockerfile create mode 100644 docker-compose.yaml diff --git a/.gitignore b/.gitignore index fedaa2b..cd032e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/.vscode /target .env diff --git a/dkr/app.dockerfile b/dkr/app.dockerfile new file mode 100644 index 0000000..4517b0a --- /dev/null +++ b/dkr/app.dockerfile @@ -0,0 +1,23 @@ +# FIXME: Use mariner once they support the latest Rust. +# FROM mcr.microsoft.com/cbl-mariner/base/rust:1 as builder +FROM rust:1-bullseye AS builder + +COPY Cargo.lock /build/ +COPY Cargo.toml /build/ +COPY src /build/src + +# Build the default page +WORKDIR /build + +RUN cargo build --release +RUN mkdir -p /app && mv target/release/nederlandskie /app/ + +# FROM mcr.microsoft.com/cbl-mariner/distroless/base:2.0 +FROM debian:bullseye-slim + +COPY --from=builder /app /app + +WORKDIR /app +EXPOSE 8000 + +ENTRYPOINT [ "/app/nederlandskie" ] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..0124369 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,41 @@ +version: '3.8' +services: + db: + image: mcr.microsoft.com/cbl-mariner/base/postgres:14 + restart: always + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + ports: + - '5432:5432' + networks: + - backend + volumes: + - ./sql:/docker-entrypoint-initdb.d + - db:/var/lib/postgresql/data + api: + build: + context: . + dockerfile: dkr/app.dockerfile + command: 'launch' + image: nederlandskie + depends_on: + - db + ports: + - 8000:8000 + networks: + - backend + # environment: + # DATABASE_URL: 'postgres://postgres:postgres@db/nederlandskie' + volumes: + - ./.env:/app/.env + links: + - db + +networks: + backend: + + +volumes: + db: + driver: local From f90841ce8da3f07c15a7f73ed4c819ee42820366 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Fri, 18 Oct 2024 13:48:53 -0500 Subject: [PATCH 2/3] Create database first --- sql/00_create_database.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 sql/00_create_database.sql diff --git a/sql/00_create_database.sql b/sql/00_create_database.sql new file mode 100644 index 0000000..a032f37 --- /dev/null +++ b/sql/00_create_database.sql @@ -0,0 +1 @@ +CREATE DATABASE nederlandskie; \ No newline at end of file From 8f5dd6b50ea4b5b2cdbac182c8d1a330fffea6c0 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Fri, 18 Oct 2024 14:24:45 -0500 Subject: [PATCH 3/3] Server is now properly working --- dkr/app.dockerfile | 3 +++ docker-compose.yaml | 1 + sql/00_create_database.sql | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 sql/00_create_database.sql diff --git a/dkr/app.dockerfile b/dkr/app.dockerfile index 4517b0a..60efe86 100644 --- a/dkr/app.dockerfile +++ b/dkr/app.dockerfile @@ -15,6 +15,9 @@ RUN mkdir -p /app && mv target/release/nederlandskie /app/ # FROM mcr.microsoft.com/cbl-mariner/distroless/base:2.0 FROM debian:bullseye-slim +RUN apt-get update && apt-get install -y ca-certificates +RUN update-ca-certificates + COPY --from=builder /app /app WORKDIR /app diff --git a/docker-compose.yaml b/docker-compose.yaml index 0124369..4ed57b9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,6 +6,7 @@ services: environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=nederlandskie ports: - '5432:5432' networks: diff --git a/sql/00_create_database.sql b/sql/00_create_database.sql deleted file mode 100644 index a032f37..0000000 --- a/sql/00_create_database.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE DATABASE nederlandskie; \ No newline at end of file