From f89fa3f159c9bf44d0a5319eb11e36a2ffec9c41 Mon Sep 17 00:00:00 2001 From: xyny <60004820+xynydev@users.noreply.github.com> Date: Sat, 27 Jul 2024 14:31:52 +0000 Subject: [PATCH] fix: add typespec schemas for cli modules, remove modules.json (not needed anymore) (#209) The website build process now uses the GitHub API to generate a global `modules.json`. If you decide to move the directory containing all the modules, please tell me, or make a PR changing [this line](https://github.com/blue-build/website/blob/9eb198c4e532e82e70b980da955b87f39ce663b4/astro.config.mjs#L102). If you don't, I'll find out anyways, because the website builds will break. Also, whenever updating the modules, make sure the schema is updated too to match the current state of the module. If you need help with writing [TypeSpec](https://typespec.io/), consult me, but you probably wont, since it's just a type system kind of like TypeScript's or Rust's . --- modules.json | 4 ---- .../modules/containerfile/containerfile.tsp | 16 ++++++++++++++ .../modules/containerfile/module.yml | 1 - template/templates/modules/copy/README.md | 4 ++-- template/templates/modules/copy/copy.tsp | 21 +++++++++++++++++++ template/templates/modules/copy/module.yml | 1 - 6 files changed, 39 insertions(+), 8 deletions(-) delete mode 100644 modules.json create mode 100644 template/templates/modules/containerfile/containerfile.tsp create mode 100644 template/templates/modules/copy/copy.tsp diff --git a/modules.json b/modules.json deleted file mode 100644 index 3c5d30e..0000000 --- a/modules.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "https://raw.githubusercontent.com/blue-build/cli/main/template/templates/modules/containerfile/module.yml", - "https://raw.githubusercontent.com/blue-build/cli/main/template/templates/modules/copy/module.yml" -] \ No newline at end of file diff --git a/template/templates/modules/containerfile/containerfile.tsp b/template/templates/modules/containerfile/containerfile.tsp new file mode 100644 index 0000000..dfdf170 --- /dev/null +++ b/template/templates/modules/containerfile/containerfile.tsp @@ -0,0 +1,16 @@ +import "@typespec/json-schema"; +using TypeSpec.JsonSchema; + +@jsonSchema("/modules/containerfile.json") +model ContainerfileModule { + /** The containerfile module is a tool for adding custom Containerfile instructions for custom image builds. + * https://blue-build.org/reference/modules/containerfile/ + */ + type: "containerfile"; + + /** Lines to directly insert into the generated Containerfile. */ + snippets?: Array; + + /** Names of directories in ./containerfiles/ containing each a Containerfile to insert into the generated Containerfile. */ + containerfiles?: Array; +} \ No newline at end of file diff --git a/template/templates/modules/containerfile/module.yml b/template/templates/modules/containerfile/module.yml index 67e3faa..4a285bc 100644 --- a/template/templates/modules/containerfile/module.yml +++ b/template/templates/modules/containerfile/module.yml @@ -1,6 +1,5 @@ name: containerfile shortdesc: The containerfile module enables the addition of custom Containerfile instructions into the build process. -readme: https://raw.githubusercontent.com/blue-build/cli/main/template/templates/modules/containerfile/README.md example: | type: containerfile snippets: diff --git a/template/templates/modules/copy/README.md b/template/templates/modules/copy/README.md index 6c525dc..a35ba9b 100644 --- a/template/templates/modules/copy/README.md +++ b/template/templates/modules/copy/README.md @@ -15,7 +15,7 @@ The `copy` module is a short-hand method of adding a [`COPY`](https://docs.docke The `copy` module's properties are a 1-1 match with the `COPY` instruction containing `src`, `dest`, and `from` (optional). The example below will `COPY` the file `/usr/bin/yq` from `docker.io/mikefarah/yq` into `/usr/bin/`. ```yaml -mdoules: +modules: - type: copy from: docker.io/mikefarah/yq src: /usr/bin/yq @@ -31,7 +31,7 @@ COPY --linked --from=docker.io/mikefarah/yq /usr/bin/yq /usr/bin/ Omitting `from:` will allow copying from the build context: ```yaml -mdoules: +modules: - type: copy src: file/to/copy.conf dest: /usr/etc/app/ diff --git a/template/templates/modules/copy/copy.tsp b/template/templates/modules/copy/copy.tsp new file mode 100644 index 0000000..0848d74 --- /dev/null +++ b/template/templates/modules/copy/copy.tsp @@ -0,0 +1,21 @@ +import "@typespec/json-schema"; +using TypeSpec.JsonSchema; + +@jsonSchema("/modules/copy.json") +model CopyModule { + /** The copy module is a short-hand method of adding a COPY instruction into the Containerfile. + * https://blue-build.org/reference/modules/copy/ + */ + type: "containerfile"; + + /** Equivalent to the --from property in a COPY statement, use to specify an image to copy from. + * By default, the COPY source is the build environment's file tree. + */ + from?: string; + + /** Path to source file or directory. */ + src: string; + + /** Path to destination file or directory. */ + dest: string; +} \ No newline at end of file diff --git a/template/templates/modules/copy/module.yml b/template/templates/modules/copy/module.yml index 2179b6f..2477ba5 100644 --- a/template/templates/modules/copy/module.yml +++ b/template/templates/modules/copy/module.yml @@ -1,6 +1,5 @@ name: copy shortdesc: The copy module is a direct translation of the `COPY` instruction in a Containerfile. -readme: https://raw.githubusercontent.com/blue-build/cli/main/template/templates/modules/copy/README.md example: | type: copy from: docker.io/mikefarah/yq