Merge pull request #789 from hinshun/fetch-http
Adds support for op.#FetchHTTP
This commit is contained in:
commit
21bed8aee6
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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: _
|
||||
|
@ -7,6 +7,7 @@ package op
|
||||
#FetchContainer |
|
||||
#PushContainer |
|
||||
#FetchGit |
|
||||
#FetchHTTP |
|
||||
#Exec |
|
||||
#Local |
|
||||
#Copy |
|
||||
|
@ -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
|
||||
|
9
tests/ops/fetch-http/exist/main.cue
Normal file
9
tests/ops/fetch-http/exist/main.cue
Normal file
@ -0,0 +1,9 @@
|
||||
package testing
|
||||
|
||||
import "alpha.dagger.io/dagger/op"
|
||||
|
||||
#up: [
|
||||
op.#FetchHTTP & {
|
||||
url: "https://releases.dagger.io/dagger/latest_version"
|
||||
},
|
||||
]
|
9
tests/ops/fetch-http/nonexistent/main.cue
Normal file
9
tests/ops/fetch-http/nonexistent/main.cue
Normal file
@ -0,0 +1,9 @@
|
||||
package testing
|
||||
|
||||
import "alpha.dagger.io/dagger/op"
|
||||
|
||||
#up: [
|
||||
op.#FetchHTTP & {
|
||||
url: "https://releases.dagger.io/dagger/nonexistent_version"
|
||||
},
|
||||
]
|
Reference in New Issue
Block a user