22/// Current implementation uses `docker` and `AWS ECR` as container registry.
33use std:: path:: PathBuf ;
44
5- use crate :: prelude:: * ;
65use crate :: prelude:: anyhow:: Context as _;
6+ use crate :: prelude:: * ;
77use crate :: utils:: aws_cli:: {
88 aws_account_id, ec2_autoscaling_latest_instance_refresh_status,
99 ec2_autoscaling_start_instance_refresh, ecr_compute_next_numeric_tag, ecr_docker_login,
@@ -18,12 +18,12 @@ pub struct ContainerCmdArgs {}
1818
1919impl Default for ContainerSubCommand {
2020 fn default ( ) -> Self {
21- ContainerSubCommand :: Build ( BuildSubCmdArgs :: default ( ) )
21+ ContainerSubCommand :: Build ( ContainerBuildSubCmdArgs :: default ( ) )
2222 }
2323}
2424
2525#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
26- pub struct BuildSubCmdArgs {
26+ pub struct ContainerBuildSubCmdArgs {
2727 /// Path to build file relative to context directory (i.e. a Dockerfile)
2828 pub build_file : PathBuf ,
2929 /// Build context directory (default to repository root)
@@ -41,7 +41,7 @@ pub struct BuildSubCmdArgs {
4141}
4242
4343#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
44- pub struct ListSubCmdArgs {
44+ pub struct ContainerListSubCmdArgs {
4545 /// Region where the container repository lives
4646 #[ arg( long) ]
4747 pub region : String ,
@@ -51,7 +51,7 @@ pub struct ListSubCmdArgs {
5151}
5252
5353#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
54- pub struct PullSubCmdArgs {
54+ pub struct ContainerPullSubCmdArgs {
5555 /// Region where the container repository lives
5656 #[ arg( long) ]
5757 pub region : String ,
@@ -67,7 +67,7 @@ pub struct PullSubCmdArgs {
6767}
6868
6969#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
70- pub struct PushSubCmdArgs {
70+ pub struct ContainerPushSubCmdArgs {
7171 /// Local image name (the one used in the build command)
7272 #[ arg( long) ]
7373 pub image : String ,
@@ -89,7 +89,7 @@ pub struct PushSubCmdArgs {
8989}
9090
9191#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
92- pub struct PromoteSubCmdArgs {
92+ pub struct ContainerPromoteSubCmdArgs {
9393 /// Region where the container repository lives
9494 #[ arg( long) ]
9595 pub region : String ,
@@ -102,7 +102,7 @@ pub struct PromoteSubCmdArgs {
102102}
103103
104104#[ derive( clap:: Args , Clone , PartialEq , Debug ) ]
105- pub struct RolloutSubCmdArgs {
105+ pub struct ContainerRolloutSubCmdArgs {
106106 /// Region of the Auto Scaling Group
107107 #[ arg( long) ]
108108 pub region : String ,
@@ -112,36 +112,36 @@ pub struct RolloutSubCmdArgs {
112112 pub asg : String ,
113113
114114 /// Strategy for instance refresh (Rolling is the standard choice for zero-downtime rollouts)
115- #[ arg( long, value_name = "Rolling" , default_value_t = RolloutSubCmdArgs :: default ( ) . strategy) ]
115+ #[ arg( long, value_name = "Rolling" , default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . strategy) ]
116116 pub strategy : String ,
117117
118118 /// Seconds for instance warmup
119- #[ arg( long, value_name = "SECS" , default_value_t = RolloutSubCmdArgs :: default ( ) . instance_warmup) ]
119+ #[ arg( long, value_name = "SECS" , default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . instance_warmup) ]
120120 pub instance_warmup : u64 ,
121121
122122 /// Minimum healthy percentage during the rollout
123- #[ arg( long, value_name = "PCT" , default_value_t = RolloutSubCmdArgs :: default ( ) . min_healthy_percentage) ]
123+ #[ arg( long, value_name = "PCT" , default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . min_healthy_percentage) ]
124124 pub min_healthy_percentage : u8 ,
125125
126126 /// If set, skip replacing instances that already match the launch template/config
127- #[ arg( long, default_value_t = RolloutSubCmdArgs :: default ( ) . skip_matching) ]
127+ #[ arg( long, default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . skip_matching) ]
128128 pub skip_matching : bool ,
129129
130130 /// Wait until the refresh completes
131- #[ arg( long, default_value_t = RolloutSubCmdArgs :: default ( ) . wait) ]
131+ #[ arg( long, default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . wait) ]
132132 pub wait : bool ,
133133
134134 /// Max seconds to wait when --wait is set
135- #[ arg( long, default_value_t = RolloutSubCmdArgs :: default ( ) . wait_timeout_secs) ]
135+ #[ arg( long, default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . wait_timeout_secs) ]
136136 pub wait_timeout_secs : u64 ,
137137
138138 /// Poll interval seconds when --wait is set
139- #[ arg( long, default_value_t = RolloutSubCmdArgs :: default ( ) . wait_poll_secs) ]
139+ #[ arg( long, default_value_t = ContainerRolloutSubCmdArgs :: default ( ) . wait_poll_secs) ]
140140 pub wait_poll_secs : u64 ,
141141}
142142
143143#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
144- pub struct RunSubCmdArgs {
144+ pub struct ContainerRunSubCmdArgs {
145145 /// Fully qualified image reference (e.g. 123.dkr.ecr.us-east-1.amazonaws.com/bc-backend:latest)
146146 #[ arg( long) ]
147147 pub image : String ,
@@ -163,7 +163,7 @@ pub struct RunSubCmdArgs {
163163 pub extra_arg : Vec < String > ,
164164}
165165
166- impl Default for RolloutSubCmdArgs {
166+ impl Default for ContainerRolloutSubCmdArgs {
167167 fn default ( ) -> Self {
168168 Self {
169169 region : String :: new ( ) ,
@@ -180,7 +180,7 @@ impl Default for RolloutSubCmdArgs {
180180}
181181
182182#[ derive( clap:: Args , Default , Clone , PartialEq ) ]
183- pub struct RollbackSubCmdArgs {
183+ pub struct ContainerRollbackSubCmdArgs {
184184 /// Region where the container repository lives
185185 #[ arg( long) ]
186186 pub region : String ,
@@ -206,7 +206,7 @@ pub fn handle_command(
206206 }
207207}
208208
209- fn build ( build_args : BuildSubCmdArgs ) -> anyhow:: Result < ( ) > {
209+ fn build ( build_args : ContainerBuildSubCmdArgs ) -> anyhow:: Result < ( ) > {
210210 let context_dir = build_args. context_dir . unwrap_or ( git_repo_root_or_cwd ( ) ?) ;
211211 let build_file_path = if build_args. build_file . is_absolute ( ) {
212212 build_args. build_file . clone ( )
@@ -230,7 +230,7 @@ fn build(build_args: BuildSubCmdArgs) -> anyhow::Result<()> {
230230 docker_cli ( args, None , None , "docker build failed" )
231231}
232232
233- fn list ( list_args : ListSubCmdArgs ) -> anyhow:: Result < ( ) > {
233+ fn list ( list_args : ContainerListSubCmdArgs ) -> anyhow:: Result < ( ) > {
234234 let ecr_repository = & list_args. repository ;
235235 let latest_present = ecr_get_manifest ( ecr_repository, & list_args. region , "latest" ) ?. is_some ( ) ;
236236 let rollback_present =
@@ -281,7 +281,7 @@ fn list(list_args: ListSubCmdArgs) -> anyhow::Result<()> {
281281 Ok ( ( ) )
282282}
283283
284- fn pull ( args : PullSubCmdArgs ) -> anyhow:: Result < ( ) > {
284+ fn pull ( args : ContainerPullSubCmdArgs ) -> anyhow:: Result < ( ) > {
285285 let account_id = aws_account_id ( ) ?;
286286 eprintln ! (
287287 "📥 Pulling image from ECR\n Account: {account_id}\n Region: {}\n Repo: {}\n Tag: {}" ,
@@ -308,7 +308,7 @@ fn pull(args: PullSubCmdArgs) -> anyhow::Result<()> {
308308 Ok ( ( ) )
309309}
310310
311- fn push ( push_args : PushSubCmdArgs ) -> anyhow:: Result < ( ) > {
311+ fn push ( push_args : ContainerPushSubCmdArgs ) -> anyhow:: Result < ( ) > {
312312 ecr_ensure_repo_exists ( & push_args. repository , & push_args. region ) ?;
313313 // check if the container as already been pushed
314314 if let Some ( existing_manifest) = ecr_get_manifest (
@@ -407,7 +407,7 @@ fn push(push_args: PushSubCmdArgs) -> anyhow::Result<()> {
407407}
408408
409409/// promote: point N to `latest` and move the previous `latest` to `rollback`
410- fn promote ( promote_args : PromoteSubCmdArgs ) -> anyhow:: Result < ( ) > {
410+ fn promote ( promote_args : ContainerPromoteSubCmdArgs ) -> anyhow:: Result < ( ) > {
411411 // Fetch current 'latest' and the target tag's manifest.
412412 let prev_latest_manifest =
413413 ecr_get_manifest ( & promote_args. repository , & promote_args. region , "latest" )
@@ -462,7 +462,7 @@ fn promote(promote_args: PromoteSubCmdArgs) -> anyhow::Result<()> {
462462}
463463
464464/// rollback: promote 'rollback' to 'latest' and then remove the 'rollback' tag
465- fn rollback ( rollback_args : RollbackSubCmdArgs ) -> anyhow:: Result < ( ) > {
465+ fn rollback ( rollback_args : ContainerRollbackSubCmdArgs ) -> anyhow:: Result < ( ) > {
466466 use anyhow:: Context ;
467467 // Fetch the manifest of the 'rollback' tag
468468 let rb = ecr_get_manifest ( & rollback_args. repository , & rollback_args. region , "rollback" ) ?
@@ -508,7 +508,7 @@ fn rollback(rollback_args: RollbackSubCmdArgs) -> anyhow::Result<()> {
508508}
509509
510510/// rollout: rollout latest promoted container
511- fn rollout ( args : RolloutSubCmdArgs ) -> anyhow:: Result < ( ) > {
511+ fn rollout ( args : ContainerRolloutSubCmdArgs ) -> anyhow:: Result < ( ) > {
512512 use anyhow:: Context ;
513513 use std:: {
514514 io:: { self , Write } ,
@@ -607,7 +607,7 @@ fn rollout(args: RolloutSubCmdArgs) -> anyhow::Result<()> {
607607 Ok ( ( ) )
608608}
609609
610- fn run ( args : RunSubCmdArgs ) -> anyhow:: Result < ( ) > {
610+ fn run ( args : ContainerRunSubCmdArgs ) -> anyhow:: Result < ( ) > {
611611 let mut cli_args: Vec < String > = vec ! [ "run" . into( ) , "--rm" . into( ) ] ;
612612
613613 if let Some ( ref name) = args. name {
0 commit comments