feat: update leptos service
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
ac435a843e
commit
34145ba380
@ -18,6 +18,34 @@ pub struct CuddleReleaserOptions {
|
|||||||
app: String,
|
app: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum CuddleEnv {
|
||||||
|
Prod,
|
||||||
|
Dev,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for CuddleEnv {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
CuddleEnv::Prod => "prod".into(),
|
||||||
|
CuddleEnv::Dev => "dev".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryInto<CuddleEnv> for String {
|
||||||
|
type Error = eyre::Error;
|
||||||
|
|
||||||
|
fn try_into(self) -> Result<CuddleEnv, Self::Error> {
|
||||||
|
let env = match self.as_str() {
|
||||||
|
"prod" => CuddleEnv::Prod,
|
||||||
|
"dev" => CuddleEnv::Dev,
|
||||||
|
_ => eyre::bail!("was not a valid env: {}", self),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(env)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl CuddleReleaser {
|
impl CuddleReleaser {
|
||||||
pub async fn new(client: dagger_sdk::Query) -> eyre::Result<Self> {
|
pub async fn new(client: dagger_sdk::Query) -> eyre::Result<Self> {
|
||||||
let cuddle_file = CuddleFile::from_cuddle_file().await?;
|
let cuddle_file = CuddleFile::from_cuddle_file().await?;
|
||||||
@ -31,11 +59,8 @@ impl CuddleReleaser {
|
|||||||
folder: ".cuddle/tmp".into(),
|
folder: ".cuddle/tmp".into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
pub async fn releaser(&self, env: CuddleEnv) -> eyre::Result<()> {
|
||||||
impl MainAction for CuddleReleaser {
|
|
||||||
async fn execute_main(&self, _ctx: &mut cli::Context) -> eyre::Result<()> {
|
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
|
|
||||||
if self.cuddle_file.deployment.is_none() {
|
if self.cuddle_file.deployment.is_none() {
|
||||||
@ -49,7 +74,7 @@ impl MainAction for CuddleReleaser {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.env
|
.env
|
||||||
.0
|
.0
|
||||||
.get(&self.env.as_ref().unwrap_or(&"prod".to_string()).to_string())
|
.get(&self.env.as_ref().unwrap_or(&env.to_string()).to_string())
|
||||||
{
|
{
|
||||||
Some(c) => match c.clusters.first().take() {
|
Some(c) => match c.clusters.first().take() {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
@ -111,3 +136,10 @@ impl MainAction for CuddleReleaser {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl MainAction for CuddleReleaser {
|
||||||
|
async fn execute_main(&self, _ctx: &mut cli::Context) -> eyre::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ use crate::{
|
|||||||
rust_service::{
|
rust_service::{
|
||||||
architecture::{Architecture, Os},
|
architecture::{Architecture, Os},
|
||||||
extensions::CargoBInstallExt,
|
extensions::CargoBInstallExt,
|
||||||
RustServiceStage,
|
RustServiceContext, RustServiceStage,
|
||||||
},
|
},
|
||||||
Context, MainAction, PullRequestAction,
|
Context, MainAction, PullRequestAction,
|
||||||
};
|
};
|
||||||
@ -27,6 +27,7 @@ pub struct LeptosService {
|
|||||||
arch: Option<Architecture>,
|
arch: Option<Architecture>,
|
||||||
os: Option<Os>,
|
os: Option<Os>,
|
||||||
deploy_target_name: Option<String>,
|
deploy_target_name: Option<String>,
|
||||||
|
deploy: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LeptosService {
|
impl LeptosService {
|
||||||
@ -42,6 +43,7 @@ impl LeptosService {
|
|||||||
arch: None,
|
arch: None,
|
||||||
os: None,
|
os: None,
|
||||||
deploy_target_name: None,
|
deploy_target_name: None,
|
||||||
|
deploy: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +92,12 @@ impl LeptosService {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_deploy(&mut self, deploy: bool) -> &mut Self {
|
||||||
|
self.deploy = deploy;
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn get_src(&self) -> PathBuf {
|
fn get_src(&self) -> PathBuf {
|
||||||
self.source
|
self.source
|
||||||
.clone()
|
.clone()
|
||||||
@ -341,7 +349,7 @@ impl PullRequestAction for LeptosService {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl MainAction for LeptosService {
|
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 mut s = self.clone();
|
||||||
|
|
||||||
let container = s
|
let container = s
|
||||||
@ -354,56 +362,58 @@ impl MainAction for LeptosService {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs();
|
.as_secs();
|
||||||
|
|
||||||
container
|
let tag = format!(
|
||||||
.publish(format!(
|
"docker.io/kasperhermansen/{}:main-{}",
|
||||||
"docker.io/kasperhermansen/{}:main-{}",
|
self.bin_name, timestamp,
|
||||||
self.bin_name, timestamp,
|
);
|
||||||
))
|
container.publish(tag).await?;
|
||||||
.await?;
|
ctx.set_image_tag(format!("main-{}", ×tamp.to_string()))?;
|
||||||
|
|
||||||
let update_deployments_docker_image =
|
if self.deploy {
|
||||||
"docker.io/kasperhermansen/update-deployment:1701123940";
|
let update_deployments_docker_image =
|
||||||
let dep = self
|
"docker.io/kasperhermansen/update-deployment:1701123940";
|
||||||
.client
|
let dep = self
|
||||||
.container()
|
.client
|
||||||
.from(update_deployments_docker_image);
|
.container()
|
||||||
|
.from(update_deployments_docker_image);
|
||||||
|
|
||||||
let dep = if let Ok(sock) = std::env::var("SSH_AUTH_SOCK") {
|
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))
|
dep.with_unix_socket("/tmp/ssh_sock", self.client.host().unix_socket(sock))
|
||||||
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh_sock")
|
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh_sock")
|
||||||
.with_exec(vec![
|
.with_exec(vec![
|
||||||
"update-deployment",
|
"update-deployment",
|
||||||
"--repo",
|
"--repo",
|
||||||
&format!(
|
&format!(
|
||||||
"git@git.front.kjuulh.io:kjuulh/{}-deployment.git",
|
"git@git.front.kjuulh.io:kjuulh/{}-deployment.git",
|
||||||
self.get_deploy_target()
|
self.get_deploy_target()
|
||||||
),
|
),
|
||||||
"--service",
|
"--service",
|
||||||
&self.bin_name,
|
&self.bin_name,
|
||||||
"--image",
|
"--image",
|
||||||
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
|
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
dep.with_env_variable("GIT_USERNAME", "kjuulh")
|
dep.with_env_variable("GIT_USERNAME", "kjuulh")
|
||||||
.with_env_variable(
|
.with_env_variable(
|
||||||
"GIT_PASSWORD",
|
"GIT_PASSWORD",
|
||||||
std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"),
|
std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"),
|
||||||
)
|
)
|
||||||
.with_exec(vec![
|
.with_exec(vec![
|
||||||
"update-deployment",
|
"update-deployment",
|
||||||
"--repo",
|
"--repo",
|
||||||
&format!(
|
&format!(
|
||||||
"https://git.front.kjuulh.io/kjuulh/{}-deployment.git",
|
"https://git.front.kjuulh.io/kjuulh/{}-deployment.git",
|
||||||
self.get_deploy_target()
|
self.get_deploy_target()
|
||||||
),
|
),
|
||||||
"--service",
|
"--service",
|
||||||
&self.bin_name,
|
&self.bin_name,
|
||||||
"--image",
|
"--image",
|
||||||
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
|
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
|
||||||
])
|
])
|
||||||
};
|
};
|
||||||
|
|
||||||
dep.sync().await?;
|
dep.sync().await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user