And the compose deploy now works
This commit is contained in:
parent
f6431ee922
commit
ce8a22203d
11
Dockerfile
11
Dockerfile
@ -21,6 +21,8 @@ WORKDIR /app
|
||||
# source code into the container. Once built, copy the executable to an
|
||||
# output directory before the cache mounted /app/target is unmounted.
|
||||
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.lock,target=Cargo.lock \
|
||||
--mount=type=cache,target=/app/target/ \
|
||||
@ -44,6 +46,12 @@ EOF
|
||||
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
|
||||
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.
|
||||
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
|
||||
ARG UID=10001
|
||||
@ -63,5 +71,8 @@ COPY --from=build /bin/server /bin/
|
||||
# Expose the port that the application listens on.
|
||||
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.
|
||||
CMD ["/bin/server"]
|
||||
|
||||
66
compose.yaml
66
compose.yaml
@ -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:
|
||||
server:
|
||||
build:
|
||||
@ -14,37 +5,26 @@ services:
|
||||
target: final
|
||||
ports:
|
||||
- 3000:3000
|
||||
|
||||
# The commented out section below is an example of how to define a PostgreSQL
|
||||
# database that your application can use. `depends_on` tells Docker Compose to
|
||||
# start the database before your application. The `db-data` volume persists the
|
||||
# database data between container restarts. The `db-password` secret is used
|
||||
# to set the database password. You must create `db/password.txt` and add
|
||||
# a password of your choosing to it before running `docker compose up`.
|
||||
# depends_on:
|
||||
# db:
|
||||
# condition: service_healthy
|
||||
# db:
|
||||
# image: postgres
|
||||
# restart: always
|
||||
# user: postgres
|
||||
# secrets:
|
||||
# - db-password
|
||||
# volumes:
|
||||
# - db-data:/var/lib/postgresql/data
|
||||
# environment:
|
||||
# - POSTGRES_DB=example
|
||||
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
|
||||
# expose:
|
||||
# - 5432
|
||||
# healthcheck:
|
||||
# test: [ "CMD", "pg_isready" ]
|
||||
# interval: 10s
|
||||
# timeout: 5s
|
||||
# retries: 5
|
||||
# volumes:
|
||||
# db-data:
|
||||
# secrets:
|
||||
# db-password:
|
||||
# file: db/password.txt
|
||||
|
||||
environment:
|
||||
- DATABASE_URL=postgres://postgres:64ED6F27-D08D-40B4-BC80-034C7C207986@db/postgres
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
db:
|
||||
image: postgres
|
||||
restart: always
|
||||
user: postgres
|
||||
# secrets:
|
||||
# - db-password
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_DB=example
|
||||
- POSTGRES_PASSWORD=64ED6F27-D08D-40B4-BC80-034C7C207986
|
||||
healthcheck:
|
||||
test: [ "CMD", "pg_isready" ]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
volumes:
|
||||
db-data:
|
||||
|
||||
13
src/main.rs
13
src/main.rs
@ -5,19 +5,26 @@ use axum::{Extension, Router};
|
||||
use std::net::SocketAddr;
|
||||
use axum::routing::{get, post};
|
||||
use clap::Parser;
|
||||
use sea_orm::{ConnectionTrait, DatabaseConnection};
|
||||
use migration::{Migrator, MigratorTrait};
|
||||
use crate::error::AppError;
|
||||
use crate::ingestion::ingestion::{monzo_batched_csv, monzo_batched_json, monzo_updated};
|
||||
|
||||
#[derive(Debug, clap::Parser)]
|
||||
struct Config {
|
||||
#[clap(short, long, env)]
|
||||
#[clap(short, long, env, default_value = "0.0.0.0:3000")]
|
||||
addr: SocketAddr,
|
||||
#[clap(short, long = "db", env)]
|
||||
database_url: String,
|
||||
}
|
||||
|
||||
async fn health_check() -> &'static str {
|
||||
"Ok"
|
||||
async fn health_check(
|
||||
Extension(db): Extension<DatabaseConnection>,
|
||||
) -> Result<&'static str, AppError> {
|
||||
db.execute_unprepared("SELECT 1")
|
||||
.await?;
|
||||
|
||||
Ok("Ok")
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user