-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Cue spec validation #170
Draft
adamperlin
wants to merge
9
commits into
Azure:main
Choose a base branch
from
adamperlin:cue-spec-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e63806a
Initial pass at modeling SPEC in cue, incomplete WIP
adamperlin 6ffd03b
Add updated spec.cue
adamperlin d902d2f
Add beginnings of cue_validate_test.go
adamperlin 4b3491d
Update spec.cue, add cue_validate unit tests, begin fixing test fixtures
adamperlin 6c66a76
Fix cue spec, cue_validate_test, and a few test fixtures
adamperlin ce2eac2
Update some comments and remove close(...) where it is already implicit
adamperlin a29a2e4
Fix source name regex
adamperlin c3deb6c
Add back uint as valid type for 'revision' in spec.cue
adamperlin 1c24808
Merge branch 'main' into cue-spec-validation
adamperlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
package spec | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// TODO: consider adding defaults to more fields | ||
|
||
// This alias exists for the sake of being explicit, and in case we want to add restrictions later | ||
// for what kind of filepaths we allow in Dalec | ||
let filepath = string | ||
|
||
// {0, ..., 511} = {0o000, ..., 0o777} are valid unix perms | ||
let perms = >= 0 & <= 0o777 | ||
|
||
// A source name must be alphanumeric, with the inclusion of '_', '-', and '.' | ||
let sourceName = =~ "^[a-zA-Z0-9-._]+$" | ||
|
||
#BuildStep: { | ||
command: string | ||
env?: [string]: string | ||
} | ||
|
||
#CacheDirConfig: { | ||
mode?: "shared" | "private" | "locked" | ||
key?: string | ||
include_distro_key?: bool | ||
include_arch_key?: bool | ||
} | ||
|
||
#Command: { | ||
dir?: filepath | ||
mounts?: [...#SourceMount] | ||
cache_dirs?: [filepath]: #CacheDirConfig | ||
env?: [string]: string | ||
steps: [...#BuildStep] | ||
} | ||
|
||
#SourceMount: { | ||
dest: filepath | ||
// structural cycle formed by source.image.mounts.spec.source must terminate somehow for cue to accept | ||
// even though there are non-recursive source variants so there is implicitly a base case, | ||
// cue's cycle detection is not currently buggy in this case | ||
spec: null | #Source | ||
} | ||
|
||
#SourceContext: { | ||
name?: string | ||
} | ||
|
||
#SourceDockerImage: { | ||
ref: string | ||
cmd?: #Command | ||
} | ||
|
||
#SourceHTTP: { | ||
// TODO: specify url field further? | ||
url: string | ||
} | ||
|
||
#SourceBuild: { | ||
source?: #SubSource | ||
dockerfile_path?: filepath | ||
target?: string | ||
args?: [string]: string | ||
} | ||
|
||
#SourceGit: { | ||
// TODO: specify URL field further? | ||
url: string | ||
commit?: string | ||
keepGitDir?: bool | ||
} | ||
|
||
#SourceInlineFile: { | ||
contents?: string | ||
permissions?: perms | ||
uid?: >= 0 | ||
gid?: >= 0 | ||
} | ||
|
||
#SourceInlineDir: { | ||
files?: [sourceName]: #SourceInlineFile | ||
permissions?: perms | ||
uid?: >= 0 | ||
gid?: >= 0 | ||
} | ||
|
||
#SourceInlineVariant: { file: #SourceInlineFile } | | ||
{ dir: #SourceInlineDir } | ||
#SourceInline: { inline: #SourceInlineVariant } | ||
|
||
#SourceVariant: { context: #SourceContext } | | ||
{ git: #SourceGit } | | ||
{ build: #SourceBuild } | | ||
{ http: #SourceHTTP } | | ||
{ image: #SourceDockerImage } | | ||
{ inline: #SourceInlineVariant } | ||
|
||
// these are sources which are suitable as a sub-source for | ||
// SourceBuild's .source | ||
#SubSourceVariant: { context: #SourceContext } | | ||
{ git: #SourceGit } | | ||
{ http: #SourceHTTP } | | ||
{ image: #SourceDockerImage } | | ||
#SourceInline | ||
|
||
// base properties which are source-independent | ||
#SourceBase: { path?: filepath | ||
includes?: [...string] | ||
excludes?: [...string] | ||
} | ||
|
||
#Source: {#SourceBase, #SourceVariant} | ||
#SubSource: {#SourceBase, #SubSourceVariant} | ||
|
||
#PackageDependencies: { | ||
build?: [string]: (null | [...string]) | ||
runtime?: [string]: (null | [...string]) | ||
recommends?: [string]: (null | [...string]) | ||
test?: [string]: (null | [...string]) | ||
} | ||
|
||
#ArtifactBuild: { | ||
steps: [...#BuildStep] | ||
env?: [string]: string | ||
} | ||
|
||
#ArtifactConfig: { | ||
subpath?: filepath | ||
name?: string | ||
} | ||
|
||
#Artifacts: { | ||
binaries?: [filepath]: (null | #ArtifactConfig) | ||
manpages?: [filepath]: (null | #ArtifactConfig) | ||
} | ||
|
||
#CheckOutput: { | ||
equals?: string | ||
contains?: [...string] | ||
matches?: string | ||
starts_with?: string | ||
ends_with?: string | ||
empty?: bool | ||
} | ||
|
||
#TestStep: { | ||
command?: string | ||
env?: [string]: string | ||
stdout?: #CheckOutput | ||
stderr?: #CheckOutput | ||
stdin?: string | ||
} | ||
|
||
#FileCheckOutput: { | ||
#CheckOutput | ||
permissions?: perms | ||
is_dir?: bool | ||
not_exist?: bool | ||
} | ||
|
||
#TestSpec: { | ||
name: string | ||
dir?: filepath | ||
mounts?: [...#SourceMount] | ||
cacheDirs?: [string]: #CacheDirConfig | ||
env?: [string]: string | ||
steps: [...#TestStep] | ||
files?: [filepath]: (null | #FileCheckOutput) | ||
} | ||
|
||
#SymlinkTarget: { | ||
path: filepath | ||
} | ||
|
||
#PostInstall: { | ||
symlinks?: [filepath]: #SymlinkTarget | ||
} | ||
|
||
#ImageConfig: { | ||
entrypoint?: string | ||
cmd?: string | ||
env?: [...string] | ||
labels?: [string]: string | ||
volumes?: [string]: null | ||
working_dir?: string | ||
stop_signal?: string | ||
base?: string | ||
post?: #PostInstall | ||
user?: string | ||
} | ||
|
||
#Frontend: { | ||
image: string | ||
cmdline?: string | ||
} | ||
|
||
#Target: { | ||
dependencies?: (null | #PackageDependencies) | ||
image?: #ImageConfig | ||
frontend?: #Frontend | ||
tests?: [...#TestSpec] | ||
} | ||
|
||
#PatchSpec: { | ||
source: sourceName | ||
strip?: int | ||
} | ||
|
||
#ChangelogEntry: { | ||
date: time.Time | ||
author: string | ||
changes: [...string] | ||
} | ||
|
||
#Spec: { | ||
name: string | *"My Package" | ||
description: string | *"My Dalec Package" | ||
website?: string | ||
version: string | *"0.1" | ||
revision: uint | string | *"1" | ||
noarch?: bool | ||
|
||
conflicts?: [string]: (null | [...string]) | ||
replaces?: [string]: (null | [...string]) | ||
provides?: [...string] | ||
|
||
sources?: [sourceName]: #Source | ||
|
||
patches?: [sourceName]: [...#PatchSpec] | ||
|
||
build?: #ArtifactBuild | ||
|
||
// TODO: could probably validate magic variables here, | ||
// TARGET* vars should not have any default values applied | ||
args?: [string]: (string | int | null) | ||
|
||
license: string | *"Needs License" | ||
|
||
vendor: string | *"My Vendor" | ||
|
||
packager: string | *"Azure Container Upstream" | ||
|
||
artifacts?: #Artifacts | ||
|
||
targets?: [string]: #Target | ||
|
||
dependencies?: #PackageDependencies | ||
|
||
image?: #ImageConfig | ||
|
||
changelog?: [...#ChangelogEntry] | ||
|
||
tests?: [...#TestSpec] | ||
} | ||
|
||
#Spec |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is definitely worthwhile to capture all of the defaults in this PR. We actually have extensive defaults, mostly undocumented.