diff options
| -rw-r--r-- | include/deliverable.h | 10 | ||||
| -rw-r--r-- | src/deliverable.c | 52 | 
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 | 
