And the compose deploy now works

This commit is contained in:
Joshua Coles 2023-09-04 17:41:19 +01:00
parent f6431ee922
commit ce8a22203d
3 changed files with 44 additions and 46 deletions

View File

@ -21,6 +21,8 @@ WORKDIR /app
# source code into the container. Once built, copy the executable to an # source code into the container. Once built, copy the executable to an
# output directory before the cache mounted /app/target is unmounted. # output directory before the cache mounted /app/target is unmounted.
RUN --mount=type=bind,source=src,target=src \ RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=entity,target=entity \
--mount=type=bind,source=migration,target=migration \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \ --mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \ --mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \ --mount=type=cache,target=/app/target/ \
@ -44,6 +46,12 @@ EOF
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57). # (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
FROM debian:bullseye-slim AS final FROM debian:bullseye-slim AS final
RUN set -ex; \
apt-get update && \
apt-get -y install --no-install-recommends \
ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Create a non-privileged user that the app will run under. # Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user # See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001 ARG UID=10001
@ -63,5 +71,8 @@ COPY --from=build /bin/server /bin/
# Expose the port that the application listens on. # Expose the port that the application listens on.
EXPOSE 3000 EXPOSE 3000
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# What the container should run when it is started. # What the container should run when it is started.
CMD ["/bin/server"] CMD ["/bin/server"]

View File

@ -1,12 +1,3 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker compose reference guide at
# https://docs.docker.com/compose/compose-file/
# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services: services:
server: server:
build: build:
@ -14,37 +5,26 @@ services:
target: final target: final
ports: ports:
- 3000:3000 - 3000:3000
environment:
# The commented out section below is an example of how to define a PostgreSQL - DATABASE_URL=postgres://postgres:64ED6F27-D08D-40B4-BC80-034C7C207986@db/postgres
# database that your application can use. `depends_on` tells Docker Compose to depends_on:
# start the database before your application. The `db-data` volume persists the db:
# database data between container restarts. The `db-password` secret is used condition: service_healthy
# to set the database password. You must create `db/password.txt` and add db:
# a password of your choosing to it before running `docker compose up`. image: postgres
# depends_on: restart: always
# db: user: postgres
# condition: service_healthy # secrets:
# db: # - db-password
# image: postgres volumes:
# restart: always - db-data:/var/lib/postgresql/data
# user: postgres environment:
# secrets: - POSTGRES_DB=example
# - db-password - POSTGRES_PASSWORD=64ED6F27-D08D-40B4-BC80-034C7C207986
# volumes: healthcheck:
# - db-data:/var/lib/postgresql/data test: [ "CMD", "pg_isready" ]
# environment: interval: 10s
# - POSTGRES_DB=example timeout: 5s
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password retries: 5
# expose: volumes:
# - 5432 db-data:
# healthcheck:
# test: [ "CMD", "pg_isready" ]
# interval: 10s
# timeout: 5s
# retries: 5
# volumes:
# db-data:
# secrets:
# db-password:
# file: db/password.txt

View File

@ -5,19 +5,26 @@ use axum::{Extension, Router};
use std::net::SocketAddr; use std::net::SocketAddr;
use axum::routing::{get, post}; use axum::routing::{get, post};
use clap::Parser; use clap::Parser;
use sea_orm::{ConnectionTrait, DatabaseConnection};
use migration::{Migrator, MigratorTrait}; use migration::{Migrator, MigratorTrait};
use crate::error::AppError;
use crate::ingestion::ingestion::{monzo_batched_csv, monzo_batched_json, monzo_updated}; use crate::ingestion::ingestion::{monzo_batched_csv, monzo_batched_json, monzo_updated};
#[derive(Debug, clap::Parser)] #[derive(Debug, clap::Parser)]
struct Config { struct Config {
#[clap(short, long, env)] #[clap(short, long, env, default_value = "0.0.0.0:3000")]
addr: SocketAddr, addr: SocketAddr,
#[clap(short, long = "db", env)] #[clap(short, long = "db", env)]
database_url: String, database_url: String,
} }
async fn health_check() -> &'static str { async fn health_check(
"Ok" Extension(db): Extension<DatabaseConnection>,
) -> Result<&'static str, AppError> {
db.execute_unprepared("SELECT 1")
.await?;
Ok("Ok")
} }
#[tokio::main] #[tokio::main]