Compare commits

...

4 Commits
main ... docker

Author SHA1 Message Date
trivernis 2c02320d83
Swap postgresql-client for libpq5 in docker build
Signed-off-by: trivernis <trivernis@protonmail.com>
4 years ago
trivernis 314e305bba
Remove build-essential package from runtime container
Signed-off-by: trivernis <trivernis@protonmail.com>
4 years ago
trivernis 6a56c02712
Fix docker build
Signed-off-by: trivernis <trivernis@protonmail.com>
4 years ago
trivernis 1550cebdf7
Add Dockerfile
Signed-off-by: trivernis <trivernis@protonmail.com>
4 years ago

@ -0,0 +1,2 @@
target
.env

@ -0,0 +1,24 @@
# syntax=docker/dockerfile:1.0-experimental
FROM rust:latest AS builder
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev libopus-dev libpq-dev
WORKDIR /usr/src
RUN USER=root cargo new tobi
WORKDIR /usr/src/tobi
COPY Cargo.toml Cargo.lock ./
COPY src ./src
COPY bot-coreutils ./bot-coreutils
COPY bot-database ./bot-database
COPY bot-serenityutils ./bot-serenityutils
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=target \
cargo build --release
RUN mkdir /tmp/tobi
RUN --mount=type=cache,target=target cp target/release/tobi-rs /tmp/tobi/
FROM bitnami/minideb:latest
RUN install_packages openssl libopus0 ffmpeg python3 python3-pip libpq5
RUN pip3 install youtube-dl
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/
COPY --from=builder /tmp/tobi/tobi-rs .
ENTRYPOINT ["/tobi-rs"]

@ -4,9 +4,9 @@ extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
use crate::error::DatabaseResult;
use crate::error::{DatabaseError, DatabaseResult};
use diesel::prelude::*;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::r2d2::{ConnectionManager, ManageConnection, Pool};
use std::env;
pub mod database;
@ -22,11 +22,16 @@ type PoolConnection = Pool<ConnectionManager<PgConnection>>;
embed_migrations!("../bot-database/migrations");
fn get_connection() -> DatabaseResult<PoolConnection> {
dotenv::dotenv()?;
let database_url = env::var("DATABASE_URL").expect("No DATABASE_URL in path");
log::debug!("Establishing database connection...");
let manager = ConnectionManager::<PgConnection>::new(database_url);
log::trace!("Connecting...");
manager
.connect()
.map_err(|e| DatabaseError::Msg(format!("{:?}", e)))?;
log::trace!("Creating pool...");
let pool = Pool::builder().max_size(16).build(manager)?;
log::trace!("Getting one connection to run migrations...");
let connection = pool.get()?;
log::debug!("Running migrations...");
embedded_migrations::run(&connection)?;

@ -15,8 +15,12 @@ pub static VERSION: &str = env!("CARGO_PKG_VERSION");
#[tokio::main]
async fn main() {
let _ = dotenv::dotenv();
init_logger();
let mut client = get_client().await.unwrap();
let mut client = get_client()
.await
.map_err(|e| log::error!("Failed to get client: {:?}", e))
.expect("Failed to get client");
// start listening for events by starting a single shard
if let Err(why) = client.start_autosharded().await {

Loading…
Cancel
Save