Skip to content

Commit

Permalink
Dockerfile for building a linux build works now. Added an include_tem…
Browse files Browse the repository at this point in the history
…plates! macro.
  • Loading branch information
golddranks committed Nov 18, 2016
1 parent 315485e commit 7984a12
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
37 changes: 26 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
FROM clux/muslrust
FROM debian:jessie
MAINTAINER Pyry Kontio <[email protected]>

RUN apt-get update && apt-get install -y \
libpq-dev \
sqlite3 \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*
curl \
git \
libpq-dev \
sqlite3 \
ca-certificates \
g++ \
postgresql \
postgresql-client \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*

RUN git clone --branch 0.1 https://github.com/golddranks/ganbare.git && cd ganbare
RUN ln -s /lib/x86_64-linux-gnu/libsqlite3.so.0 /lib/x86_64-linux-gnu/libsqlite3.so
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2016-11-06
RUN git clone --branch 0.1.1 https://github.com/golddranks/ganbare.git
RUN ln -s /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 /usr/lib/x86_64-linux-gnu/libsqlite3.so
RUN /root/.cargo/bin/cargo install diesel_cli

ENV RUN DATABASE_URL=postgres://[email protected]/ganbare_testing
ENV GANBARE_DATABASE_URL=postgres://[email protected]/ganbare_testing
ENV GANBARE_BUILDTIME_PEPPER=`cat /dev/urandom | base64 | head -c 42`
ENV DATABASE_URL=postgres://root@%2Fvar%2Frun%2Fpostgresql/ganbare_build
ENV GANBARE_DATABASE_URL=postgres://root@%2Fvar%2Frun%2Fpostgresql/ganbare_build

RUN cargo install diesel_cli && diesel database setup && cargo build --release
WORKDIR ganbare

RUN /etc/init.d/postgresql start && \
su - postgres -c "createuser root; psql -c 'alter user root with createdb'" && \
bash -l -c "/root/.cargo/bin/diesel database setup;"

RUN /etc/init.d/postgresql start && \
bash -l -c "GANBARE_BUILDTIME_PEPPER=`cat /dev/urandom | head -c 32 | base64` \
/root/.cargo/bin/cargo build --release"
26 changes: 22 additions & 4 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,16 @@ fn post_question(req: &mut Request) -> PencilResult {
redirect(&new_url, 303).map(|resp| resp.refresh_cookie(&conn, &sess, req.remote_addr().ip()) )
}

macro_rules! include_templates(
($app:ident, $temp_dir:expr, $($file:expr),*) => { {
let mut reg = $app.handlebars_registry.write().expect("This is supposed to fail fast and hard.");
$(
reg.register_template_string($file, include_str!(concat!(env!("PWD"), "/", $temp_dir, "/", $file)).to_string())
.expect("This is supposed to fail fast and hard.");
)*
} }
);

fn main() {
println!("Starting.");
dotenv().ok();
Expand All @@ -870,19 +880,27 @@ fn main() {
println!("Database OK.");

let mut app = Pencil::new(".");

include_templates!(app, "templates", "hello.html", "main.html", "confirm.html", "add_quiz.html", "add_word.html", "manage.html", "change_password.html");

/*
app.register_template("hello.html");
app.register_template("main.html");
app.register_template("confirm.html");
app.register_template("add_quiz.html");
app.register_template("add_word.html");
app.register_template("manage.html");
app.register_template("change_password.html");
app.enable_static_file_handling();
println!("Templates loaded.");
*/

app.enable_static_file_handling();

// app.set_debug(true);
// app.set_log_level();
// env_logger::init().unwrap();
/*
app.set_debug(true);
app.set_log_level();
env_logger::init().unwrap();
*/

app.get("/", "hello", hello);
app.post("/logout", "logout", logout);
Expand Down

0 comments on commit 7984a12

Please sign in to comment.