A compose service: a Resource {ecosystem:compose, kind:Service} the file * DEFINES; it DEPENDS_ON the services it depends on / links, USAGE * {ref:image} its image, DEPENDS_ON {via:build} the Dockerfile it builds and * CONNECTS_TO the services its environment addresses. */
| 1600 | * {ref:image} its image, DEPENDS_ON {via:build} the Dockerfile it builds and |
| 1601 | * CONNECTS_TO the services its environment addresses. */ |
| 1602 | static void dk_compose_service(const cbm_compose_service_t *s, void *ud) { |
| 1603 | dk_compose_t *c = ud; |
| 1604 | const char *qn = dk_compose_qn(c, s->name); |
| 1605 | if (!qn) { |
| 1606 | return; |
| 1607 | } |
| 1608 | if (c->pass == 0) { |
| 1609 | char esc[CBM_SZ_512]; |
| 1610 | cbm_json_escape(esc, (int)sizeof(esc), s->name); |
| 1611 | char props[CBM_SZ_1K]; |
| 1612 | snprintf(props, sizeof(props), |
| 1613 | "{\"ecosystem\":\"compose\",\"kind\":\"Service\",\"service\":\"%s\"}", esc); |
| 1614 | int64_t id = cbm_gbuf_upsert_node(c->ctx->gbuf, "Resource", |
| 1615 | cbm_arena_sprintf(c->a, "Service/%s", s->name), qn, |
| 1616 | c->file, s->line + SKIP_ONE, s->end_line, props); |
| 1617 | dk_compose_edge(c, c->file_node, id, "DEFINES", "{}"); |
| 1618 | const cbm_gbuf_node_t *self = id > 0 ? cbm_gbuf_find_by_id(c->ctx->gbuf, id) : NULL; |
| 1619 | for (int i = 0; self && i < s->nenv; i++) { |
| 1620 | if (cbm_pipeline_env_setter(c->ctx, self, s->name, s->env[i], "compose", |
| 1621 | s->env_lines[i]) > 0) { |
| 1622 | c->edges++; |
| 1623 | } |
| 1624 | } |
| 1625 | return; |
| 1626 | } |
| 1627 | const cbm_gbuf_node_t *self = cbm_gbuf_find_by_qn(c->ctx->gbuf, qn); |
| 1628 | if (!self) { |
| 1629 | return; |
| 1630 | } |
| 1631 | for (int i = 0; i < s->ndeps; i++) { |
| 1632 | const char *dq = dk_compose_qn(c, s->deps[i]); |
| 1633 | const cbm_gbuf_node_t *dep = dq ? cbm_gbuf_find_by_qn(c->ctx->gbuf, dq) : NULL; |
| 1634 | dk_compose_edge(c, self->id, dep ? dep->id : 0, "DEPENDS_ON", "{\"via\":\"depends_on\"}"); |
| 1635 | } |
| 1636 | dk_compose_connects(c, s, self->id); |
| 1637 | if (s->image) { |
| 1638 | char esc[CBM_SZ_1K]; |
| 1639 | cbm_json_escape(esc, (int)sizeof(esc), s->image); |
| 1640 | char props[CBM_SZ_2K]; |
| 1641 | snprintf(props, sizeof(props), "{\"ref\":\"image\",\"image\":\"%s\"}", esc); |
| 1642 | dk_compose_edge(c, self->id, cbm_pipeline_image_node(c->ctx, s->image), "USAGE", props); |
| 1643 | } |
| 1644 | if (s->dockerfile) { |
| 1645 | const char *mqn = cbm_fqn_module(c->a, c->ctx->project_name, s->dockerfile); |
| 1646 | const cbm_gbuf_node_t *mod = mqn ? cbm_gbuf_find_by_qn(c->ctx->gbuf, mqn) : NULL; |
| 1647 | if (mod && mod->file_path && strcmp(mod->file_path, s->dockerfile) == 0) { |
| 1648 | dk_compose_edge(c, self->id, mod->id, "DEPENDS_ON", |
| 1649 | "{\"via\":\"build\",\"tool\":\"compose\"}"); |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | /* The .env of the directory of `rel` under the repository, NULL when none. */ |
| 1655 | static char *dk_read_dotenv(const cbm_pipeline_ctx_t *ctx, const char *rel) { |
nothing calls this directly
no test coverage detected