Skip to content

Commit

Permalink
Add igni deploy config
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin committed Jan 13, 2025
1 parent b2be8e4 commit 5999f37
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 3 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ RUN sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list.d/debian.s
libopencv-dev \
python3 \
python3-pip \
wait-for-it \
&& rm -rf /var/lib/apt/lists/*

USER vscode
Expand Down
39 changes: 39 additions & 0 deletions vidformer-igni/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM debian:bookworm AS build

RUN sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list.d/debian.sources && \
apt update && \
apt upgrade -y && \
apt install -y curl build-essential pkg-config yasm libfdk-aac-dev libvpx-dev libx264-dev libopencv-dev clang && \
rm -rf /var/lib/apt/lists/*

WORKDIR /src

# Build ffmpeg
RUN curl https://ffmpeg.org/releases/ffmpeg-7.0.tar.xz | tar xJ && \
mv ffmpeg-7.0 ffmpeg
RUN cd ffmpeg && mkdir build && ./configure --prefix=/src/ffmpeg/build --pkg-config-flags="--static" --enable-nonfree --enable-gpl --enable-libx264 --enable-libvpx --enable-libfdk-aac --disable-stripping --disable-decoder=exr,phm && make -j$(nproc) && make install

# Install rust toolchain
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Build vidformer
COPY ./Cargo.toml ./
COPY ./vidformer ./vidformer
COPY ./vidformer-cli ./vidformer-cli
COPY ./vidformer-igni ./vidformer-igni
ENV FFMPEG_PKG_CONFIG_PATH="/src/ffmpeg/build/lib/pkgconfig" FFMPEG_INCLUDE_DIR="/src/ffmpeg/build/include"
RUN cargo build --release -p vidformer-igni

FROM debian:bookworm

RUN sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list.d/debian.sources && \
apt update && \
apt upgrade -y && \
apt install -y libopencv-dev libfdk-aac-dev wait-for-it && \
rm -rf /var/lib/apt/lists/*

COPY --from=build /src/target/release/vidformer-igni /usr/local/bin/vidformer-igni

EXPOSE 8000
ENTRYPOINT [ "/usr/local/bin/vidformer-igni" ]
11 changes: 10 additions & 1 deletion vidformer-igni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

The next generation scale-out vidformer server.

## Development Deployment
## Development Setup

```bash
docker-compose -f docker-compose-db.yaml up
cargo run -- user add --name test --api-key test
cargo run -- server --config igni.toml
```

## Deployment

```bash
# From vidformer project root
docker build -t igni -f vidformer-igni/Dockerfile .
cd vidformer-igni
docker-compose -f docker-compose-prod.yaml up
```
12 changes: 12 additions & 0 deletions vidformer-igni/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

access_log /var/log/nginx/host.access.log main;

location / {
proxy_pass http://igni:8080;
proxy_set_header Host $host;
}
}
38 changes: 38 additions & 0 deletions vidformer-igni/docker-compose-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
services:
postgres:
image: postgres:latest
container_name: igni_db
environment:
POSTGRES_USER: igni
POSTGRES_PASSWORD: igni
POSTGRES_DB: igni
ports:
- "127.0.0.1:5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init:/docker-entrypoint-initdb.d
web:
image: nginx
container_name: igni_web
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./conf.d:/etc/nginx/conf.d
- nginx_logs:/var/log/nginx
igni:
image: igni
container_name: igni_app
entrypoint: ["wait-for-it", "postgres:5432", "--", "/usr/local/bin/vidformer-igni", "server", "--config", "/etc/igni.toml"]
environment:
IGNI_DB: postgres://igni:igni@postgres:5432/igni
ports:
- "127.0.0.1:8080:8080"
volumes:
- ./igni.toml:/etc/igni.toml
depends_on:
- postgres
volumes:
postgres_data:
nginx_logs:
32 changes: 32 additions & 0 deletions vidformer-igni/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}
12 changes: 11 additions & 1 deletion vidformer-igni/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,19 @@ async fn db_connect() -> Result<sqlx::Pool<sqlx::Postgres>, IgniError> {
let timeout = std::time::Duration::from_secs(10);
let start_time = std::time::Instant::now();
loop {
// Pull connection string from environment
let conn_str = match std::env::var("IGNI_DB") {
Ok(s) => s,
Err(_) => {
return Err(IgniError::General(
"Environment variable IGNI_DB not set".to_string(),
));
}
};

match PgPoolOptions::new()
.max_connections(10)
.connect("postgres://igni:igni@localhost/igni")
.connect(&conn_str)
.await
{
Ok(pool) => {
Expand Down
2 changes: 1 addition & 1 deletion vidformer-igni/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) async fn cmd_server(
.await
.map_err(|e| IgniError::General(format!("Failed to bind to {}: {}", addr, e)))?;

info!("Opened server on {}", addr);
println!("Opened igni server on {}", addr);

loop {
let (stream, client_addr) = match listener.accept().await {
Expand Down

0 comments on commit 5999f37

Please sign in to comment.