Done with the repository layout

This commit is contained in:
Hoang Nguyen 2023-12-11 00:00:00 +07:00
parent 0041771955
commit 0629cfc453
Signed by: folliehiyuki
GPG key ID: B0567C20730E9B11
15 changed files with 117 additions and 40 deletions

View file

@ -18,8 +18,6 @@ module(
# )
# use_repo(nix_repo, "nixpkgs")
# TODO: enable `nogo` linters (doesn't support bzlmod yet)
# Ref: https://github.com/bazelbuild/rules_go/issues/3529
bazel_dep(name = "rules_go", version = "0.43.0")
# FIXME: temporarily use the Go SDK from host, until we have rules_nixpkgs_go

View file

@ -8,9 +8,19 @@ This project generates CUE schemas for Pulumi providers, based on `+schema.json+
See link:./examples[examples/] directory for some use cases.
== Providers
== Tools
Except link:./providers/pulumi[`+pulumi+`] package, which implements base schema for `+Pulumi.yaml+` file, all CUE packages inside link:./providers[providers/] directory are auto-generated. See link:./tools/pulumi-schemas/providers.toml[providers.toml] file for the full list of providers and their JSON schema sources.
* **cue-pulumi-gen**: a program to generate CUE definitions for Pulumi providers' JSON schemas inside link:./schemata/providers[schemata/providers/] directory
* **pulumi-schema**: a simple command to conveniently print out `+schema.json+` file, given a Pulumi proivder's name
== Schema packages
All CUE packages inside link:./schemata/providers[schemata/providers/] directory are auto-generated. See link:./internal/schema/providers.toml[providers.toml] file for the full list of providers and their JSON schema sources.
link:./schemata/pulumi[schemata/pulumi] defines CUE schema for:
* `Pulumi.yaml` in link:./schemata/pulumi/pulumi.cue[pulumi.cue]. It is extended upon https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/pulumi.json with support for `+pulumi-yaml+` definitions.
* `schema.json` (package metaschema) for a Pulumi provider in link:./schemata/pulumi/package.cue[package.cue]. The CUE definition is imported by `+cue+` CLI from https://github.com/pulumi/pulumi/blob/master/pkg/codegen/schema/pulumi.json.
== Reference
@ -23,10 +33,3 @@ Existing projects, which inspires me to create this one:
* https://github.com/tweag/tf-ncl[tf-ncl]
* https://github.com/tnarg/cue_terraform[cue_terraform]
== Roadmap
Things to implement (yeah, there are a lot \^-\^)
* [ ] Use https://github.com/tweag/rules_nixpkgs[rules_nixpkgs]
* [ ] Ditch `+go.mod+` file and `+golangci-lint+` (solely rely on `+nogo+` and GOPACKAGEDIRVER)

View file

@ -13,6 +13,6 @@ cue_consolidated_files(
module = "//cue.mod:cuelumi",
output_format = "yaml",
deps = [
"//providers/pulumi",
"//schemata/pulumi",
],
)

View file

@ -5,7 +5,7 @@
package main
import (
"gitlab.com/FollieHiyuki/cuelumi/providers/pulumi"
"gitlab.com/FollieHiyuki/cuelumi/schemata/pulumi"
)
name: pulumi.#Name & "cuelumi-examples"

View file

@ -26,15 +26,52 @@
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
# Information to be put into reuse's arguments
copyright = "Hoang Nguyen <folliekazetani@protonmail.com>";
licenses = [ "Apache-2.0" "CC0-1.0" ];
apps = {
# Wrap bazel with `nix run .#bazel`, for convenience
inherit (pkgs) bazel;
# Run `go mod tidy` then update BUILD.bazel files
gazelle = let bazel = "${pkgs.bazel}/bin/bazel"; in
pkgs.writeShellScriptBin "gazelle-update" ''
${bazel} run @rules_go//go -- mod tidy -v
${bazel} run //:gazelle
gazelle =
let
arguments = [
[ "@rules_go//go" "--" "mod" "tidy" "-v" ]
[ "//:gazelle" ]
];
in
pkgs.writeShellScriptBin "gazelle-update" (with lib; concatStringsSep "\n"
(forEach
arguments
(x: "${pkgs.bazel}/bin/bazel run " + (concatStringsSep " " x))
)
);
# FIXME: doesn't work yet (https://github.com/cue-lang/cue/issues/2654)
package-metaschema = with pkgs;
writeShellScriptBin "package-metaschema" ''
set -e
INPUT_SCHEMA=/tmp/pulumi.json
OUTFILE=./schemata/pulumi/package.cue
${curl}/bin/curl -fsSL \
-o "$INPUT_SCHEMA" \
https://raw.githubusercontent.com/pulumi/pulumi/master/pkg/codegen/schema/pulumi.json
${cue}/bin/cue import --force \
--package="pulumi" \
--path="#Package" \
--outfile="$OUTFILE" \
"$INPUT_SCHEMA"
# Re-add the SPDX header, to make `reuse lint` happy
${reuse}/bin/reuse annotate \
--copyright="${copyright}" \
--license="${builtins.elemAt licenses 0}" \
--style=c \
"$OUTFILE"
'';
};
in

View file

@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
load("@rules_go//go:def.bzl", "go_library")
go_library(
name = "schema",
srcs = ["metadata.go"],
importpath = "gitlab.com/FollieHiyuki/cuelumi/internal/schema",
visibility = ["//:__subpackages__"],
)

View file

@ -0,0 +1,7 @@
/*
* SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
package schema

View file

@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
# For the list of existing Pulumi proivders, see https://www.pulumi.com/registry/
[aci]
type = "github"
version = "v0.0.6"
repository = "https://github.com/netascode/pulumi-aci"
schema_path = "provider/cmd/pulumi-resource-aci/schema.json"
[acme]
type = "github"
version = "v0.0.1"
repository = "https://github.com/pulumiverse/pulumi-acme"
schema_path = "provider/cmd/pulumi-resource-acme/schema.json"
[aiven]
type = "github"
version = "v6.7.2"
repository = "https://github.com/pulumi/pulumi-aiven"
schema_path = "provider/cmd/pulumi-resource-aiven/schema.json"

View file

@ -1,14 +0,0 @@
// SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
//
// SPDX-License-Identifier: Apache-2.0
// This package implements schema for the base Pulumi.yaml file.
// It extends https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/pulumi.json with support for pulumi-yaml definitions.
// Ref: https://www.pulumi.com/docs/languages-sdks/yaml/yaml-language-reference/
package pulumi
#Name: string
#Runtime: string
#Description: string

View file

@ -7,7 +7,8 @@ load("@rules_cue//cue:cue.bzl", "cue_instance")
cue_instance(
name = "pulumi",
srcs = [
"main.cue",
"package.cue",
"pulumi.cue",
],
ancestor = "//cue.mod:cuelumi",
visibility = ["//visibility:public"],

View file

@ -0,0 +1,3 @@
// SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
//
// SPDX-License-Identifier: Apache-2.0

View file

@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
//
// SPDX-License-Identifier: Apache-2.0
package pulumi
#Name: string
#Runtime: string
#Description: string

View file

@ -5,14 +5,14 @@
load("@rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "pulumi-schemas_lib",
name = "pulumi-schema_lib",
srcs = ["main.go"],
importpath = "gitlab.com/FollieHiyuki/cuelumi/tools/pulumi-schemas",
importpath = "gitlab.com/FollieHiyuki/cuelumi/tools/pulumi-schema",
visibility = ["//visibility:private"],
)
go_binary(
name = "pulumi-schemas",
embed = [":pulumi-schemas_lib"],
name = "pulumi-schema",
embed = [":pulumi-schema_lib"],
visibility = ["//visibility:public"],
)

View file

@ -1,4 +0,0 @@
# SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0