From 45572312561a2986a3e093927de4e44935d3721e Mon Sep 17 00:00:00 2001 From: JeremyLARDENOIS Date: Fri, 9 Jan 2026 14:34:27 +0100 Subject: [PATCH] feat: dockerize application --- .drone.yml | 53 +++++++++++++++++++++++++++++----------------- Dockerfile | 17 +++++++++++++++ docker-compose.yml | 16 +++++++++++++- 3 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 Dockerfile diff --git a/.drone.yml b/.drone.yml index 71c861f..781a0a4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,34 +7,47 @@ platform: steps: - name: build-release - image: rust:1.91 + image: rust:1.92 commands: - cargo build --verbose --workspace --release - name: test - image: rust:1.91 + image: rust:1.92 commands: - cargo test --verbose --workspace - name: lint - image: rust:1.91 + image: rust:1.92 commands: - rustup component add clippy - cargo clippy --all-targets --all-features -- name: push-binary-release - image: plugins/gitea-release +- name: format + image: rust:1.92 + commands: + - rustup component add rustfmt + - cargo fmt --all -- --check +- name: build-image + image: plugins/docker settings: - base_url: https://gitea.lardenois.cc - api_key: - from_secret: gitea-package - files: - - target/release/pg-instance-handler - title: "Release ${DRONE_TAG:-v${DRONE_BUILD_NUMBER}}" - note: "Automated release from commit ${DRONE_COMMIT_SHA}" - checksum: - - sha256 + repo: gitea.lardenois.cc/jerem/nats-test + tags: latest + dockerfile: Dockerfile + dry_run: "true" when: - event: tag - status: success - depends_on: - - build-release - - test - - lint + branch: + exclude: + - main +- name: build-and-push-image + image: plugins/docker + settings: + registry: gitea.lardenois.cc + repo: gitea.lardenois.cc/matos-ai/pg-instance-handler + tags: + - latest + dockerfile: Dockerfile + username: + from_secret: GITEA_USER + password: + from_secret: GITEA_PASSWORD + when: + branch: + include: + - main diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..038c9f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM rust:1.92 AS builder + +RUN rustup target add x86_64-unknown-linux-musl +RUN apt-get update && apt-get install -y musl-tools && rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/src/app + +COPY ./Cargo.toml ./Cargo.lock ./ +COPY ./src ./src + +RUN cargo build --release --target x86_64-unknown-linux-musl + +FROM scratch + +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/pg-instance-handler /pg-instance-handler + +CMD ["/pg-instance-handler"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b525354..3fc9ade 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,4 +10,18 @@ services: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s timeout: 5s - retries: 5 \ No newline at end of file + retries: 5 + + pg-instance-handler: + build: + context: . + dockerfile: Dockerfile + depends_on: + postgres: + condition: service_healthy + environment: + DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres + ports: + - "8080:8080" + volumes: + - ./database.txt:/database.txt:ro \ No newline at end of file