From 7546612d12f2b47e086f87bc72772a3ec93f3039 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 16:57:21 -0400 Subject: [PATCH 01/11] hopefully ready for release --- Jenkinsfile | 89 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d30c17e..499fa58 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,11 @@ pipeline { agent any - + environment { + linuxServiceAccount=credentials("a83b97d0-dbc6-42d9-96c9-f07a7f2dfab5") + linuxServiceAccountID="3ca1be00-3d9f-42a1-bab2-48a4d7b99fb0" + database_connectionString=credentials("e0e068dd-57e4-4e2b-b6b2-9d9f0d21adeb") + targetHost="alloces.lan" + } stages { stage('clean old'){ steps{ @@ -10,16 +15,88 @@ pipeline { stage('Build') { steps { sh 'dotnet publish vassago.csproj --configuration Release --os linux' - archiveArtifacts artifacts: 'bin/Release/net7.0/linux-x64/publish/*' + archiveArtifacts artifacts: 'bin/Release/net9.0/linux-x64/publish/*' } } - stage('Deploy'){ - when{ + stage ('upload') { + when { + //now my CI/CD is no longer continuous, it's just... automatic. + //(which is what I actually want tbh) + //but that does mean I have to put this condition in every single branch branch "release" } steps{ - + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf temp_deploy & mkdir -p temp_deploy' + scp -i \"${PK}\" -r dist ${linuxServiceAccount_USR}@${env.targetHost}:temp_deploy + """ + } } } + stage ('stop') + { + when { + branch "release" + } + steps{ + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop test274' + """ + } + } + } + stage ('update db') + { + when { + branch "release" + } + steps{ + //TODO: backup database + sh """#!/bin/bash + """ + + sh """#!/bin/bash + dotnet ef database update --connection "${env.database_connectionString}" + """ + //TODO: if updating the db fails, restore the old one + sh """#!/bin/bash + """ + } + } + stage ('replace') + { + when { + branch "release" + } + steps{ + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv dist/appsettings.json appsettings.json' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && mv temp_deploy/ dist/' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv appsettings.json dist/appsettings.json' + """ + } + } + } + stage ('spin up') + { + when { + branch "release" + } + steps{ + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user start test274' + """ + } + } + } + } -} \ No newline at end of file +} From b4b0fd155b352af4e991fdc58ae8d8325ee83acd Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:00:09 -0400 Subject: [PATCH 02/11] fix cred strings --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 499fa58..4ebc992 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { linuxServiceAccount=credentials("a83b97d0-dbc6-42d9-96c9-f07a7f2dfab5") linuxServiceAccountID="3ca1be00-3d9f-42a1-bab2-48a4d7b99fb0" - database_connectionString=credentials("e0e068dd-57e4-4e2b-b6b2-9d9f0d21adeb") + database_connectionString=credentials("7ab58922-c647-42e5-ae15-84faa0c1ee7d") targetHost="alloces.lan" } stages { From 33f55dc7904f7f3d51e122bef6e80e5e3750d46a Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:02:05 -0400 Subject: [PATCH 03/11] .net 8 --- Jenkinsfile | 2 +- vassago.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ebc992..3bd225d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { stage('Build') { steps { sh 'dotnet publish vassago.csproj --configuration Release --os linux' - archiveArtifacts artifacts: 'bin/Release/net9.0/linux-x64/publish/*' + archiveArtifacts artifacts: 'bin/Release/net8.0/linux-x64/publish/*' } } stage ('upload') { diff --git a/vassago.csproj b/vassago.csproj index 3c3c5ba..dae7d44 100644 --- a/vassago.csproj +++ b/vassago.csproj @@ -1,7 +1,7 @@ - net9.0 + net8.0 enable $(NoWarn);CA2254 From 246a6e20199cc50b0e258e3ddbba7751b230ff22 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:12:38 -0400 Subject: [PATCH 04/11] .toarray for .net8 --- ConsoleService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConsoleService.cs b/ConsoleService.cs index 1a568a3..25e7244 100644 --- a/ConsoleService.cs +++ b/ConsoleService.cs @@ -42,7 +42,7 @@ namespace vassago ProtocolInterfaces.ProtocolList.twitchs.Add(t); } - Task.WaitAll(initTasks, cancellationToken); + Task.WaitAll(initTasks.ToArray(), cancellationToken); } public Task StopAsync(CancellationToken cancellationToken) From 09f439188a385fbd944153e4b6b0375494e26004 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:15:02 -0400 Subject: [PATCH 05/11] build to dist? --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3bd225d..179f854 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,8 +14,8 @@ pipeline { } stage('Build') { steps { - sh 'dotnet publish vassago.csproj --configuration Release --os linux' - archiveArtifacts artifacts: 'bin/Release/net8.0/linux-x64/publish/*' + dotnetBuild(outputDirectory: "./dist", project: "vassago.csproj") + archiveArtifacts artifacts: 'dist/*' } } stage ('upload') { From 275faaacfc5cfb3419bd32cb2b7e23da0c30a878 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:17:31 -0400 Subject: [PATCH 06/11] move out of test274's house --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 179f854..2aee03b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,7 +44,7 @@ pipeline { withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) { sh """#!/bin/bash - ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop test274' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop vassgo' """ } } @@ -92,7 +92,7 @@ pipeline { withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) { sh """#!/bin/bash - ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user start test274' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user start vassago' """ } } From 660af2805e191d4c294504cb77250a1491b92145 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:18:40 -0400 Subject: [PATCH 07/11] ttttyyyypppppeeeee ssssslllloooowwwweeeerrrrrr for accuracy --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2aee03b..8a47e57 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,7 +44,7 @@ pipeline { withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')]) { sh """#!/bin/bash - ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop vassgo' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop vassago' """ } } From bcc5389d63f08a95cfae91d193cdeb3f08ed18a2 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:30:18 -0400 Subject: [PATCH 08/11] test commands. also install dotnet-ef although surely with dotnet tool list we could check, but it's cutely formatted --- Jenkinsfile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8a47e57..59c2e91 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,35 @@ pipeline { targetHost="alloces.lan" } stages { + + stage("environment setup") { //my environment, here on the jenkins agent + steps { + script { + + sh """#!/bin/bash + function testcmd(){ + if ! command -v \$1 2>&1 >/dev/null + then + echo "this agent doesn't have \$1" + exit 1 + fi + } + + testcmd mktemp + testcmd curl + testcmd git + testcmd sed + testcmd ssh + testcmd ssh-keyscan + testcmd ssh-keygen + testcmd scp + testcmd dotnet + + dotnet tool install --global dotnet-ef + """ + } + } + } stage('clean old'){ steps{ sh 'rm -rf bin obj' From 41172f755c8cde82c99d0f76ce7b3b79e1499555 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:40:03 -0400 Subject: [PATCH 09/11] how about not global then? --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59c2e91..72907d5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { testcmd scp testcmd dotnet - dotnet tool install --global dotnet-ef + dotnet tool install dotnet-ef """ } } From 11411182634148aa4c076887cc4e7550ed902a18 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:51:20 -0400 Subject: [PATCH 10/11] don't doublenest dist/ --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 72907d5..f03f266 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -106,7 +106,7 @@ pipeline { { sh """#!/bin/bash ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv dist/appsettings.json appsettings.json' - ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && mv temp_deploy/ dist/' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && mv temp_deploy dist' ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv appsettings.json dist/appsettings.json' """ } From be36c3cb55654ff70efe3f58a1d7a25947bcac35 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Mar 2025 17:59:30 -0400 Subject: [PATCH 11/11] mv the contents --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f03f266..c82aca9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -106,7 +106,7 @@ pipeline { { sh """#!/bin/bash ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv dist/appsettings.json appsettings.json' - ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && mv temp_deploy dist' + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && shopt -s dotglob & mv temp_deploy/* dist/' ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv appsettings.json dist/appsettings.json' """ }