]> git.ipfire.org Git - pakfire.git/commitdiff
jobs: Upload packages after the build is done
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 15:49:26 +0000 (15:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 15:49:26 +0000 (15:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c
src/pakfire/daemon.h
src/pakfire/job.c

index f857e27037336604d7d62bb137219e134a2e3123..fcb554083cbb7ba86ff9ab92a536201a0205ef8c 100644 (file)
@@ -59,6 +59,9 @@ struct pakfire_daemon {
        // HTTP Client
        struct pakfire_httpclient* client;
 
+       // Build Service
+       struct pakfire_buildservice* service;
+
        // URL
        char url[PATH_MAX];
 
@@ -1094,6 +1097,8 @@ static void pakfire_daemon_free(struct pakfire_daemon* daemon) {
                sd_event_source_unref(daemon->connect_timer);
        if (daemon->stats_timer)
                sd_event_source_unref(daemon->stats_timer);
+       if (daemon->service)
+               pakfire_buildservice_unref(daemon->service);
        if (daemon->client)
                pakfire_httpclient_unref(daemon->client);
        if (daemon->cgroup)
@@ -1147,6 +1152,11 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
        if (r)
                goto ERROR;
 
+       // Connect to the build service
+       r = pakfire_buildservice_create(&d->service, d->ctx, d->url);
+       if (r < 0)
+               goto ERROR;
+
        // Create the cgroup
        r = pakfire_cgroup_create(&d->cgroup, d->ctx, NULL, "pakfire-daemon", 0);
        if (r < 0)
@@ -1190,6 +1200,10 @@ sd_event* pakfire_daemon_loop(struct pakfire_daemon* daemon) {
        return sd_event_ref(daemon->loop);
 }
 
+struct pakfire_buildservice* pakfire_daemon_buildservice(struct pakfire_daemon* daemon) {
+       return pakfire_buildservice_ref(daemon->service);
+}
+
 struct pakfire_httpclient* pakfire_daemon_httpclient(struct pakfire_daemon* daemon) {
        return pakfire_httpclient_ref(daemon->client);
 }
index ccca574c67de5bf0227be8468c207e6b244f72f5..2bbffc57c89bca60d30658cf9a410df996968c2b 100644 (file)
@@ -25,6 +25,7 @@
 
 struct pakfire_daemon;
 
+#include <pakfire/buildservice.h>
 #include <pakfire/ctx.h>
 #include <pakfire/job.h>
 
@@ -34,6 +35,7 @@ struct pakfire_daemon* pakfire_daemon_ref(struct pakfire_daemon* daemon);
 struct pakfire_daemon* pakfire_daemon_unref(struct pakfire_daemon* daemon);
 
 sd_event* pakfire_daemon_loop(struct pakfire_daemon* daemon);
+struct pakfire_buildservice* pakfire_daemon_buildservice(struct pakfire_daemon* daemon);
 struct pakfire_httpclient* pakfire_daemon_httpclient(struct pakfire_daemon* daemon);
 
 const char* pakfire_daemon_url(struct pakfire_daemon* daemon);
index d764d94f3ed1f8e607f640f236696d71f613512b..4f4303b6658ddab6d46ddfe345f4efae465ed3d0 100644 (file)
@@ -49,8 +49,12 @@ struct pakfire_job {
        struct pakfire_ctx* ctx;
        int nrefs;
 
+       // Daemon
        struct pakfire_daemon* daemon;
 
+       // Build Service
+       struct pakfire_buildservice* service;
+
        // Event Loop
        sd_event* loop;
 
@@ -101,6 +105,9 @@ struct pakfire_job {
                PAKFIRE_JOB_STATE_EXITED,
                PAKFIRE_JOB_STATE_KILLED,
        } state;
+
+       // Uploads
+       char** uploads;
 };
 
 static int pakfire_parse_job(struct pakfire_job* job, json_object* data) {
@@ -236,6 +243,10 @@ static void pakfire_job_free(struct pakfire_job* job) {
        if (job->log.stderr)
                pakfire_log_stream_unref(job->log.stderr);
 
+       if (job->service)
+               pakfire_buildservice_unref(job->service);
+       if (job->uploads)
+               pakfire_strings_free(job->uploads);
        if (job->config)
                pakfire_config_unref(job->config);
        if (job->loop)
@@ -337,6 +348,60 @@ ERROR:
        return r;
 }
 
+static int pakfire_job_result(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+               struct pakfire_build* build, struct pakfire_archive* archive, void* data) {
+       struct pakfire_job* job = data;
+       struct pakfire_package* pkg = NULL;
+       char* uuid = NULL;
+       int r;
+
+       // Fetch package metadata
+       r = pakfire_archive_make_package(archive, NULL, &pkg);
+       if (r < 0)
+               goto ERROR;
+
+       // Fetch NEVRA
+       const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
+       if (!nevra) {
+               r = -EINVAL;
+               goto ERROR;
+       }
+
+       // Fetch filename
+       const char* filename = pakfire_package_get_filename(pkg);
+       if (!filename) {
+               r = -EINVAL;
+               goto ERROR;
+       }
+
+       // Fetch path
+       const char* path = pakfire_archive_get_path(archive);
+       if (!path) {
+               r = -EINVAL;
+               goto ERROR;
+       }
+
+       // Upload the file
+       r = pakfire_buildservice_upload(job->service, path, filename, &uuid);
+       if (r < 0) {
+               ERROR(job->ctx, "Could not upload %s: %s\n", nevra, strerror(-r));
+               goto ERROR;
+       }
+
+       // Store the ID of the upload
+       r = pakfire_strings_append(&job->uploads, uuid);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (pkg)
+               pakfire_package_unref(pkg);
+       if (uuid)
+               free(uuid);
+
+       return r;
+}
+
 /*
        This method is triggered by SIGCHLD whenever the job exits
 */
@@ -522,7 +587,7 @@ static int pakfire_job_child(struct pakfire_job* job) {
        // XXX need to set target
 
        // Run the build
-       r = pakfire_build_exec(build, job->pkg, NULL, NULL);
+       r = pakfire_build_exec(build, job->pkg, pakfire_job_result, job);
 
 ERROR:
        if (build)
@@ -817,6 +882,9 @@ int pakfire_job_create(struct pakfire_job** job, struct pakfire_ctx* ctx,
                goto ERROR;
        }
 
+       // Fetch a reference to the build service
+       j->service = pakfire_daemon_buildservice(daemon);
+
        // Initialize the PID file descriptor
        j->pidfd = -1;