feat: update leptos service
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-03-02 15:23:54 +01:00
parent ac435a843e
commit 34145ba380
2 changed files with 96 additions and 54 deletions

View File

@@ -10,7 +10,7 @@ use crate::{
rust_service::{
architecture::{Architecture, Os},
extensions::CargoBInstallExt,
RustServiceStage,
RustServiceContext, RustServiceStage,
},
Context, MainAction, PullRequestAction,
};
@@ -27,6 +27,7 @@ pub struct LeptosService {
arch: Option<Architecture>,
os: Option<Os>,
deploy_target_name: Option<String>,
deploy: bool,
}
impl LeptosService {
@@ -42,6 +43,7 @@ impl LeptosService {
arch: None,
os: None,
deploy_target_name: None,
deploy: true,
}
}
@@ -90,6 +92,12 @@ impl LeptosService {
self
}
pub fn with_deploy(&mut self, deploy: bool) -> &mut Self {
self.deploy = deploy;
self
}
fn get_src(&self) -> PathBuf {
self.source
.clone()
@@ -341,7 +349,7 @@ impl PullRequestAction for LeptosService {
#[async_trait]
impl MainAction for LeptosService {
async fn execute_main(&self, _ctx: &mut Context) -> eyre::Result<()> {
async fn execute_main(&self, ctx: &mut Context) -> eyre::Result<()> {
let mut s = self.clone();
let container = s
@@ -354,56 +362,58 @@ impl MainAction for LeptosService {
.unwrap()
.as_secs();
container
.publish(format!(
"docker.io/kasperhermansen/{}:main-{}",
self.bin_name, timestamp,
))
.await?;
let tag = format!(
"docker.io/kasperhermansen/{}:main-{}",
self.bin_name, timestamp,
);
container.publish(tag).await?;
ctx.set_image_tag(format!("main-{}", &timestamp.to_string()))?;
let update_deployments_docker_image =
"docker.io/kasperhermansen/update-deployment:1701123940";
let dep = self
.client
.container()
.from(update_deployments_docker_image);
if self.deploy {
let update_deployments_docker_image =
"docker.io/kasperhermansen/update-deployment:1701123940";
let dep = self
.client
.container()
.from(update_deployments_docker_image);
let dep = if let Ok(sock) = std::env::var("SSH_AUTH_SOCK") {
dep.with_unix_socket("/tmp/ssh_sock", self.client.host().unix_socket(sock))
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh_sock")
.with_exec(vec![
"update-deployment",
"--repo",
&format!(
"git@git.front.kjuulh.io:kjuulh/{}-deployment.git",
self.get_deploy_target()
),
"--service",
&self.bin_name,
"--image",
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
])
} else {
dep.with_env_variable("GIT_USERNAME", "kjuulh")
.with_env_variable(
"GIT_PASSWORD",
std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"),
)
.with_exec(vec![
"update-deployment",
"--repo",
&format!(
"https://git.front.kjuulh.io/kjuulh/{}-deployment.git",
self.get_deploy_target()
),
"--service",
&self.bin_name,
"--image",
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
])
};
let dep = if let Ok(sock) = std::env::var("SSH_AUTH_SOCK") {
dep.with_unix_socket("/tmp/ssh_sock", self.client.host().unix_socket(sock))
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh_sock")
.with_exec(vec![
"update-deployment",
"--repo",
&format!(
"git@git.front.kjuulh.io:kjuulh/{}-deployment.git",
self.get_deploy_target()
),
"--service",
&self.bin_name,
"--image",
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
])
} else {
dep.with_env_variable("GIT_USERNAME", "kjuulh")
.with_env_variable(
"GIT_PASSWORD",
std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"),
)
.with_exec(vec![
"update-deployment",
"--repo",
&format!(
"https://git.front.kjuulh.io/kjuulh/{}-deployment.git",
self.get_deploy_target()
),
"--service",
&self.bin_name,
"--image",
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
])
};
dep.sync().await?;
dep.sync().await?;
}
Ok(())
}