Skip to content

Instantly share code, notes, and snippets.

@applejag
Last active November 9, 2020 15:45
Show Gist options
  • Save applejag/07bcb76f86bcca3a398d42a51b3d303f to your computer and use it in GitHub Desktop.
Save applejag/07bcb76f86bcca3a398d42a51b3d303f to your computer and use it in GitHub Desktop.
JSON/YAML schema for .wharf-ci.yml files

The language server from Red Hat, that most editors use to have YAML syntax and intellisense, has support for JSON schemas.

This file is an attempt on such a schema. Would be nice to autogenerate these in the future, but having it at all is a nice first step. We might want to move this into the https://gitlab.dgc.local/tools/wharf-project project group, and optionally deploy and version this together with the https://gitlab.dgc.local/tools/wharf-project/cmd project...

How to use in Visual Studio Code

  1. Install the "YAML" extension (id: redhat.vscode-yaml, link: https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml)

  2. Add the following to your user settings:

        "yaml.schemas":{
            "https://gist.githubusercontent.com/jilleJr/07bcb76f86bcca3a398d42a51b3d303f/raw/5aec3157fbc1aecfb88fe3126c1e072bb40eba4f/wharf-ci-schema.json": [
                ".wharf-ci.yml",
                ".dgc-ci.yml",
            ]
        },
  3. Done! Open any .wharf-ci.yml file in some project and see it in action. Preview:

    image

How to use in GoLand

I've not found direct documentation of this, but it is possible according to the documentation to specify JSON schemas (as seen here: https://www.jetbrains.com/help/go/json.html#ws_json_schema_add_custom). RubyMine has documentation on specifying custom schemas (https://www.jetbrains.com/help/ruby/yaml.html#remote_json) so I'm thinking it could be possible, if you were so inclined to look for it in the settings. I do not have GoLand installed so I cannot verify.

Why on public gist.github.com, instead of gitlab.dgc.local

Certificate issues. Some editors (such as VS Code) has their own certificate stores instead of using the systems certificate store. Instead of trying to work with that I just posted it here instead.

{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Wharf configuration schema (.wharf-ci.yml)",
"type": "object",
"properties": {
"environments": {
"type": "object",
"title": "Wharf build environment variables definitions",
"description": "Wharf environment variables per environment available when starting a build for this project. The 'environments' property inside each stage refers to the property name as defined here directly under this global 'environments' map/object.",
"additionalProperties": {
"type": "object",
"title": "Map/object of environment variables",
"description": "Each variable defined here can later be used inside most fields and inside referenced files (for example, inside kubectl.file) when written in the format of ${name-of-variable}. A simple string substitution is performed in values and files inside the steps.",
"additionalProperties": {
"type": [
"boolean",
"integer",
"number",
"string"
]
}
}
},
"inputs": {
"title": "Input variables",
"description": "When starting a build via Wharf, you have the option to fill out input variables that are defined here.",
"type": "array",
"items": {
"type": "object",
"anyOf": [
{
"title": "Choice input",
"description": "Let's the user choose between the given options defined in the 'values' property.",
"type": "object",
"additionalProperties": false,
"required": [
"type",
"name",
"values"
],
"properties": {
"type": {
"title": "Input type",
"type": "string",
"const": "choice"
},
"name": {
"title": "Input name",
"description": "This name is what's shown in the front-end for the user, as well as being available as a variable to be used inside most fields and inside referenced files (for example, inside kubectl.file) when written in the format of ${name-of-variable}. A simple string substitution is performed in values and files inside the steps.",
"type": "string"
},
"default": {
"title": "Input default value",
"description": "Default value that is pre-populated in the input in the front-end for the user when they start a new build.",
"type": "string"
},
"values": {
"title": "Input options for 'choose' type",
"description": "An array of string values that the user is presented with to choose between.",
"type": "array",
"items": {
"type": "string"
}
}
}
},
{
"title": "String/text input",
"description": "Let's the user enter a value in a free text input field.",
"type": "object",
"additionalProperties": false,
"required": [
"type",
"name"
],
"properties": {
"type": {
"title": "Input type",
"type": "string",
"const": "string"
},
"name": {
"title": "Input name",
"description": "This name is what's shown in the front-end for the user, as well as being available as a variable to be used inside most fields and inside referenced files (for example, inside kubectl.file) when written in the format of ${name-of-variable}. A simple string substitution is performed in values and files inside the steps.",
"type": "string"
},
"default": {
"title": "Input default value",
"description": "Default value that is pre-populated in the input in the front-end for the user when they start a new build.",
"type": "string"
}
}
},
{
"title": "Password input",
"description": "Let's the user enter a value in a free text input field, but where the input is masked in the front-end. Semantically identical to the 'string' input type.",
"type": "object",
"additionalProperties": false,
"required": [
"type",
"name"
],
"properties": {
"type": {
"title": "Input type",
"type": "string",
"const": "password"
},
"name": {
"title": "Input name",
"description": "This name is what's shown in the front-end for the user, as well as being available as a variable to be used inside most fields and inside referenced files (for example, inside kubectl.file) when written in the format of ${name-of-variable}. A simple string substitution is performed in values and files inside the steps.",
"type": "string"
},
"default": {
"title": "Input default value",
"description": "Default value that is pre-populated in the input in the front-end for the user when they start a new build.",
"type": "string"
}
}
},
{
"title": "Number input",
"description": "Let's the user enter a numeric value.",
"type": "object",
"additionalProperties": false,
"required": [
"type",
"name"
],
"properties": {
"type": {
"title": "Input type",
"type": "string",
"const": "number"
},
"name": {
"title": "Input name",
"description": "This name is what's shown in the front-end for the user, as well as being available as a variable to be used inside most fields and inside referenced files (for example, inside kubectl.file) when written in the format of ${name-of-variable}. A simple string substitution is performed in values and files inside the steps.",
"type": "string"
},
"default": {
"title": "Input default value",
"description": "Default value that is pre-populated in the input in the front-end for the user when they start a new build.",
"type": [
"number",
"integer"
]
}
}
}
]
}
}
},
"additionalProperties": {
"title": "Wharf build stage",
"description": "A build stage map/object. All stages will run in sequence of each other, and all stages shall include one or more build step. Build steps inside a build stage is specified by adding steps to this map/object.",
"type": "object",
"additionalProperties": {
"title": "Wharf build step",
"description": "Map/object for a Wharf build step. All steps are run in parallell of the other steps inside the same build stage. Specify the step type by adding a property inside this build step, for example 'container'. Build steps can only contain 1 step type.",
"type": "object",
"maxProperties": 1,
"additionalProperties": false,
"properties": {
"docker": {
"title": "Docker build step type",
"description": "Build an image from a Dockerfile and push to a registry.",
"type": "object",
"additionalProperties": false,
"required": [
"file",
"tag"
],
"properties": {
"file": {
"type": "string",
"examples": [
"src/api/Dockerfile"
]
},
"tag": {
"type": "string",
"examples": [
"latest,${GIT_COMMIT},${GIT_TAG}"
]
},
"name": {
"type": "string"
},
"group": {
"type": "string",
"default": "default"
},
"context": {
"type": "string",
"default": ".",
"examples": [
"src/api"
]
},
"secret": {
"type": "string"
},
"registry": {
"type": "string",
"default": "https://harbor.dgc.local"
},
"append-cert": {
"type": "boolean"
},
"push": {
"type": "boolean",
"default": true
},
"args": {
"type": "array",
"items": {
"type": "string"
},
"examples": [
[
"FIRST_ARG=Value from '.wharf-ci.yml' file!",
"SECOND_ARG=12453125"
]
]
}
}
},
"container": {
"title": "Container build step type",
"description": "Run commands in a container.",
"type": "object",
"additionalProperties": false,
"required": [
"image",
"cmds"
],
"properties": {
"image": {
"type": "string",
"examples": [
"alpine:latest"
]
},
"cmds": {
"type": "array",
"items": {
"type": "string"
},
"examples": [
[
"echo 'hello world'"
]
]
},
"os": {
"type": "string",
"default": "linux",
"enum": [
"linux",
"windows"
]
},
"shell": {
"type": "string",
"examples": [
"/bin/sh"
]
},
"certificatesMountPath": {
"type": "string",
"examples": [
"/usr/local/share/ca-certificates"
]
},
"secretName": {
"type": "string",
"examples": [
"spark-system-tests-secret"
]
}
}
},
"kubectl": {
"title": "Kubectl build step type",
"description": "Run `kubectl apply -f` on a Kubernetes manifest.",
"type": "object",
"additionalProperties": false,
"required": [
"namespace"
],
"properties": {
"file": {
"type": "string",
"examples": [
"deploy/api.yaml"
]
},
"files": {
"type": "array",
"items": {
"type": "string"
},
"examples": [
[
"deploy/api.yaml"
]
]
},
"namespace": {
"type": "string",
"examples": [
"stage"
]
},
"action": {
"type": "string",
"default": "apply",
"examples": [
"apply",
"create",
"patch",
"delete"
]
},
"force": {
"type": "boolean",
"default": false
},
"cluster": {
"type": "string",
"examples": [
"kubectl-config",
"hybrid-config",
"dev-config"
]
}
}
},
"helm": {
"title": "Helm-deploy build step type",
"description": "Install or upgrade a helm-chart.",
"type": "object",
"additionalProperties": false,
"required": [
"chart",
"name",
"namespace"
],
"properties": {
"chart": {
"type": "string",
"examples": [
"web-app"
]
},
"name": {
"type": "string",
"examples": [
"test-deploy"
]
},
"namespace": {
"type": "string",
"examples": [
"stage"
]
},
"repo": {
"type": "string",
"default": "https://harbor.dgc.local/chartrepo"
},
"set": {
"type": "array",
"items": {
"type": "object",
"minProperties": 1,
"maxProperties": 1
},
"examples": [
[
{
"image.tag": "latest"
}
]
]
},
"files": {
"type": "array",
"items": {
"type": "string"
},
"examples": [
[
"deploy/values.yaml"
]
]
},
"chartVersion": {
"type": "string",
"examples": [
"0.1.22"
]
},
"helmVersion": {
"type": "string",
"examples": [
"v2.14.1",
"v3.0.2",
"v3.2.0",
"latest"
]
},
"cluster": {
"type": "string",
"examples": [
"kubectl-config",
"hybrid-config",
"dev-config"
]
}
}
},
"helm-package": {
"title": "Helm-package build step type",
"description": "Packages a sub-folder or repo into a helm-chart and pushes it to a chart-repository.",
"type": "object",
"additionalProperties": false,
"required": [
"version",
"chart-path"
],
"properties": {
"version": {
"type": "string",
"examples": [
"${GIT_TAG}"
]
},
"chart-path": {
"type": "string",
"examples": [
"/web-app"
]
},
"destination": {
"type": "string",
"default": "https://harbor.dgc.local/chartrepo/default"
}
}
},
"nuget-package": {
"title": "NuGet-package build step type",
"description": "Packages a .NET project into a NuGet and pushes it to a NuGet-repository.",
"type": "object",
"additionalProperties": false,
"required": [
"project-path",
"version",
"repo"
],
"properties": {
"project-path": {
"type": "string",
"examples": [
"src/Iver.Spark.Service.Api.Client"
]
},
"version": {
"type": "string",
"examples": [
"${GIT_TAG}"
]
},
"repo": {
"type": "string",
"examples": [
"http://nuget.dgc.local/libs/api/v2/package"
]
}
}
}
}
},
"properties": {
"environments": {
"title": "Environments filter",
"description": "Optionally specify an array of Wharf environment names, as specified in the global 'environments' map/object. If specified then only if the given environment that was used to start the build is included in this array, will this stage execute. Otherwise this stage will be skipped.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
},
"uniqueItems": true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment