Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
fix(backend): Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
evoxmusic committed Apr 11, 2024
1 parent 0b2a247 commit 5b54f46
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 83 deletions.
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,15 @@ That's it!

### Installation

```bash
cargo build

# run the server
cargo run
```

### Using containers

Build the container images using make for convenience
Today you can run Torii using Docker Compose. In the future, we will provide a Helm chart to deploy Torii on Kubernetes and even locally.

```bash
#From the root of the repository
make docker_build_backend

make docker_build_frontend
docker compose up
```

## Usage

To start Torii, run the following command:

```bash
torii --config ./config.yaml
```

Using docker compose
```bash
docker compose up
```
Once Torii is started, you can access the frontend at `http://localhost:5173`. The backend is available at `http://localhost:9999`.

## Configuration

Expand Down
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

# Sources
!src
!examples
17 changes: 7 additions & 10 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
FROM rust:1.74.0-alpine3.18 as builder
FROM rust:1.77.2-bookworm as builder

WORKDIR /app

COPY . .

# Natively the compilation fails. We need this
# source: https://github.com/ocaml/opam-repository/issues/13718#issuecomment-475550590
RUN apk add --no-cache musl-dev

RUN cargo build --release

###
###
###
# ---

FROM scratch
FROM debian:bookworm-slim

WORKDIR /app

RUN apt update && apt install -y libssl-dev

COPY --from=builder /app/target/release/backend torii
COPY --from=builder /app/examples/config.yaml config.yaml

ENTRYPOINT ["/app/torii"]
ENTRYPOINT ["/app/torii", "-c", "/app/config.yaml"]
30 changes: 0 additions & 30 deletions backend/db/schema.sql

This file was deleted.

38 changes: 34 additions & 4 deletions backend/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@ use sqlx::types::Uuid;

use crate::errors::QError;

const DB_SCHEMA: &str = r#"
-- create status enum if it doesn't exist
DO
$$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'status') THEN
CREATE TYPE status AS ENUM (
'QUEUED',
'RUNNING',
'SUCCESS',
'FAILURE'
);
END IF;
END
$$;
-- create a new flat table to store catalog runs
CREATE TABLE IF NOT EXISTS catalog_runs
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
catalog_slug VARCHAR(255) NOT NULL,
service_slug VARCHAR(255) NOT NULL,
status status NOT NULL,
input_payload JSONB DEFAULT '{}'::jsonb NOT NULL,
tasks JSONB DEFAULT '{}'::jsonb NOT NULL
);
CREATE INDEX IF NOT EXISTS catalog_runs_catalog_slug_idx ON catalog_runs (catalog_slug);
CREATE INDEX IF NOT EXISTS catalog_runs_service_slug_idx ON catalog_runs (service_slug);
"#;

#[derive(sqlx::FromRow)]
pub struct CatalogRun {
id: Uuid,
Expand Down Expand Up @@ -62,11 +95,8 @@ pub struct CatalogRunJson {

/// Initialize the database by creating the tables
pub async fn init_database(pg_pool: &Pool<Postgres>) -> Result<(), QError> {
// read SQL schema from file
let sql_schema = include_str!("../db/schema.sql");

// execute SQL schema
let _ = pg_pool.execute(sql_schema).await?;
let _ = pg_pool.execute(DB_SCHEMA).await?;

Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async fn main() {
}
};

let server_port = env::var("PORT").unwrap_or("9999".to_string());

let connection_string = env::var("DB_CONNECTION_URL")
.unwrap_or("postgres://postgres:postgres@localhost:5432/torii".to_string());

Expand Down Expand Up @@ -123,7 +125,7 @@ async fn main() {
//.route("/catalog/:id", get(catalog::get_catalog_by_id))
//.route("/catalog", post(catalog::create_catalog));

let addr = "0.0.0.0:9999";
let addr = format!("0.0.0.0:{}", server_port);
info!("Server listening on {}", addr);

let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
Expand Down
25 changes: 20 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
services:
frontend:
image: torii-frontend:latest
ports:
- "8080:80"
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "5173:5173"
depends_on:
backend:
condition: service_started
backend:
image: torii-backend:latest
build:
context: ./backend
dockerfile: Dockerfile
restart: always
command:
--config /tmp/examples/config.yaml
Expand All @@ -16,4 +20,15 @@ services:
volumes:
- type: bind
source: ./backend
target: /tmp
target: /tmp
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: torii
ports:
- 5432:5432

0 comments on commit 5b54f46

Please sign in to comment.