Adds support for op.#FetchHTTP

Signed-off-by: Edgar Lee <edgarhinshunlee@gmail.com>
This commit is contained in:
Edgar Lee 2021-07-06 14:29:36 -07:00 committed by Edgar Lee
parent 7146223ec7
commit 0501ae91a5
7 changed files with 99 additions and 0 deletions

View File

@ -82,6 +82,16 @@ _No input._
_No output._
## op.#FetchHTTP
### op.#FetchHTTP Inputs
_No input._
### op.#FetchHTTP Outputs
_No output._
## op.#Load
### op.#Load Inputs

View File

@ -19,6 +19,7 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
bkgw "github.com/moby/buildkit/frontend/gateway/client"
bkpb "github.com/moby/buildkit/solver/pb"
digest "github.com/opencontainers/go-digest"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v3"
@ -209,6 +210,8 @@ func (p *Pipeline) doOp(ctx context.Context, op *compiler.Value, st llb.State) (
return p.PushContainer(ctx, op, st)
case "fetch-git":
return p.FetchGit(ctx, op, st)
case "fetch-http":
return p.FetchHTTP(ctx, op, st)
case "local":
return p.Local(ctx, op, st)
case "load":
@ -817,6 +820,55 @@ func (p *Pipeline) FetchGit(ctx context.Context, op *compiler.Value, st llb.Stat
), nil
}
func (p *Pipeline) FetchHTTP(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) {
link, err := op.Lookup("url").String()
if err != nil {
return st, err
}
linkRedacted := link
if u, err := url.Parse(link); err == nil {
linkRedacted = u.Redacted()
}
httpOpts := []llb.HTTPOption{}
var opts struct {
Checksum string
Filename string
Mode int64
UID int
GID int
}
if err := op.Decode(&opts); err != nil {
return st, err
}
if opts.Checksum != "" {
dgst, err := digest.Parse(opts.Checksum)
if err != nil {
return st, err
}
httpOpts = append(httpOpts, llb.Checksum(dgst))
}
if opts.Filename != "" {
httpOpts = append(httpOpts, llb.Filename(opts.Filename))
}
if opts.Mode != 0 {
httpOpts = append(httpOpts, llb.Chmod(fs.FileMode(opts.Mode)))
}
if opts.UID != 0 && opts.GID != 0 {
httpOpts = append(httpOpts, llb.Chown(opts.UID, opts.GID))
}
httpOpts = append(httpOpts, llb.WithCustomName(p.vertexNamef("FetchHTTP %s", linkRedacted)))
return llb.HTTP(
link,
httpOpts...,
), nil
}
func (p *Pipeline) DockerBuild(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) {
var (
dockerContext = op.Lookup("context")

View File

@ -85,6 +85,16 @@ package op
authHeaderSecret?: string | bytes
}
#FetchHTTP: {
do: "fetch-http"
url: string
checksum?: string
filename?: string
mode?: int | *0o644
uid?: int
gid?: int
}
#Copy: {
do: "copy"
from: _

View File

@ -7,6 +7,7 @@ package op
#FetchContainer |
#PushContainer |
#FetchGit |
#FetchHTTP |
#Exec |
#Local |
#Copy |

View File

@ -113,6 +113,14 @@ setup() {
# assert_failure
}
@test "op.#FetchHTTP" {
run "$DAGGER" compute "$TESTDIR"/ops/fetch-http/exist
assert_success
run "$DAGGER" compute "$TESTDIR"/ops/fetch-http/nonexistent
assert_failure
}
@test "op.#Exec" {
run "$DAGGER" compute "$TESTDIR"/ops/exec/invalid
assert_failure

View File

@ -0,0 +1,9 @@
package testing
import "alpha.dagger.io/dagger/op"
#up: [
op.#FetchHTTP & {
url: "https://releases.dagger.io/dagger/latest_version"
},
]

View File

@ -0,0 +1,9 @@
package testing
import "alpha.dagger.io/dagger/op"
#up: [
op.#FetchHTTP & {
url: "https://releases.dagger.io/dagger/nonexistent_version"
},
]