File tree Expand file tree Collapse file tree 6 files changed +38
-35
lines changed
Expand file tree Collapse file tree 6 files changed +38
-35
lines changed Original file line number Diff line number Diff line change @@ -36,23 +36,24 @@ pub async fn post(Json(payload): Json<PostPayload>) -> impl IntoResponse {
3636 StatusCode :: OK
3737}
3838
39- async fn post_transaction ( cx : QueuedAsyncFrameworkContext , payload : PostPayload ) -> State < ( ) > {
39+ async fn post_transaction ( cx : QueuedAsyncFrameworkContext , _payload : PostPayload ) -> State < ( ) > {
4040 unwrap ! ( cx. check( ) ) ;
4141
42- match transactions:: docker:: pull_image ( & payload . image ) . await {
42+ match transactions:: docker:: compose_up ( & DOCKER_CONTAINER_NAME ) . await {
4343 Ok ( _) => { }
4444 Err ( e) => {
45- tracing:: error!( "failed to update: {e:?}" ) ;
45+ tracing:: error!( "failed to update {} : {e:?}" , & * DOCKER_CONTAINER_NAME ) ;
4646 return State :: Retry ;
4747 }
4848 }
4949
50- unwrap ! ( cx. check( ) ) ;
51-
52- match transactions:: docker:: compose_up ( & DOCKER_CONTAINER_NAME ) . await {
50+ match transactions:: nginx:: reload ( ) . await {
5351 Ok ( _) => { }
5452 Err ( e) => {
55- tracing:: error!( "failed to update {}: {e:?}" , & * DOCKER_CONTAINER_NAME ) ;
53+ tracing:: error!(
54+ "failed to reload nginx after updating {}: {e:?}" ,
55+ & * DOCKER_CONTAINER_NAME
56+ ) ;
5657 return State :: Retry ;
5758 }
5859 }
Original file line number Diff line number Diff line change @@ -97,16 +97,6 @@ pub async fn post(Json(payload): Json<PostPayload>) -> impl IntoResponse {
9797async fn post_transaction ( cx : QueuedAsyncFrameworkContext , payload : PostPayload ) -> State < ( ) > {
9898 unwrap ! ( cx. check( ) ) ;
9999
100- match transactions:: docker:: pull_image ( & payload. image ) . await {
101- Ok ( _) => { }
102- Err ( e) => {
103- tracing:: error!( "failed to deploy {}: {e:?}" , & payload. target) ;
104- return State :: Retry ;
105- }
106- }
107-
108- unwrap ! ( cx. check( ) ) ;
109-
110100 match transactions:: docker:: compose_up ( payload. target . to_string ( ) . as_str ( ) ) . await {
111101 Ok ( _) => { }
112102 Err ( e) => {
Original file line number Diff line number Diff line change @@ -48,6 +48,11 @@ static_lazy_lock! {
4848 pub DOCKER_CONTAINER_NAME : String = env:: var( "DOCKER_CONTAINER_NAME" ) . unwrap_or_else( |_| format!( "api-{}" , clap:: crate_name!( ) ) ) ;
4949}
5050
51+ static_lazy_lock ! {
52+ /// The name of the Docker container that runs Nginx.
53+ pub DOCKER_CONTAINER_NAME_NGINX : String = env:: var( "DOCKER_CONTAINER_NAME_NGINX" ) . unwrap_or_else( |_| "nginx" . into( ) ) ;
54+ }
55+
5156static_lazy_lock ! {
5257 /// The path to the Docker Compose file.
5358 pub DOCKER_COMPOSE_FILE : PathBuf = parse_env!( "DOCKER_COMPOSE_FILE" => |s| Ok ( PathBuf :: from( s) ) ) . unwrap( ) ;
Original file line number Diff line number Diff line change @@ -2,24 +2,6 @@ use anyhow::Result;
22
33use crate :: env:: DOCKER_COMPOSE_FILE ;
44
5- pub async fn pull_image ( image : & str ) -> Result < ( ) > {
6- match tokio:: process:: Command :: new ( "docker" )
7- . arg ( "pull" )
8- . arg ( image)
9- . output ( )
10- . await
11- {
12- Ok ( _) => {
13- tracing:: info!( "successfully pulled image {}" , image) ;
14- Ok ( ( ) )
15- }
16- Err ( e) => {
17- tracing:: error!( "failed to pull image {}: {e:?}" , image) ;
18- Err ( anyhow:: anyhow!( "failed to pull image" ) )
19- }
20- }
21- }
22-
235pub async fn compose_up ( container_name : & str ) -> Result < ( ) > {
246 match tokio:: process:: Command :: new ( "docker" )
257 . arg ( "compose" )
@@ -28,6 +10,8 @@ pub async fn compose_up(container_name: &str) -> Result<()> {
2810 . arg ( "up" )
2911 . arg ( "-d" )
3012 . arg ( container_name)
13+ . arg ( "--pull" )
14+ . arg ( "always" )
3115 . arg ( "--force-recreate" )
3216 . output ( )
3317 . await
Original file line number Diff line number Diff line change 11pub mod docker;
2+ pub mod nginx;
Original file line number Diff line number Diff line change 1+ use crate :: env:: DOCKER_CONTAINER_NAME_NGINX ;
2+
3+ pub async fn reload ( ) -> anyhow:: Result < ( ) > {
4+ match tokio:: process:: Command :: new ( "docker" )
5+ . arg ( "exec" )
6+ . arg ( & * DOCKER_CONTAINER_NAME_NGINX )
7+ . arg ( "nginx" )
8+ . arg ( "-s" )
9+ . arg ( "reload" )
10+ . output ( )
11+ . await
12+ {
13+ Ok ( _) => {
14+ tracing:: info!( "successfully reloaded nginx" ) ;
15+ Ok ( ( ) )
16+ }
17+ Err ( e) => {
18+ tracing:: error!( "failed to reload nginx: {e:?}" ) ;
19+ Err ( anyhow:: anyhow!( "failed to reload nginx" ) )
20+ }
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments