Merge pull request #789 from hinshun/fetch-http

Adds support for op.#FetchHTTP
This commit is contained in:
Andrea Luzzardi 2021-07-07 17:23:16 +02:00 committed by GitHub
commit 21bed8aee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 0 deletions

View File

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

View File

@ -19,6 +19,7 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb" "github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
bkgw "github.com/moby/buildkit/frontend/gateway/client" bkgw "github.com/moby/buildkit/frontend/gateway/client"
bkpb "github.com/moby/buildkit/solver/pb" bkpb "github.com/moby/buildkit/solver/pb"
digest "github.com/opencontainers/go-digest"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"gopkg.in/yaml.v3" "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) return p.PushContainer(ctx, op, st)
case "fetch-git": case "fetch-git":
return p.FetchGit(ctx, op, st) return p.FetchGit(ctx, op, st)
case "fetch-http":
return p.FetchHTTP(ctx, op, st)
case "local": case "local":
return p.Local(ctx, op, st) return p.Local(ctx, op, st)
case "load": case "load":
@ -817,6 +820,55 @@ func (p *Pipeline) FetchGit(ctx context.Context, op *compiler.Value, st llb.Stat
), nil ), 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) { func (p *Pipeline) DockerBuild(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) {
var ( var (
dockerContext = op.Lookup("context") dockerContext = op.Lookup("context")

View File

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

View File

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

View File

@ -113,6 +113,14 @@ setup() {
# assert_failure # 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" { @test "op.#Exec" {
run "$DAGGER" compute "$TESTDIR"/ops/exec/invalid run "$DAGGER" compute "$TESTDIR"/ops/exec/invalid
assert_failure 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"
},
]