From 77b6e2aba3e3b486f5d560a9e67c0d34ea1fca49 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:21:44 +0100 Subject: [PATCH 01/18] Testing with Jenkins --- Jenkinsfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..551d922 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent none + stage('Build') { + agent { + docker { image 'rust:alpine' } + } + steps { + sh 'export' + sh 'cargo --release build' + sh 'ls -la' + } + } +} \ No newline at end of file -- 2.45.2 From 0b7af4e3d79de8390fe27e46c7a9369843e1fe2b Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:22:46 +0100 Subject: [PATCH 02/18] Testing with Jenkins --- Jenkinsfile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 551d922..8d4520c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,15 @@ pipeline { agent none - stage('Build') { - agent { - docker { image 'rust:alpine' } - } - steps { - sh 'export' - sh 'cargo --release build' - sh 'ls -la' + stages { + stage('Build') { + agent { + docker { image 'rust:alpine' } + } + steps { + sh 'export' + sh 'cargo --release build' + sh 'ls -la' + } } } } \ No newline at end of file -- 2.45.2 From ff18cd16ceddd72e43b848a01b82be65c94a0a7a Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:40:40 +0100 Subject: [PATCH 03/18] Testing with Jenkins --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8d4520c..64baedc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,8 +6,7 @@ pipeline { docker { image 'rust:alpine' } } steps { - sh 'export' - sh 'cargo --release build' + sh 'cargo build --release' sh 'ls -la' } } -- 2.45.2 From 21b30a441fb7ceced5df86685bb59659a531a549 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:44:02 +0100 Subject: [PATCH 04/18] Testing with Jenkins --- Jenkinsfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 64baedc..b2adb9d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,8 +5,12 @@ pipeline { agent { docker { image 'rust:alpine' } } + environment { + RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' + } steps { - sh 'cargo build --release' + sh 'apk add pkgconf musl-dev curl' + sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'ls -la' } } -- 2.45.2 From c587705f5a632ddd4ae2dd03ff82196427b71f96 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:44:44 +0100 Subject: [PATCH 05/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b2adb9d..fd89c8b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' } steps { - sh 'apk add pkgconf musl-dev curl' + sh 'sudo apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'ls -la' } -- 2.45.2 From 9798dfe5cbfe31710ebed077e23dce2de3fb3cd5 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 13:02:39 +0100 Subject: [PATCH 06/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fd89c8b..b2adb9d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' } steps { - sh 'sudo apk add pkgconf musl-dev curl' + sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'ls -la' } -- 2.45.2 From 5ad952d37e1848c4e6cbe7ffe86212ce29ec98d4 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 13:47:23 +0100 Subject: [PATCH 07/18] Testing with Jenkins --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b2adb9d..394ed41 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,11 +7,13 @@ pipeline { } environment { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' + TOKEN = credentials('00912d76-da44-4f04-890f-b11180e7a68f') } steps { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' - sh 'ls -la' + sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' + sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } -- 2.45.2 From 181a2e37539c99176b87e40360cf26e44a28bca5 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:34:41 +0100 Subject: [PATCH 08/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 394ed41..8c2dc24 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { } environment { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' - TOKEN = credentials('00912d76-da44-4f04-890f-b11180e7a68f') + TOKEN = credentials('gitea-key') } steps { sh 'apk add pkgconf musl-dev curl' -- 2.45.2 From a2bdd281cc87230d9bcced28d07ae9c92ab5984e Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:36:38 +0100 Subject: [PATCH 09/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8c2dc24..7c6e781 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { } environment { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' - TOKEN = credentials('gitea-key') + TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15') } steps { sh 'apk add pkgconf musl-dev curl' -- 2.45.2 From 8461871d7a0b6e99e1e3b568478171d4355b204e Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:44:55 +0100 Subject: [PATCH 10/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7c6e781..a8f81c4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } -- 2.45.2 From 4f09a0eb81fb8a29d74ba19c1081e031cd68e379 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:59:41 +0100 Subject: [PATCH 11/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a8f81c4..32a096f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/v1/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } -- 2.45.2 From 5657c570df41f2d359dd5cb43e765a8977d407cf Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:13:29 +0100 Subject: [PATCH 12/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 32a096f..138c091 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/v1/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -s -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } -- 2.45.2 From d5abe0c38a7d9369685ec7d6dbb122a15f7d0aa6 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:21:58 +0100 Subject: [PATCH 13/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 138c091..744083b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -s -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -s -v -H "Authorization: token ${TOKEN}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } -- 2.45.2 From 6fed41de0a66b6fdd60bf0de0bdc7b588df78a69 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:36:36 +0100 Subject: [PATCH 14/18] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 744083b..14b8caf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -s -v -H "Authorization: token ${TOKEN}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } -- 2.45.2 From 577d9519fab4bfb99986b2e80bbccdd4cc6f5137 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:39:29 +0100 Subject: [PATCH 15/18] Removed gitlab CI --- .gitlab-ci.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index e875bfd..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -stages: - - build - -variables: - PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/installer" - -build: - stage: build - image: rust:alpine - rules: - - if: $CI_COMMIT_BRANCH == "installer" - script: - - apk add pkgconf musl-dev curl - - RUSTFLAGS='-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' cargo build --release --target x86_64-unknown-linux-musl - - cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64 - - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file installer-amd64 "${PACKAGE_REGISTRY_URL}/dev-$CI_COMMIT_SHA/installer-amd64"' - artifacts: - paths: - - installer-amd64 -- 2.45.2 From cb8ef1e2e80effb6e8dd367dbbe2eb76483b1a0f Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:15:09 +0100 Subject: [PATCH 16/18] Switched update to gitea --- src/main.rs | 2 +- src/repository.rs | 2 +- src/update.rs | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index f9421b9..9f23690 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ impl ToString for MainMenu { } fn main() { - if let Some(version) = option_env!("CI_COMMIT_SHA") { + if let Some(version) = option_env!("BUILD_NUMBER") { println!("Starting installer version {}", version); update::check_for_updates(version); } else { diff --git a/src/repository.rs b/src/repository.rs index 4ccfaaf..a88c68f 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -48,7 +48,7 @@ fn check_config() -> bool { fn clone_repo() -> bool { println!("Cloning repo..."); if !Path::new("repo").exists() { std::fs::create_dir("repo").unwrap(); } - git!("clone", "git@ssh.gitlab.mattv.de:root/dotfiles.git", ".").success() + git!("clone", "gitea@gitea.mattv.de:root/dotfiles.git", ".").success() && check_config() } diff --git a/src/update.rs b/src/update.rs index a20e201..263f9c7 100644 --- a/src/update.rs +++ b/src/update.rs @@ -6,27 +6,31 @@ use std::path::Path; use serde::Deserialize; #[derive(Debug, Deserialize)] -struct Pipeline { - sha: String +struct PackageEntry { + version: String } -#[derive(Debug, Deserialize)] -struct PackageEntry { - version: String, - pipeline: Pipeline -} +const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464"; pub fn check_for_updates(version: &str) { + let version: u64 = version.parse().unwrap(); print!("Checking for updates... "); - let resp: Vec = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/packages?name=installer&sort=desc").send().unwrap().json().unwrap(); - let newest = resp.first().unwrap(); - if newest.pipeline.sha != version { - println!("New version exists"); + let resp: Vec = attohttpc::get("https://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer") + .header("accept", "application/json") + .header("Authorization", format!("token {GITEA_KEY}")) + .send().unwrap().json().unwrap(); + let newest = resp.into_iter() + .map(|entry| entry.version.parse::().unwrap()) + .max().unwrap(); + if newest > version { + println!("New version {newest}"); let exe = current_exe().unwrap(); let temp = Path::new("temp"); print!("Downloading... "); - attohttpc::get(format!("https://gitlab.mattv.de/api/v4/projects/43/packages/generic/installer/{}/installer-amd64", newest.version)).send().unwrap().write_to(File::create(temp).unwrap()).unwrap(); + attohttpc::get(format!("https://gitea.mattv.de/api/packages/root/generic/installer/{newest}/installer-amd64")) + .header("Authorization", format!("token {GITEA_KEY}")) + .send().unwrap().write_to(File::create(temp).unwrap()).unwrap(); println!("Done"); fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap(); -- 2.45.2 From 60fce326dd7365a36788d7ae2f7d7828ce7091ab Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:30:26 +0100 Subject: [PATCH 17/18] Use commit for version again --- Cargo.lock | 5 +++-- Cargo.toml | 1 + Jenkinsfile | 2 +- src/main.rs | 2 +- src/update.rs | 11 ++++------- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b41dc0..2dddb2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,7 @@ dependencies = [ "dialoguer", "indicatif", "serde", + "serde_json", "toml", ] @@ -354,9 +355,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", diff --git a/Cargo.toml b/Cargo.toml index 7559aee..17f67b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" dialoguer = "0.10.3" indicatif = "0.17.3" toml = "0.6.0" +serde_json = "1.0.93" [dependencies.serde] version = "1.0.152" diff --git a/Jenkinsfile b/Jenkinsfile index 14b8caf..3c49e99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${GIT_COMMIT}/installer-amd64' } } } diff --git a/src/main.rs b/src/main.rs index 9f23690..7592212 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ impl ToString for MainMenu { } fn main() { - if let Some(version) = option_env!("BUILD_NUMBER") { + if let Some(version) = option_env!("GIT_COMMIT") { println!("Starting installer version {}", version); update::check_for_updates(version); } else { diff --git a/src/update.rs b/src/update.rs index 263f9c7..5fa13cc 100644 --- a/src/update.rs +++ b/src/update.rs @@ -10,19 +10,16 @@ struct PackageEntry { version: String } -const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464"; +const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802"; pub fn check_for_updates(version: &str) { - let version: u64 = version.parse().unwrap(); print!("Checking for updates... "); - let resp: Vec = attohttpc::get("https://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer") + let resp: serde_json::Value = attohttpc::get("https://gitea.mattv.de/api/v1/repos/root/dotfiles/branches/installer") .header("accept", "application/json") .header("Authorization", format!("token {GITEA_KEY}")) .send().unwrap().json().unwrap(); - let newest = resp.into_iter() - .map(|entry| entry.version.parse::().unwrap()) - .max().unwrap(); - if newest > version { + let newest = resp["commit"]["id"].as_str().unwrap(); + if newest != version { println!("New version {newest}"); let exe = current_exe().unwrap(); let temp = Path::new("temp"); -- 2.45.2 From 1c235d1949aec8a30cd1f11f365026941f8f2bc4 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:32:30 +0100 Subject: [PATCH 18/18] Fixed warnings --- src/update.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/update.rs b/src/update.rs index 5fa13cc..73417b5 100644 --- a/src/update.rs +++ b/src/update.rs @@ -3,12 +3,6 @@ use std::fs; use std::fs::File; use std::os::unix::process::CommandExt; use std::path::Path; -use serde::Deserialize; - -#[derive(Debug, Deserialize)] -struct PackageEntry { - version: String -} const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802"; -- 2.45.2