Fixed dockerfile, put in temporary fix to create table in docker
This commit is contained in:
15
Dockerfile
15
Dockerfile
@@ -1,21 +1,22 @@
|
||||
FROM rust:1.67 as builder
|
||||
WORKDIR /siren
|
||||
RUN apt-get update && apt-get install -y cmake && apt-get auto-remove -y
|
||||
ADD src ./src/
|
||||
ADD Cargo.toml ./
|
||||
RUN cargo build --release --bin siren
|
||||
RUN apt-get update && apt-get install -y cmake && \
|
||||
cargo build --release --bin siren
|
||||
|
||||
FROM debian:bullseye-slim as packages
|
||||
WORKDIR /packages
|
||||
RUN apt-get update && apt-get install -y libopus-dev libpq5 libpq-dev curl tar xz-utils
|
||||
RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux > yt-dlp && \
|
||||
chmod +x yt-dlp
|
||||
RUN curl -L https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz > ffmpeg.tar.xz && \
|
||||
RUN apt-get update && apt-get install -y curl tar xz-utils && \
|
||||
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux > yt-dlp && \
|
||||
chmod +x yt-dlp && \
|
||||
curl -L https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz > ffmpeg.tar.xz && \
|
||||
tar -xJf ffmpeg.tar.xz --wildcards */bin/ffmpeg --transform='s/^.*\///' && rm ffmpeg.tar.xz
|
||||
|
||||
FROM debian:bullseye-slim as runtime
|
||||
WORKDIR /siren
|
||||
RUN apt-get update && apt-get install -y libopus-dev libpq5 libpq-dev && apt-get auto-remove -y
|
||||
COPY --from=builder /siren/target/release/siren /usr/local/bin/siren
|
||||
COPY --from=packages /packages /usr/bin
|
||||
# ADD migrations ./migrations/
|
||||
# ADD migrations ./
|
||||
CMD ["siren"]
|
||||
|
||||
@@ -14,7 +14,11 @@ services:
|
||||
environment:
|
||||
DISCORD_TOKEN: ${DISCORD_TOKEN}
|
||||
RUST_LOG: ${RUST_LOG}
|
||||
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}
|
||||
OPENAI_API_KEY: ${OPENAI_API_KEY}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_HOST: db
|
||||
depends_on:
|
||||
- db
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -205,7 +205,7 @@ pub async fn generate_response(ctx: &Context, msg: &Message, oai: &OAI, pool: &P
|
||||
.and(crate::database::schema::messages::channel_id.eq(channel_id.0 as i64))
|
||||
.and(crate::database::schema::messages::user_id.eq(author_id.0 as i64))
|
||||
)
|
||||
.order(crate::database::schema::messages::created.desc())
|
||||
.order(crate::database::schema::messages::created.asc())
|
||||
.limit(oai.max_context_questions)
|
||||
.load(&mut connection);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
// use std::path::Path;
|
||||
|
||||
use diesel::RunQueryDsl;
|
||||
use diesel::r2d2::{Pool, ConnectionManager};
|
||||
@@ -11,34 +11,51 @@ pub mod schema;
|
||||
|
||||
pub fn run_migrations(pool: &Pool<ConnectionManager<PgConnection>>) {
|
||||
let mut connection = pool.get().unwrap();
|
||||
let migrations_dir = Path::new("./migrations");
|
||||
let migrations = std::fs::read_dir(&migrations_dir).unwrap();
|
||||
|
||||
for migration in migrations {
|
||||
if migration.as_ref().unwrap().file_type().unwrap().is_dir() {
|
||||
let migration_paths = std::fs::read_dir(&migration.unwrap().path()).unwrap();
|
||||
|
||||
for migration_path in migration_paths {
|
||||
if migration_path.as_ref().unwrap().file_name().eq_ignore_ascii_case("up.sql") {
|
||||
let path = &migration_path.unwrap().path();
|
||||
let contents = std::fs::read_to_string(path).expect("Unable to read from file");
|
||||
if let Err(err) = diesel::sql_query(&contents).execute(&mut connection) {
|
||||
error!("Could not run migration: {}", err);
|
||||
if let Err(err) = diesel::sql_query("CREATE TABLE IF NOT EXISTS messages (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
guild_id BIGINT NOT NULL,
|
||||
channel_id BIGINT NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
created BIGINT NOT NULL,
|
||||
model TEXT NOT NULL,
|
||||
request TEXT NOT NULL,
|
||||
response TEXT NOT NULL,
|
||||
request_tags TEXT[] NOT NULL,
|
||||
response_tags TEXT[] NOT NULL
|
||||
)").execute(&mut connection) {
|
||||
error!("Could not create messages table: {}", err);
|
||||
} else {
|
||||
info!("Successfully ran migration: {}", path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
info!("Successfully created messages table");
|
||||
}
|
||||
// let migrations_dir = Path::new("./migrations");
|
||||
// let migrations = std::fs::read_dir(&migrations_dir).unwrap();
|
||||
|
||||
// for migration in migrations {
|
||||
// if migration.as_ref().unwrap().file_type().unwrap().is_dir() {
|
||||
// let migration_paths = std::fs::read_dir(&migration.unwrap().path()).unwrap();
|
||||
|
||||
// for migration_path in migration_paths {
|
||||
// if migration_path.as_ref().unwrap().file_name().eq_ignore_ascii_case("up.sql") {
|
||||
// let path = &migration_path.unwrap().path();
|
||||
// let contents = std::fs::read_to_string(path).expect("Unable to read from file");
|
||||
// if let Err(err) = diesel::sql_query(&contents).execute(&mut connection) {
|
||||
// error!("Could not run migration: {}", err);
|
||||
// } else {
|
||||
// info!("Successfully ran migration: {}", path.display());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn establish_connection() -> Pool<ConnectionManager<PgConnection>> {
|
||||
let database_user = env::var("POSTGRES_USER").expect("Expected a user in the environment");
|
||||
let database_password = env::var("POSTGRES_PASSWORD").expect("Expected a password in the environment");
|
||||
let database_name = env::var("POSTGRES_DB").expect("Expected a database name in the environment");
|
||||
let database_host = env::var("POSTGRES_HOST").unwrap_or("localhost".to_string());
|
||||
|
||||
let database_url = format!("postgres://{}:{}@localhost/{}", database_user, database_password, database_name);
|
||||
let database_url = format!("postgres://{}:{}@{}/{}", database_user, database_password, database_host, database_name);
|
||||
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
||||
Pool::builder().build(manager).expect("Failed to create pool.")
|
||||
}
|
||||
Reference in New Issue
Block a user