This commit is contained in:
Stefan Schwarz 2020-08-22 13:34:32 +02:00
parent 3b00481425
commit b495fc4ea2
5 changed files with 14 additions and 12 deletions

2
Cargo.lock generated
View file

@ -1083,7 +1083,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "macnickenson" name = "mac4nick"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",

View file

@ -1,5 +1,5 @@
[package] [package]
name = "macnickenson" name = "mac4nick"
version = "0.1.0" version = "0.1.0"
authors = ["Stefan Schwarz <stefan@f2o.io>"] authors = ["Stefan Schwarz <stefan@f2o.io>"]
edition = "2018" edition = "2018"

View file

@ -5,14 +5,14 @@ ADD . .
RUN apt update && apt install -y musl-tools RUN apt update && apt install -y musl-tools
RUN rustup target add x86_64-unknown-linux-musl RUN rustup target add x86_64-unknown-linux-musl
RUN cargo build --release --target x86_64-unknown-linux-musl RUN cargo build --release --target x86_64-unknown-linux-musl
RUN find /app/target -name macnickenson RUN find /app/target -name mac4nick
RUN strip /app/target/x86_64-unknown-linux-musl/release/macnickenson RUN strip /app/target/x86_64-unknown-linux-musl/release/mac4nick
# --- # ---
FROM scratch FROM scratch
WORKDIR /app/static WORKDIR /app/static
WORKDIR /app WORKDIR /app
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/macnickenson /app/macnickenson COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/mac4nick /app/mac4nick
USER 1000 USER 1000
CMD ["/app/macnickenson"] CMD ["/app/mac4nick"]

View file

@ -1,7 +1,7 @@
use anyhow::{Context, Result};
use argh::FromArgs; use argh::FromArgs;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlx::MySqlPool; use sqlx::MySqlPool;
use std::io;
use tide::sessions::{MemoryStore, SessionMiddleware}; use tide::sessions::{MemoryStore, SessionMiddleware};
mod db; mod db;
mod forms; mod forms;
@ -60,7 +60,7 @@ pub type Message = (Level, String);
pub type Request = tide::Request<State>; pub type Request = tide::Request<State>;
#[async_std::main] #[async_std::main]
async fn main() -> Result<(), io::Error> { async fn main() -> Result<()> {
let config: Config = argh::from_env(); let config: Config = argh::from_env();
if config.log { if config.log {
tide::log::start(); tide::log::start();
@ -68,7 +68,7 @@ async fn main() -> Result<(), io::Error> {
let pool = MySqlPool::connect(&config.dsn) let pool = MySqlPool::connect(&config.dsn)
.await .await
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{:?}", err)))?; .context("unable to open database connection")?;
let session_store = let session_store =
SessionMiddleware::new(MemoryStore::new(), config.session_secret.as_bytes()); SessionMiddleware::new(MemoryStore::new(), config.session_secret.as_bytes());
@ -80,6 +80,8 @@ async fn main() -> Result<(), io::Error> {
app.at("/").get(routes::index); app.at("/").get(routes::index);
app.at("/change").post(routes::change); app.at("/change").post(routes::change);
app.at("/healthz").get(routes::healthz); app.at("/healthz").get(routes::healthz);
app.at("/static").serve_dir("static/")?; app.at("/static")
app.listen(config.listen).await .serve_dir("static/")
.context("unable to open static files")?;
app.listen(config.listen).await.context("unable to listen")
} }

View file

@ -5,7 +5,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<title>macnickenson</title> <title>mac4nick</title>
</head> </head>
<body> <body>