Skip to content

Commit e1d417c

Browse files
committed
Use image tag format template for access check image
Signed-off-by: Robert Detjens <[email protected]>
1 parent 6410156 commit e1d417c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/access_handlers/docker.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use bollard::{
66
};
77
use futures::{StreamExt, TryStreamExt};
88
use itertools::Itertools;
9+
use minijinja::render;
910
use tokio;
1011
use tracing::{debug, error, info, trace, warn};
1112

@@ -26,7 +27,13 @@ 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!(
31+
&registry_config.tag_format,
32+
domain => registry_config.domain,
33+
challenge => "accesscheck",
34+
container => "testimage",
35+
profile => profile_name
36+
);
3037
debug!("will push test image to {}", test_image);
3138

3239
// push alpine image with build credentials
@@ -66,16 +73,16 @@ async fn check_build_credentials(client: &Docker, test_image: &str) -> Result<()
6673

6774
let registry_config = &get_config()?.registry;
6875

69-
// rename alpine image as test image
70-
let tag_opts = TagImageOptions {
71-
repo: test_image,
72-
tag: "latest",
73-
};
76+
// rename alpine image as test imag
77+
let (repo, tag) = test_image
78+
.rsplit_once(':')
79+
.unwrap_or((test_image, "latest"));
80+
let tag_opts = TagImageOptions { repo, tag };
7481
client.tag_image("alpine", Some(tag_opts)).await?;
7582

7683
// now push test iamge to configured repo
77-
debug!("pushing alpine to target registry");
78-
let options = PushImageOptions { tag: "latest" };
84+
debug!("pushing alpine to target registry as {}:{}", repo, tag);
85+
let options = PushImageOptions { tag };
7986
let build_creds = DockerCredentials {
8087
username: Some(registry_config.build.user.clone()),
8188
password: Some(registry_config.build.pass.clone()),
@@ -84,7 +91,7 @@ async fn check_build_credentials(client: &Docker, test_image: &str) -> Result<()
8491
};
8592

8693
client
87-
.push_image(test_image, Some(options), Some(build_creds))
94+
.push_image(repo, Some(options), Some(build_creds))
8895
.try_collect::<Vec<_>>()
8996
.await?;
9097

@@ -100,8 +107,11 @@ async fn check_cluster_credentials(client: &Docker, test_image: &str) -> Result<
100107
let registry_config = &get_config()?.registry;
101108

102109
// pull just-pushed alpine image from repo
110+
let (repo, tag) = test_image
111+
.rsplit_once(':')
112+
.unwrap_or((test_image, "latest"));
103113
let alpine_test_image = CreateImageOptions {
104-
from_image: test_image,
114+
from_image: [repo, tag].join(":"),
105115
..Default::default()
106116
};
107117
let cluster_creds = DockerCredentials {

0 commit comments

Comments
 (0)