aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-04-10 08:36:41 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-04-10 08:38:56 -0400
commit9cca7f4122619acbbc35df870b6ae9785f72d2c7 (patch)
tree4b5f879552132fe489f941b4fcdf276012cd2470
parent657cde7c36b3a4ff8878310792f2a768f5218a63 (diff)
downloadstasis-9cca7f4122619acbbc35df870b6ae9785f72d2c7.tar.gz
Add docker_sanitize_tag()
* Replace invalid docker tag characters with dash ('-')
-rw-r--r--include/docker.h1
-rw-r--r--src/deliverable.c8
-rw-r--r--src/docker.c12
3 files changed, 18 insertions, 3 deletions
diff --git a/include/docker.h b/include/docker.h
index 413bf6d..33726e6 100644
--- a/include/docker.h
+++ b/include/docker.h
@@ -83,5 +83,6 @@ int docker_exec(const char *args, unsigned flags);
int docker_build(const char *dirpath, const char *args, int engine);
int docker_script(const char *image, char *data, unsigned flags);
int docker_save(const char *image, const char *destdir, const char *compression_program);
+void docker_sanitize_tag(char *str);
#endif //OMC_DOCKER_H
diff --git a/src/deliverable.c b/src/deliverable.c
index 09b30f1..9b20a63 100644
--- a/src/deliverable.c
+++ b/src/deliverable.c
@@ -1758,7 +1758,9 @@ int delivery_docker(struct Delivery *ctx) {
// Append image tags to command
for (size_t i = 0; i < total_tags; i++) {
- char *tag = strlist_item(ctx->deploy.docker.tags, i);
+ char *tag_orig = strlist_item(ctx->deploy.docker.tags, i);
+ strcpy(tag, tag_orig);
+ docker_sanitize_tag(tag);
sprintf(args + strlen(args), " -t \"%s\" ", tag);
}
@@ -1795,8 +1797,8 @@ int delivery_docker(struct Delivery *ctx) {
// Test the image
// All tags point back to the same image so test the first one we see
// regardless of how many are defined
- char *tag = NULL;
- tag = strlist_item(ctx->deploy.docker.tags, 0);
+ strcpy(tag, strlist_item(ctx->deploy.docker.tags, 0));
+ docker_sanitize_tag(tag);
msg(OMC_MSG_L2, "Executing image test script for %s\n", tag);
if (ctx->deploy.docker.test_script) {
diff --git a/src/docker.c b/src/docker.c
index d5cffd9..e2a392b 100644
--- a/src/docker.c
+++ b/src/docker.c
@@ -168,3 +168,15 @@ int docker_capable(struct DockerCapabilities *result) {
result->usable = true;
return true;
}
+
+void docker_sanitize_tag(char *str) {
+ char *pos = str;
+ while (*pos != 0) {
+ if (!isalnum(*pos)) {
+ if (*pos != '.' && *pos != ':' && *pos != '/') {
+ *pos = '-';
+ }
+ }
+ pos++;
+ }
+}