Make build pipeline do cargo build
This commit is contained in:
parent
a985279db3
commit
dd6cd293ca
7
.ci/build
Executable file
7
.ci/build
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
cd blastmud-repo
|
||||||
|
echo Running tests
|
||||||
|
cargo test --target-dir ../target --profile release-with-debug
|
||||||
|
cargo build --target-dir ../target --profile release-with-debug
|
@ -11,8 +11,14 @@ jobs:
|
|||||||
type: registry-image
|
type: registry-image
|
||||||
source:
|
source:
|
||||||
repository: rust
|
repository: rust
|
||||||
|
inputs:
|
||||||
|
- blastmud-repo
|
||||||
|
caches:
|
||||||
|
- target
|
||||||
|
outputs:
|
||||||
|
- target
|
||||||
run:
|
run:
|
||||||
path: echo
|
path: blastmud-repo/.ci/build
|
||||||
args: ["Hello", "world!"]
|
args: ["Hello", "world!"]
|
||||||
resources:
|
resources:
|
||||||
- name: blastmud-repo
|
- name: blastmud-repo
|
||||||
@ -22,4 +28,3 @@ resources:
|
|||||||
source:
|
source:
|
||||||
uri: https://git.blastmud.org/blasthavers/blastmud.git
|
uri: https://git.blastmud.org/blasthavers/blastmud.git
|
||||||
branch: main
|
branch: main
|
||||||
|
|
||||||
|
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -188,6 +188,7 @@ dependencies = [
|
|||||||
"blastmud_interfaces",
|
"blastmud_interfaces",
|
||||||
"futures",
|
"futures",
|
||||||
"log",
|
"log",
|
||||||
|
"nix",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
@ -1038,9 +1039,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.26.1"
|
version = "0.26.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694"
|
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
|||||||
blastmud_interfaces = { path = "../blastmud_interfaces" }
|
blastmud_interfaces = { path = "../blastmud_interfaces" }
|
||||||
futures = "0.3.25"
|
futures = "0.3.25"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
|
nix = "0.26.2"
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
serde = { version = "1.0.149", features = ["derive", "serde_derive"] }
|
serde = { version = "1.0.149", features = ["derive", "serde_derive"] }
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
use std::path::Path;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
@ -24,12 +25,14 @@ use warp::{
|
|||||||
self, filters::ws, Filter, Reply
|
self, filters::ws, Filter, Reply
|
||||||
};
|
};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
use nix::{sys::signal::{kill, Signal}, unistd::Pid};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct Config {
|
struct Config {
|
||||||
listeners: Vec<String>,
|
listeners: Vec<String>,
|
||||||
ws_listener: String,
|
ws_listener: String,
|
||||||
gameserver: String,
|
gameserver: String,
|
||||||
|
pidfile: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
type DResult<A> = Result<A, Box<dyn Error + Send + Sync>>;
|
type DResult<A> = Result<A, Box<dyn Error + Send + Sync>>;
|
||||||
@ -637,14 +640,51 @@ async fn start_websocket(bind: String, active_sessions: SessionMap, server_sende
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn replace_old_listener(pidfile: &str) -> DResult<()> {
|
||||||
|
match fs::read_to_string(pidfile) {
|
||||||
|
Err(e) =>
|
||||||
|
if e.kind() == std::io::ErrorKind::NotFound {
|
||||||
|
info!("pidfile not found, assuming not already running");
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
info!("Error reading pidfile (other than NotFound): {}", e);
|
||||||
|
Err(Box::new(e) as Box::<dyn Error + Send + Sync>)
|
||||||
|
}
|
||||||
|
Ok(f) => {
|
||||||
|
let pid: Pid = Pid::from_raw(f.parse().map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)?);
|
||||||
|
match fs::read_to_string(format!("/proc/{}/cmdline", pid)) {
|
||||||
|
Ok(content) =>
|
||||||
|
if content.contains("blastmud_listener") {
|
||||||
|
info!("pid in pidfile references blastmud_listener; starting cutover");
|
||||||
|
kill(pid, Signal::SIGTERM)
|
||||||
|
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
|
||||||
|
} else {
|
||||||
|
info!("Pid in pidfile is for process not including blastmud_listener - ignoring pidfile");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
info!("Pid in pidfile is gone - ignoring pidfile");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
info!("Writing new pidfile");
|
||||||
|
fs::write(Path::new(pidfile), format!("{}", std::process::id()))
|
||||||
|
.map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
|
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
|
||||||
|
|
||||||
|
|
||||||
let listener_id = Uuid::new_v4();
|
let listener_id = Uuid::new_v4();
|
||||||
let mut config = read_latest_config()?;
|
let mut config = read_latest_config()?;
|
||||||
let active_sessions: SessionMap =
|
let active_sessions: SessionMap =
|
||||||
Arc::new(Mutex::new(SessionIndexes { by_uuid: BTreeMap::new(), count_by_source: BTreeMap::new() }));
|
Arc::new(Mutex::new(SessionIndexes { by_uuid: BTreeMap::new(), count_by_source: BTreeMap::new() }));
|
||||||
|
replace_old_listener(&config.pidfile)?;
|
||||||
let server_sender = start_server_task(listener_id, config.gameserver, active_sessions.clone());
|
let server_sender = start_server_task(listener_id, config.gameserver, active_sessions.clone());
|
||||||
|
|
||||||
start_pinger(listener_id, server_sender.clone());
|
start_pinger(listener_id, server_sender.clone());
|
||||||
|
18
scripts/run-latest
Normal file
18
scripts/run-latest
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Note: This script runs /app/exe/* at startup, and then any files moved into /app/exe/
|
||||||
|
# (note - create files elsewhere and move them to avoid race conditions).
|
||||||
|
# This allows deployments to work from a different Docker container by simply pushing
|
||||||
|
# into a volume mounted in the correct place.
|
||||||
|
# Remove the old file from /app/exe/ before moving the new one.
|
||||||
|
# It doesn't kill off the old process, instead the new one kills the old one.
|
||||||
|
|
||||||
|
for EXE in /app/exe/*; do
|
||||||
|
"$EXE"&
|
||||||
|
done
|
||||||
|
|
||||||
|
inotifywait --quiet --monitor -e moved_to --format "%f" /app/exe |\
|
||||||
|
while read MOVED
|
||||||
|
do
|
||||||
|
"/app/exe/$MOVED"&
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user