aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-02-23 17:16:18 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-02-23 17:19:56 -0500
commit6f41f11cc268faa09e8b4123bf0d995b5fb964e2 (patch)
treefe18c65217aaaa014b399d94099804a9d5f83557
parent8deba7c9840d3cbccf215bf52584ddfe0d848ce4 (diff)
downloadstasis-6f41f11cc268faa09e8b4123bf0d995b5fb964e2.tar.gz
Implement initial driver code for docker builds
-rw-r--r--include/deliverable.h10
-rw-r--r--src/deliverable.c52
2 files changed, 62 insertions, 0 deletions
diff --git a/include/deliverable.h b/include/deliverable.h
index 85cda6b..63adef1 100644
--- a/include/deliverable.h
+++ b/include/deliverable.h
@@ -142,6 +142,14 @@ struct Delivery {
char *dest;
} deploy[1000];
+ struct Docker {
+ struct DockerCapabilities capabilities;
+ char *dockerfile;
+ char *registry;
+ struct StrList *build_args;
+ struct StrList *tags;
+ } docker;
+
struct Rule {
struct INIFILE *_handle;
bool enable_final; ///< true=allow rc value replacement, false=keep rc value even if final release
@@ -345,4 +353,6 @@ int delivery_init_artifactory(struct Delivery *ctx);
int delivery_artifact_upload(struct Delivery *ctx);
int delivery_mission_render_files(struct Delivery *ctx);
+
+int delivery_docker(struct Delivery *ctx);
#endif //OMC_DELIVERABLE_H
diff --git a/src/deliverable.c b/src/deliverable.c
index e1179a4..1860ee6 100644
--- a/src/deliverable.c
+++ b/src/deliverable.c
@@ -1574,3 +1574,55 @@ int delivery_mission_render_files(struct Delivery *ctx) {
return 0;
}
+
+int delivery_docker(struct Delivery *ctx) {
+ if (!docker_capable(&ctx->docker.capabilities)) {
+ return -1;
+ }
+ char args[PATH_MAX];
+ size_t total_tags = strlist_count(ctx->docker.tags);
+ size_t total_build_args = strlist_count(ctx->docker.build_args);
+
+ if (!total_tags) {
+ fprintf(stderr, "error: at least one docker image tag must be defined\n");
+ return -1;
+ }
+
+ // Append image tags to command
+ for (size_t i = 0; i < total_tags; i++) {
+ char *tag = strlist_item(ctx->docker.tags, i);
+ sprintf(args + strlen(args), " -t \"%s\" ", tag);
+ }
+
+ // Append build arguments to command (i.e. --build-arg "key=value"
+ for (size_t i = 0; i < total_build_args; i++) {
+ char *build_arg = strlist_item(ctx->docker.build_args, i);
+ if (!build_arg) {
+ break;
+ }
+ sprintf(args + strlen(args), " --build-arg \"%s\" ", build_arg);
+ }
+
+ // Build the image
+ if (docker_build(ctx->storage.delivery_dir, args, ctx->docker.capabilities.build)) {
+ return -1;
+ }
+
+ // 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->docker.tags, 0);
+ if (docker_script(tag, "source /etc/profile\npython -m pip freeze\nmamba info", 0)) {
+ // test failed -- don't save the image
+ return -1;
+ }
+
+ // Test successful, save image
+ if (docker_save(basename(tag), ctx->storage.delivery_dir)) {
+ // save failed
+ return -1;
+ }
+
+ return 0;
+} \ No newline at end of file