@@ -6,10 +6,11 @@ use bollard::{
66} ;
77use futures:: { StreamExt , TryStreamExt } ;
88use itertools:: Itertools ;
9+ use minijinja;
910use tokio;
1011use tracing:: { debug, error, info, trace, warn} ;
1112
12- use crate :: clients:: docker;
13+ use crate :: clients:: { docker, render_strict } ;
1314use crate :: configparser:: { get_config, get_profile_config} ;
1415
1516/// container registry / daemon access checks
@@ -26,7 +27,16 @@ pub async fn check(profile_name: &str) -> Result<()> {
2627
2728 // build test image string
2829 // registry.example.com/somerepo/testimage:pleaseignore
29- let test_image = format ! ( "{}/credstestimage" , registry_config. domain) ;
30+ let test_image = render_strict (
31+ & registry_config. tag_format ,
32+ minijinja:: context! {
33+ domain => registry_config. domain,
34+ challenge => "accesscheck" ,
35+ container => "testimage" ,
36+ profile => profile_name
37+ } ,
38+ )
39+ . context ( "could not render tag format template" ) ?;
3040 debug ! ( "will push test image to {}" , test_image) ;
3141
3242 // push alpine image with build credentials
@@ -66,16 +76,16 @@ async fn check_build_credentials(client: &Docker, test_image: &str) -> Result<()
6676
6777 let registry_config = & get_config ( ) ?. registry ;
6878
69- // rename alpine image as test image
70- let tag_opts = TagImageOptions {
71- repo : test_image ,
72- tag : "latest" ,
73- } ;
79+ // rename alpine image as test imag
80+ let ( repo , tag ) = test_image
81+ . rsplit_once ( ':' )
82+ . unwrap_or ( ( test_image , "latest" ) ) ;
83+ let tag_opts = TagImageOptions { repo , tag } ;
7484 client. tag_image ( "alpine" , Some ( tag_opts) ) . await ?;
7585
7686 // now push test iamge to configured repo
77- debug ! ( "pushing alpine to target registry" ) ;
78- let options = PushImageOptions { tag : "latest" } ;
87+ debug ! ( "pushing alpine to target registry as {}:{}" , repo , tag ) ;
88+ let options = PushImageOptions { tag } ;
7989 let build_creds = DockerCredentials {
8090 username : Some ( registry_config. build . user . clone ( ) ) ,
8191 password : Some ( registry_config. build . pass . clone ( ) ) ,
@@ -84,7 +94,7 @@ async fn check_build_credentials(client: &Docker, test_image: &str) -> Result<()
8494 } ;
8595
8696 client
87- . push_image ( test_image , Some ( options) , Some ( build_creds) )
97+ . push_image ( repo , Some ( options) , Some ( build_creds) )
8898 . try_collect :: < Vec < _ > > ( )
8999 . await ?;
90100
@@ -100,8 +110,11 @@ async fn check_cluster_credentials(client: &Docker, test_image: &str) -> Result<
100110 let registry_config = & get_config ( ) ?. registry ;
101111
102112 // pull just-pushed alpine image from repo
113+ let ( repo, tag) = test_image
114+ . rsplit_once ( ':' )
115+ . unwrap_or ( ( test_image, "latest" ) ) ;
103116 let alpine_test_image = CreateImageOptions {
104- from_image : test_image ,
117+ from_image : [ repo , tag ] . join ( ":" ) ,
105118 ..Default :: default ( )
106119 } ;
107120 let cluster_creds = DockerCredentials {
0 commit comments