Editing one Dockerfile keeps every image's build edge -- also the one * between nodes that both pre-existed (Image -> the unchanged Dockerfile), * which the incremental routes recompute whole. `legacy`: through the * full-load route, else the closure-repair route. Returns the build edge * count before / after as "full=N inc=M", or NULL; *route: the route taken. */
| 3909 | * full-load route, else the closure-repair route. Returns the build edge |
| 3910 | * count before / after as "full=N inc=M", or NULL; *route: the route taken. */ |
| 3911 | static char *incremental_build_keep(bool legacy, cbm_incremental_route_t *route) { |
| 3912 | char tmp[256]; |
| 3913 | snprintf(tmp, sizeof(tmp), "/tmp/cbm_buildkeep_XXXXXX"); |
| 3914 | if (!cbm_mkdtemp(tmp)) { |
| 3915 | return NULL; |
| 3916 | } |
| 3917 | write_temp_file(tmp, "src/web/Dockerfile", "FROM nginx:1.27\n"); |
| 3918 | write_temp_file(tmp, "src/api/Dockerfile", "FROM golang:1.22\n"); |
| 3919 | write_temp_file(tmp, "skaffold.yaml", |
| 3920 | "apiVersion: skaffold/v4beta6\nkind: Config\nbuild:\n artifacts:\n" |
| 3921 | " - image: web\n context: src/web\n" |
| 3922 | " - image: api\n context: src/api\n"); |
| 3923 | char db_path[512]; |
| 3924 | snprintf(db_path, sizeof(db_path), "%s/buildkeep.db", tmp); |
| 3925 | static const char builds[] = |
| 3926 | "SELECT COUNT(*) FROM edges e JOIN nodes s ON s.id=e.source_id WHERE e.type='DEPENDS_ON' " |
| 3927 | "AND s.label='Image' AND json_extract(e.properties,'$.via')='build'"; |
| 3928 | int full = k8s_inc_index(tmp, db_path) == 0 ? k8s_inc_count(db_path, builds) : -1; |
| 3929 | write_temp_file(tmp, "src/web/Dockerfile", "FROM nginx:1.27\n# edited\n"); |
| 3930 | #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API |
| 3931 | if (legacy) { |
| 3932 | cbm_pipeline_incremental_test_force_legacy_partial_once(); |
| 3933 | } |
| 3934 | #else |
| 3935 | (void)legacy; |
| 3936 | #endif |
| 3937 | char *out = NULL; |
| 3938 | if (k8s_inc_index(tmp, db_path) == 0) { |
| 3939 | char buf[64]; |
| 3940 | snprintf(buf, sizeof(buf), "full=%d inc=%d", full, k8s_inc_count(db_path, builds)); |
| 3941 | out = strdup(buf); |
| 3942 | } |
| 3943 | *route = cbm_pipeline_incremental_test_last_route(); |
| 3944 | th_rmtree(tmp); |
| 3945 | return out; |
| 3946 | } |
| 3947 | |
| 3948 | TEST(incremental_dockerfile_edit_keeps_build_edges) { |
| 3949 | cbm_incremental_route_t route = CBM_INCREMENTAL_ROUTE_NONE; |
no test coverage detected