diff --git a/.dagger/env/docs/.gitignore b/.dagger/env/docs/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/.dagger/env/docs/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/.dagger/env/docs/plan/main.cue b/.dagger/env/docs/plan/main.cue new file mode 100644 index 00000000..183b628d --- /dev/null +++ b/.dagger/env/docs/plan/main.cue @@ -0,0 +1,95 @@ +package main + +import ( + "encoding/json" + + "dagger.io/dagger" + "dagger.io/os" + + "dagger.io/js/yarn" + "dagger.io/git" + "dagger.io/docker" + + "dagger.io/aws" + "dagger.io/aws/s3" +) + +// dagger repository +repository: dagger.#Artifact @dagger(input) + +// docs version +version: string | *"devel" @dagger(input) + +// if repository is checked out at a tag, use it as the version +tag: git.#CurrentBranch & { + "repository": repository +} +if (tag.name & =~"^v") != _|_ { + version: tag.name +} + +// AWS credentials +awsConfig: aws.#Config @dagger(input) + +// Lint the markdowns +lint: os.#Container & { + image: docker.#Pull & { + from: "tmknom/markdownlint:0.23.1" + } + + command: "markdownlint ./docs" + dir: "/src" + mount: "/src": from: repository +} + +// Build the docs website +docs: yarn.#Package & { + source: repository + cwd: "./tools/gendocs" + buildDir: "./tools/gendocs/public" + args: ["--prefix-paths"] + env: VERSION: version +} + +// Upload to S3 +website: s3.#Sync & { + config: awsConfig + source: docs.build + delete: true + target: "s3://docs.dagger.io/\(version)/" +} + +// generate and upload a `tags.json` file for the navbar version selector +tags: git.#Tags & { + "repository": repository +} +versions: [ for name in tags.tags {tag: name}, { + tag: "devel" +}] + +versionsObject: s3.#Put & { + config: awsConfig + sourceInline: json.Marshal(versions) + contentType: "application/json" + target: "s3://docs.dagger.io/tags.json" +} + +// if we're building a release, redirect the docs website to this page +if version != "devel" { + redirect: s3.#Put & { + config: awsConfig + sourceInline: #""" + + + + + + + Nothing to see here; see the latest version of the docs. + + + """# + contentType: "text/html" + target: "s3://docs.dagger.io/index.html" + } +} diff --git a/.dagger/env/docs/values.yaml b/.dagger/env/docs/values.yaml new file mode 100644 index 00000000..27e3888f --- /dev/null +++ b/.dagger/env/docs/values.yaml @@ -0,0 +1,35 @@ +name: docs +inputs: + awsConfig.accessKey: + secret: ENC[AES256_GCM,data:/KR+mkBb51etyZqiQnl4kxIl4vw=,iv:lFBuaqK9MVr5fYGMM8bN/XyZ9/oUInDWvzhYuK8Yj20=,tag:sHwcSTJ1lKzIDRYzr4Z/yg==,type:str] + awsConfig.region: + text: us-east-1 + awsConfig.secretKey: + secret: ENC[AES256_GCM,data:0bHcnNwbKR2F+PKB/Xzs06zsvJHENPZHEcx9SUN3Sn2/fzf0fA2G2w==,iv:A306R2ldjigteL6c0jkvOxZbHtxhlobP2FuPknuf+N4=,tag:CvDqdrej34Kbh8Y7zG5O8Q==,type:str] + repository: + dir: + path: . + exclude: + - '**/node_modules' + - cmd/dagger/dagger + - cmd/dagger/dagger-debug +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBaZVVuYThsYk9YcWhYb0g4 + TDhZQ21YN0FCRExKV2tqbVVUNTg5MWRUVUJzCndjc28yVUZEK3ZoQzVDQkk4emZQ + WGx2bUxSZlBENXlibzQ1MVkvc2I2MVkKLS0tIFJKS0ZENFhuVmdUM2h1a2xrK01a + ejRKQXNFZzBTbUxpc05acnkxQ2U2UkEKX1byNj64xOiRGAJ9lwh55d/mlasI3H6H + b+o3HbXSbV0G0UwQxEOisntR6o27ry/l12ai/sOQ4f9MXm6FRw2XTg== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-05-29T02:37:17Z" + mac: ENC[AES256_GCM,data:mXlkcR6U0sQwXdk4mYMKmA6/tcZWVtQt76RVfYOj3uE89XgIUQhk5qts/fp8DMpOB90KZtUJB2Im2+ppqdhtKQO2xcp0Cj6WN1omYRdGbSAMBMPtIbbAdzMcZwvCScRvfDn1ecCSeHikTpDlvUImmoOJLH4ItvLq7JK3oUgPvUs=,iv:ckI70eAguY4p8eTI2W5Iws1zYaqkZuHcNWwjGBjbVYk=,tag:/hoRjWxK/5oxbmia4TgcKA==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/environment/pipeline.go b/environment/pipeline.go index a94de13f..08c4f74b 100644 --- a/environment/pipeline.go +++ b/environment/pipeline.go @@ -213,6 +213,8 @@ func (p *Pipeline) doOp(ctx context.Context, op *compiler.Value, st llb.State) ( return p.Local(ctx, op, st) case "load": return p.Load(ctx, op, st) + case "workdir": + return p.Workdir(ctx, op, st) case "subdir": return p.Subdir(ctx, op, st) case "docker-build": @@ -232,6 +234,14 @@ func (p *Pipeline) vertexNamef(format string, a ...interface{}) string { return prefix + " " + name } +func (p *Pipeline) Workdir(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) { + path, err := op.Lookup("path").String() + if err != nil { + return st, err + } + return st.Dir(path), nil +} + func (p *Pipeline) Subdir(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) { // FIXME: this could be more optimized by carrying subdir path as metadata, // and using it in copy, load or mount. diff --git a/stdlib/dagger/op/op.cue b/stdlib/dagger/op/op.cue index 3961e7e2..aeb94423 100644 --- a/stdlib/dagger/op/op.cue +++ b/stdlib/dagger/op/op.cue @@ -40,6 +40,11 @@ package op dir: string } +#Workdir: { + do: "workdir" + path: string +} + #Exec: { do: "exec" args: [...string] diff --git a/stdlib/dagger/op/op_fullop.cue b/stdlib/dagger/op/op_fullop.cue index fc763832..3fa35920 100644 --- a/stdlib/dagger/op/op_fullop.cue +++ b/stdlib/dagger/op/op_fullop.cue @@ -12,6 +12,7 @@ package op #Copy | #Load | #Subdir | + #Workdir | #WriteFile | #Mkdir | #DockerBuild) & {do: string} diff --git a/stdlib/git/git.cue b/stdlib/git/git.cue index 35713db0..aa07e4eb 100644 --- a/stdlib/git/git.cue +++ b/stdlib/git/git.cue @@ -1,7 +1,9 @@ package git import ( + "dagger.io/dagger" "dagger.io/dagger/op" + "dagger.io/alpine" ) // A git repository @@ -23,3 +25,82 @@ import ( }, ] } + +// Get the name of the current checked out branch or tag +#CurrentBranch: { + repository: dagger.#Artifact @dagger(input) + name: { + string + @dagger(output) + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: bash: "=~5.1" + package: git: "=~2.30" + } + }, + + op.#Exec & { + mount: "/repository": from: repository + dir: "/repository" + args: [ + "/bin/bash", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "-c", + #""" + printf "$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" > /name.txt + """#, + ] + }, + + op.#Export & { + source: "/name.txt" + format: "string" + }, + ] + } +} + +// List tags of a repository +#Tags: { + repository: dagger.#Artifact @dagger(input) + tags: { + [...string] + @dagger(output) + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: bash: "=~5.1" + package: jq: "=~1.6" + package: git: "=~2.30" + } + }, + + op.#Exec & { + mount: "/repository": from: repository + dir: "/repository" + args: [ + "/bin/bash", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "-c", + #""" + git tag -l | jq --raw-input --slurp 'split("\n") | map(select(. != ""))' > /tags.json + """#, + ] + }, + + op.#Export & { + source: "/tags.json" + format: "json" + }, + ] + } +}