Skip to content

Commit

Permalink
Implement initial driver code for docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jhunkeler committed Feb 23, 2024
1 parent 8deba7c commit 6f41f11
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/deliverable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
52 changes: 52 additions & 0 deletions src/deliverable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6f41f11

Please sign in to comment.