Remove the logger (for the moment) and update the deployment script.
This commit is contained in:
parent
d83b56c642
commit
dcf7523ccf
5 changed files with 258 additions and 288 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
target
|
target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
backend/data/recipes.sqlite
|
backend/data/recipes.sqlite
|
||||||
|
/deploy-to-pi.ps1
|
||||||
|
|
|
||||||
483
Cargo.lock
generated
483
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -13,10 +13,9 @@ serde = { version = "1.0", features = ["derive"] }
|
||||||
listenfd = "0.3" # To watch file modifications and automatically launch a build process (only used in dev/debug).
|
listenfd = "0.3" # To watch file modifications and automatically launch a build process (only used in dev/debug).
|
||||||
ron = "0.5" # Rust object notation, to load configuration files.
|
ron = "0.5" # Rust object notation, to load configuration files.
|
||||||
itertools = "0.9"
|
itertools = "0.9"
|
||||||
env_logger = "0.7"
|
|
||||||
|
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
|
|
||||||
[dependencies.rusqlite]
|
[dependencies.rusqlite]
|
||||||
version = "0.22"
|
version = "0.23"
|
||||||
features = ["bundled"]
|
features = ["bundled"]
|
||||||
|
|
@ -2,13 +2,12 @@ use std::io::prelude::*;
|
||||||
use std::{fs::File, env::args};
|
use std::{fs::File, env::args};
|
||||||
|
|
||||||
use actix_files as fs;
|
use actix_files as fs;
|
||||||
use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpResponse, web::Query, middleware::Logger};
|
use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpResponse, web::Query};
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use listenfd::ListenFd;
|
use listenfd::ListenFd;
|
||||||
use ron::de::from_reader;
|
use ron::de::from_reader;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use env_logger;
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
|
@ -28,7 +27,7 @@ pub struct Request {
|
||||||
|
|
||||||
fn main_page(query: Query<Request>) -> HttpResponse {
|
fn main_page(query: Query<Request>) -> HttpResponse {
|
||||||
|
|
||||||
let main_template = MainTemplate { test: &"*** test ***" };
|
let main_template = MainTemplate { test: &"*** test 2 ***" };
|
||||||
|
|
||||||
let s = main_template.render().unwrap();
|
let s = main_template.render().unwrap();
|
||||||
HttpResponse::Ok().content_type("text/html").body(s)
|
HttpResponse::Ok().content_type("text/html").body(s)
|
||||||
|
|
@ -64,7 +63,6 @@ async fn main() -> std::io::Result<()> {
|
||||||
// let database_connection = db::create_or_update();
|
// let database_connection = db::create_or_update();
|
||||||
|
|
||||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
std::env::set_var("RUST_LOG", "actix_web=info");
|
||||||
env_logger::init();
|
|
||||||
|
|
||||||
let mut listenfd = ListenFd::from_env();
|
let mut listenfd = ListenFd::from_env();
|
||||||
let mut server =
|
let mut server =
|
||||||
|
|
@ -72,8 +70,6 @@ async fn main() -> std::io::Result<()> {
|
||||||
|| {
|
|| {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.wrap(Logger::default())
|
|
||||||
.wrap(Logger::new("%a %{User-Agent}i"))
|
|
||||||
.service(web::resource("/").to(main_page))
|
.service(web::resource("/").to(main_page))
|
||||||
.service(fs::Files::new("/static", "static").show_files_listing())
|
.service(fs::Files::new("/static", "static").show_files_listing())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
49
deploy.ps1
49
deploy.ps1
|
|
@ -1,28 +1,43 @@
|
||||||
if ($args.Count -lt 1) {
|
# TODO:
|
||||||
|
# * copy the conf if it doesn't exist
|
||||||
|
# * create the destination directory if doesn't exist
|
||||||
|
|
||||||
|
if ($args.Count -lt 3) {
|
||||||
$scriptName = [Environment]::GetCommandLineArgs()[1]
|
$scriptName = [Environment]::GetCommandLineArgs()[1]
|
||||||
echo "Usage: $scriptName <destination>"
|
Write-Output "Usage: $scriptName <address: string> <remote director: string> <key file: openssh format>"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
cargo build --release
|
$address=$args[0]
|
||||||
|
$destination=$args[1]
|
||||||
|
$ssh_key=$args[2]
|
||||||
|
|
||||||
systemctl --user stop www-recipes.service
|
$ssh_command = "ssh -i $ssh_key $address"
|
||||||
|
$scp_command = "scp -r -i $ssh_key"
|
||||||
|
|
||||||
$destination=$args[0]
|
function Invoke-SSH([string]$command)
|
||||||
|
{
|
||||||
if (!(Test-Path -Path $destination)) {
|
$expression = "$ssh_command $command"
|
||||||
New-Item -ItemType directory -Path $destination
|
Write-Output "Executing: $expression"
|
||||||
|
Invoke-Expression $expression | Write-Output
|
||||||
}
|
}
|
||||||
|
|
||||||
strip target/release/recipes
|
function Copy-SSH([string]$source, [string]$destination)
|
||||||
Copy-Item target/release/recipes -Destination $destination
|
{
|
||||||
|
$expression = "$scp_command $source ${address}:$destination"
|
||||||
Copy-Item backend/static -Destination $destination -Recurse -Force
|
Write-Output "Executing: $expression"
|
||||||
|
Invoke-Expression $expression
|
||||||
# Do not overwrite the configuration.
|
|
||||||
if (!(Test-Path -Path $destination/conf.ron)) {
|
|
||||||
Copy-Item backend/conf.ron -Destination $destination
|
|
||||||
}
|
}
|
||||||
|
|
||||||
systemctl --user start www-recipes.service
|
cargo build --target arm-unknown-linux-gnueabihf --release
|
||||||
|
|
||||||
|
# $a = Invoke-Expression ($ssh_command + "ls")
|
||||||
|
Invoke-SSH("sudo systemctl stop recipes")
|
||||||
|
|
||||||
|
Copy-SSH -source "./target/arm-unknown-linux-gnueabihf/release/recipes" -destination "~/recipes/"
|
||||||
|
Copy-SSH -source "./backend/static/" -destination "~/recipes/"
|
||||||
|
|
||||||
|
Invoke-SSH("chmod u+x recipes/recipes")
|
||||||
|
Invoke-SSH("sudo systemctl start recipes")
|
||||||
|
|
||||||
|
Write-Output "Deployment finished"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue