From 06b403ead5f1de1e103b15e3b63abc876abd2f18 Mon Sep 17 00:00:00 2001 From: Tip ten Brink <75669206+tiptenbrink@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:34:40 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + Cargo.lock | 354 ++++++++++++++++++++++++++++++++ Cargo.toml | 9 + src/main.rs | 334 ++++++++++++++++++++++++++++++ staging_v2.1.tar.gz | Bin 0 -> 1928 bytes staging_v2.1/docker-compose.yml | 81 ++++++++ staging_v2.1/entrypoint.sh | 5 + staging_v2.1/secrets.sh | 2 + staging_v2.1/staging.env | 34 +++ 9 files changed, 820 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs create mode 100644 staging_v2.1.tar.gz create mode 100644 staging_v2.1/docker-compose.yml create mode 100755 staging_v2.1/entrypoint.sh create mode 100755 staging_v2.1/secrets.sh create mode 100644 staging_v2.1/staging.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..5f9cad2 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,354 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "clap" +version = "4.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "dploy" +version = "0.1.0" +dependencies = [ + "clap", + "keyring", + "rpassword", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "keyring" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec6488afbd1d8202dbd6e2dd38c0753d8c0adba9ac9985fc6f732a0d551f75e1" +dependencies = [ + "byteorder", + "lazy_static", + "linux-keyutils", + "security-framework", + "winapi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "linux-keyutils" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f27bb67f6dd1d0bb5ab582868e4f65052e58da6401188a08f0da09cf512b84b" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rpassword" +version = "7.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80472be3c897911d0137b2d2b9055faf6eeac5b14e324073d83bc17b191d7e3f" +dependencies = [ + "libc", + "rtoolbox", + "windows-sys", +] + +[[package]] +name = "rtoolbox" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c247d24e63230cdb56463ae328478bd5eac8b8faa8c69461a77e8e323afac90e" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4b5b394 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "dploy" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = { version = "4.4.10", features = ["derive"] } +keyring = { version = "2.1.0", default-features = false, features=[ "linux-no-secret-service" ] } +rpassword = "7.3.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..bbff84c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,334 @@ +#![allow(dead_code, unused_variables)] + +use clap::{Parser, ValueEnum, Subcommand}; +use rpassword::prompt_password; +use keyring::{Entry, Result as KeyringResult, Error as KeyringError, Error::NoEntry}; +use std::process::{Command as Cmd, Output}; + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] +enum Environment { + /// Local development environment + Localdev, + /// Staging environment + Staging, + /// Production environment + Production +} + +impl Environment { + fn to_string(self: Self) -> &'static str { + match self { + Self::Localdev => "localdev", + Self::Staging => "staging", + Self::Production => "production" + } + } +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] +enum Stage { + /// Download stage + Download, + /// Deploy stage + Deploy, +} + +impl Stage { + fn to_string(self: Self) -> &'static str { + match self { + Self::Download => "download", + Self::Deploy => "deploy" + } + } +} + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None, args_conflicts_with_subcommands(true))] +struct Args { + /// Environment + #[arg(value_enum, required = true)] + env: Option, + + /// Version or tag to deploy + #[arg(id = "version_tag", default_value = "latest")] + tag: Option, + + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand, Debug)] +enum Commands { + /// Download tag or version with specific env + Download { + /// Environment + #[arg(value_enum)] + env: Environment, + + /// Version or tag to download + #[arg(id = "version_tag", default_value = "latest")] + tag: String, + }, + + /// Download tag or version with specific env + Deploy { + /// Environment + #[arg(value_enum)] + env: Environment, + + /// Version or tag to deploy + #[arg(id = "version_tag", default_value = "latest")] + tag: String, + }, + + /// Save authentication details for specific stage until reboot + Auth { + #[arg(value_enum)] + stage: Stage + }, +} + +static TMP_DIR: &str = "/tmp/ti_dploy"; + +fn get_password() -> KeyringResult> { + let entry = Entry::new("ti_dploy", "default")?; + match entry.get_password() { + Ok(pw) => Ok(Some(pw)), + Err(NoEntry) => Ok(None), + Err(err) => Err(err), + } +} + +fn set_password(password: &str, stage: &str) -> KeyringResult<()> { + let entry = Entry::new("ti_dploy", stage)?; + entry.set_password(password)?; + Ok(()) +} + +fn env_tag_name(env: &str, tag: &str) -> String { + format!("{}_{}", env, tag) +} + +fn location(env: &str, tag: &str) -> String { + let env_tag_name = env_tag_name(env, tag); + + format!("{}/{}", TMP_DIR, env_tag_name) +} + +fn download_release(repo: &str, env: &str, tag: &str) -> () { + let output = Cmd::new("gh") + .arg("release") + .arg("download") + .arg(tag) + .arg("-R") + .arg(repo) + .arg("-p") + .arg(env) + .output().unwrap(); +} + +fn make_archive(source_dir_parent: &str, source_dir: &str, env: &str, tag: &str) -> () { + mk_tmp_dir(); + + let archives_dir = format!("{}/archives", TMP_DIR); + let mk_tmp_dir = Cmd::new("mkdir") + .arg("-p") + .arg(&archives_dir) + .output().unwrap(); + let archive_name = format!("{}.tar.gz", env_tag_name(env, tag)); + + let archive_loc = format!("{}/{}", &archives_dir, &archive_name); + + let remove_existing = Cmd::new("rm") + .arg(&archive_loc) + .output().unwrap(); + + let mut output_archive_prog = Cmd::new("tar"); + let output_archive = output_archive_prog + .current_dir(source_dir_parent) + .arg("-czf") + .arg(archive_loc) + .arg(source_dir); + println!("{:?}", output_archive); + output_archive.output().unwrap(); +} + +fn download_tag(repo_url: &str, env: &str, tag: &str) -> () { + let loc_str = location(env, tag); + let repo_loc = format!("{}_repo", loc_str); + + let mk_tmp_dir = Cmd::new("mkdir") + .arg("-p") + .arg(TMP_DIR) + .output().unwrap(); + + let remove_existing = Cmd::new("rm") + .arg("-rf") + .arg(&repo_loc) + .output().unwrap(); + + let repo_clone = Cmd::new("git") + .arg("clone") + .arg("--filter=tree:0") + .arg(repo_url) + .arg(&repo_loc) + .output().unwrap(); + + let checkout = Cmd::new("git") + .current_dir(&repo_loc) + .arg("checkout") + .arg(tag) + .output().unwrap(); + + let use_dir = format!("{}/use", repo_loc); + + make_archive(&use_dir, env, env, tag); +} + + +fn move_to_archives(env: &str, tag: &str) -> () { + mk_tmp_dir(); + + let archives_dir = format!("{}/archives", TMP_DIR); + let mk_tmp_dir = Cmd::new("mkdir") + .arg("-p") + .arg(&archives_dir) + .output().unwrap(); + + let env_tag = env_tag_name(env, tag); + let archive_name = format!("{}.tar.gz", &env_tag); + + let archive_loc = format!("{}/{}", &archives_dir, &archive_name); + + let remove_existing = Cmd::new("rm") + .arg(&archive_loc) + .output().unwrap(); + + + let move_archive = Cmd::new("mv") + .arg(format!("./{}", &archive_name)) + .arg(&archive_loc) + .output().unwrap(); +} + +fn mk_tmp_dir() -> () { + let mk_tmp_dir = Cmd::new("mkdir") + .arg("-p") + .arg(TMP_DIR) + .output().unwrap(); +} + +fn extract(env: &str, tag: &str) -> () { + let archives_dir = format!("{}/archives", TMP_DIR); + let env_tag = env_tag_name(env, tag); + let archive_name = format!("{}.tar.gz", &env_tag); + + let archive_loc = format!("{}/{}", &archives_dir, &archive_name); + let target_dir = format!("{}/{}", TMP_DIR, env_tag); + + let remove_existing = Cmd::new("rm") + .arg("-rf") + .arg(&target_dir) + .output().unwrap(); + + let mk_tmp_dir = Cmd::new("mkdir") + .arg("-p") + .arg(&target_dir) + .output().unwrap(); + + let mut tar_prog = Cmd::new("tar"); + //tar -xzf /tmp/ti_dploy/archives/staging_b648930.tar.gz -C ./staging_b648930 --strip-components 1 + // strip components might not work on every platform + let tar_prog = tar_prog.arg("-xzf") + .arg(archive_loc) + .current_dir(TMP_DIR) + .arg("-C") + .arg(env_tag) + .arg("--strip-components") + .arg("1"); + + println!("{:?}", tar_prog); + + tar_prog.output().unwrap(); + () +} + +#[derive(Debug)] +enum Error { + NoPassword, + KeyringError(KeyringError) +} + +fn add_password_maybe(env: Environment, cmd: &mut Cmd) -> Result<&mut Cmd, Error> { + match env { + Environment::Localdev => Ok(cmd), + Environment::Staging | Environment::Production => { + match get_password() { + Ok(Some(password)) => Ok(cmd.env("TI_DPLOY_SECRET", password)), + Ok(None) => Err(Error::NoPassword), + Err(e) => Err(Error::KeyringError(e)) + } + } + } +} + +fn show_cmd_result(output: &Output) { + println!("{}", output.status); + println!("{}", String::from_utf8(output.stderr.clone()).unwrap()); + println!("{}", String::from_utf8(output.stdout.clone()).unwrap()); +} + +fn main() { + let args = Args::parse(); + + let repo = "DSAV-Dodeka/dodeka"; + let repo_url = "https://github.com/DSAV-Dodeka/dodeka.git"; + + println!("{:?}", args); + + match args.command { + Some(Commands::Auth { stage }) => { + let password = prompt_password("Enter password:\n").unwrap(); + set_password(&password, stage.to_string()).unwrap(); + println!("Set password!"); + return () + }, + Some(Commands::Download { env, tag }) => { + let env_str = env.to_string(); + let tag = "b648930"; + download_tag(repo_url, env_str, tag); + //TODO download step + extract(env_str, &tag); + + return () + }, + Some(Commands::Deploy { env, tag }) => { + + let env_str = env.to_string(); + + extract(env_str, &tag); + + let loc_str = location(env_str, &tag); + + let mut run_secrets = Cmd::new(format!("{}/{}", loc_str, "secrets.sh")); + let pw_cmd = add_password_maybe(env, &mut run_secrets); + if pw_cmd.as_ref().is_err_and(|e| matches!(e, Error::NoPassword)) { + println!("Set password using `dploy auth`!"); + return () + } + let run_secrets = pw_cmd.unwrap(); + + let secrets_output = run_secrets.output().unwrap(); + show_cmd_result(&secrets_output); + + // let entrypoint_output = Cmd::new(format!("{}/{}", location, "entrypoint.sh")) + // .output().unwrap(); + + // show_cmd_result(&entrypoint_output); + } + None => {} + } + + +} diff --git a/staging_v2.1.tar.gz b/staging_v2.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..c36d1deed6d3d034a930d7d6931ca9e3f918c4f4 GIT binary patch literal 1928 zcmV;32Y2`%iwFP!000001MOK`ZzD++4%!!F3H|}%kc`A4jU8WOVa1V5;?0De8ArBv z(F&nf*^S=0RowS-s{5M;*8m_C?8h9n_RGZPW@~O&gIxE*;vI3XSSnO$}=}w3;WV9Sw)`3HJ^6KM7 z-=v!Ny?6aid3|UWBJr89( zH1|O*Sj1hFU*B>b;JF+YQfXj;YdWcbhNh*btn75eX>x+mqzE<(ke(-R&pM}>u3fIQ z2$&W!09Qn)Xc?`}QbOYeGU;;`D06H=c4HehMO!K{LB3~^^oyL)ximm0R5IF|;i3cp zWpJg-Z&=x#lQ<9#Co?I2DUxSix%fXY3^p0tY*vFG& zvYDZtBil(uxxT#UjeFhi5x}e(jK-HZ?OgXpqu&jN7k6jA8uf>zyeU|yAe51|tQ8eb z)vpXaweTIH(SdsF z#5Y3`r*x@1z`R?wQl%prTyW;;#dN`^Hyt}dP2*Awz;Nye6>;XSpd5l_HeDkEjmd*~ z9cWZlHjE%N5|jd3*_b)k33((WI$15h+)ib*>bW^Bd@f^ccL3Zh?@32D%TG&3S)Tdw z>nz9Mb1}#4^vPlW;%dv)?iwFS6^y^>TjQTJ+P^;BX&F=ts)I-O$ZIG61DSKO+Q?Ln z3^ESgN&0xR{Imp(0foxSl$Z3klk~Hv3=A`}4d#qHX(7uPXpUr2(VE$ccfG5(n>FWy zclg&yhjMiK-)t6b9*bm#gvWd1zB$Q0uAey%C59=uV}8uKWV8N^`6v-y_{1$ktIuSF zG9sb{BO#ul$Thf+GUHKrbKA!SQ=rUU90ER)2COH1&=GT}o0pyX6^o85CeH+zXK1iI zXPRTY-4}zz;dR896EyLxR<`j~aEUpF
>N$`K+{g3TbFdaVT84uKd^?I|hRsWe+g8TaK8CsG% z$mF)%NxW0tbJfP=*=`(BkYtx_iO3`cQQ@wkh%o~uveTl;OiR49UxTRd3MOWp4bb;K z*ePTppbAsV3cN`Ijsiqb;=&+Jub@&M9(8N=cBP7cYNb46&JAzhV7aM81dIR*+&Hvo zLBi#m^CAA0Ht?=HUrg~5kjJiK%d*XN$9TyJ0-Xu+AtIO>6(-tJ1_isDJow_uqKmpq z(D6a3^TqQ{$uZUGIbJoph0kj3RQP=H(xq~sw7J7=e$C3#R0~L6#u4W0R8z#Jxx$du zJJsus3a@*dUP`5WIl38lsA5fJ`J-2%eyLFNb?wShDGyh7s>DL;QW3_!yz#e@T9<&@ z#sOy1^W?38O$bc_sX>K&DrN$y&>M~fRv@3*I4YijnnohjRQ8o&8{L}0yCwC}-O}eM zhk$cyEX;lB6#0X0h5H{fd9(^8hSj5f0($8CPorJmzWbs{I-8SHpsJk`0*nam?EfbUj44ug;xhyq$k_+fHm7@OD6{bxOxAuW4m1e$)^V> zml1xH?fcgZl;UvmZUQST55m~--1 by default + db: + container_name: "db${DEPLOY_NAME:-}" + profiles: [ "data", "all" ] + # Docker image that it will set up + image: "${DB_APP_IMAGE}:${DB_VERSION}" + # A volume is basically a file system shared between the host and the container + volumes: + # : + # This means the volume will be accessible from the container in the dest. directory in the container + - dodeka-db-volume:${DB_RESOURCES_TARGET} + command: -c config_file=${DB_CONF_FILE} + # Some environment variables depend on deployment variables, so we load those in manually + environment: + - PGDATA=${DB_RESOURCES_TARGET} + - POSTGRES_PASSWORD + - POSTGRES_USER + # This maps ports, so the container port will be available at localhost: + ports: + - "${DB_HOST_HOST}:${DB_HOST_PORT}:3141" + # Shared memory size, defaults to 64m which can cause problems (apparently) + shm_size: 256m + restart: always +# healthcheck: +# test: "pg_isready -p 3141" +# interval: 30s +# retries: 5 +# start_period: 10s +# start_interval: 2s +# timeout: 10s + kv: + container_name: "kv${DEPLOY_NAME:-}" + profiles: [ "data", "all" ] + image: "${KV_IMAGE}:${KV_VERSION}" + environment: + - REDIS_PASSWORD + ports: + - "${KV_HOST_HOST}:${KV_HOST_PORT}:6379" + restart: always + server: + container_name: "server${DEPLOY_NAME:-}" + profiles: [ "all" ] + depends_on: + - db + - kv + # Docker image that it will set up + image: "${SERVER_IMAGE}:${SERVER_VERSION}" + # Some environment variables depend on deployment variables, so we load those in manually + environment: + - DB_PASS=${POSTGRES_PASSWORD} + - KV_PASS=${REDIS_PASSWORD} + - MAIL_PASS=${COMCOM_MAIL_PASS} + - KEY_PASS=${KEY_PASSWORD} + - RECREATE=${RECREATE} + # This maps ports, so the container port will be available at localhost: + ports: + - "${SERVER_HOST_HOST}:${SERVER_HOST_PORT}:4241" + # Shared memory size, defaults to 64m which can cause problems (apparently) + shm_size: 256m + # This important for being able to send email when email has same ip as host + extra_hosts: + - "host.docker.internal:host-gateway" + restart: always + # Prevent too large core dumps + ulimits: + core: + soft: 0 + hard: 0 +volumes: + # This name should correspond to the volume mentioned in volumes above + dodeka-db-volume: + # A local directory + driver: local + name: dodeka-db-volume-staging +networks: + # Set up a network so that other containers on this network can access each other + # A different container on this network can access this container by using the container name as the hostname + # So localhost:3000 is exposed to other containers as :3000 + default: + name: ${NETWORK_NAME} \ No newline at end of file diff --git a/staging_v2.1/entrypoint.sh b/staging_v2.1/entrypoint.sh new file mode 100755 index 0000000..454e570 --- /dev/null +++ b/staging_v2.1/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh +export COMPOSE_PROJECT_NAME="{{ main.project }}${DEPLOY_NAME}" +export NETWORK_NAME="{{ main.docker_net_name }}${DEPLOY_NAME}" +docker compose --env-file staging.env --profile all pull +docker compose --env-file staging.env --profile all up -d \ No newline at end of file diff --git a/staging_v2.1/secrets.sh b/staging_v2.1/secrets.sh new file mode 100755 index 0000000..9eeb065 --- /dev/null +++ b/staging_v2.1/secrets.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo $TI_DPLOY_SECRET \ No newline at end of file diff --git a/staging_v2.1/staging.env b/staging_v2.1/staging.env new file mode 100644 index 0000000..929f922 --- /dev/null +++ b/staging_v2.1/staging.env @@ -0,0 +1,34 @@ +# This .env file contains environment variables used during deployment +# The host port will be the port that the host will open, i.e. what nginx will connect to. Hostname defined by HOST_HOST +KV_HOST_HOST=127.0.0.1 +DB_HOST_HOST=127.0.0.1 +SERVER_HOST_HOST=127.0.0.1 + +# The tag to upload to GHCR to +KV_IMAGE=ghcr.io/dsav-dodeka/redis +# Docker tag version +KV_VERSION=staging +# The host port will be the port that the host will open, i.e. what nginx will connect to. Hostname defined by HOST_HOST +KV_HOST_PORT=6379 + +# The tag to upload to GHCR to +DB_APP_IMAGE=ghcr.io/dsav-dodeka/postgres +# Docker tag version +DB_VERSION=staging +DB_HOST_PORT=3141 +# This is the directory that the resources will be loaded into in the container +DB_RESOURCES_TARGET=/dodeka-db +DB_CONF_FILE=/dodeka_conf/postgresql.conf +POSTGRES_USER=dodeka + +SERVER_IMAGE=ghcr.io/dsav-dodeka/server +SERVER_VERSION=staging +# The host port will be the port that the host will open, i.e. what nginx will connect to. Hostname defined by HOST_HOST +SERVER_HOST_PORT=4241 + +# The following are not specified and should be specified in a script: +# - COMCOM_MAIL_PASS +# - POSTGRES_PASSWORD +# - REDIS_PASSWORD +# - KEY_PASSWORD +# - RECREATE \ No newline at end of file