1+ use crate :: embed_files;
12use dockworker:: container:: ContainerFilters ;
23use dockworker:: { ContainerCreateOptions , ContainerHostConfig , Docker , PortBindings } ;
4+ use futures_util:: StreamExt ;
35use include_dir:: Dir ;
6+ use std:: future;
47use std:: path:: Path ;
58use std:: time:: Duration ;
69
7- use crate :: embed_files;
8-
910pub fn connect_docker ( ) -> Docker {
1011 return Docker :: connect_with_defaults ( ) . expect ( "[-] Failed to connect to Docker" ) ;
1112}
@@ -67,6 +68,29 @@ pub async fn start_container<'a>(
6768 ] ;
6869 host_config. binds ( binds) ;
6970
71+ // Pull the image
72+ println ! ( "[*] Pulling grafana image ..." ) ;
73+ match docker
74+ . create_image ( "grafana/grafana-enterprise" , "latest" )
75+ . await
76+ {
77+ Err ( error) => {
78+ println ! ( "[-] Error: {:?}\n \t Pulling the grafana image failed" , error) ;
79+ panic ! ( "" )
80+ }
81+ Ok ( result) => {
82+ result
83+ . for_each ( |item| {
84+ if let Err ( error) = item {
85+ println ! ( "[-] Error: {:?}\n \t Pulling the grafana image failed" , error) ;
86+ panic ! ( "" )
87+ }
88+ future:: ready ( ( ) )
89+ } )
90+ . await
91+ }
92+ }
93+
7094 // Create the container
7195 let mut create_options = ContainerCreateOptions :: new ( "grafana/grafana-enterprise:latest" ) ;
7296 create_options
@@ -89,7 +113,9 @@ pub async fn start_container<'a>(
89113 // Start the container
90114 docker. start_container ( & container_id) . await . unwrap ( ) ;
91115
92- println ! ( "[*] Grafana container started successfully. It can be accessed at http://localhost:3000" ) ;
116+ println ! (
117+ "[*] Grafana container started successfully. It can be accessed at http://localhost:3000"
118+ ) ;
93119}
94120
95121pub async fn remove_container ( docker : & Docker , container_id : String ) {
@@ -156,4 +182,4 @@ pub async fn get_dead_container_id(docker: &Docker, container_name: &str) -> Opt
156182 . iter ( )
157183 . find ( |& c| c. Names . contains ( & format ! ( "/{}" , container_name) ) )
158184 . map ( |c| c. Id . clone ( ) )
159- }
185+ }
0 commit comments