refactored

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones 2022-01-13 11:31:08 -07:00
parent 729013ae91
commit 2745e1ae2e
No known key found for this signature in database
GPG Key ID: CFB3A382EB166F4C
10 changed files with 31 additions and 48 deletions

View File

@ -68,38 +68,35 @@ package engine
config: #ImageConfig config: #ImageConfig
} }
// Build a container image using buildkit // Build a container image using a Dockerfile
#Dockerfile: { #Dockerfile: {
$dagger: task: _name: "Dockerfile" $dagger: task: _name: "Dockerfile"
// Source directory to build // Source directory to build
source: #FS source: #FS
{
frontend: "dockerfile"
dockerfile: {
path: string | *"Dockerfile"
} | {
contents: string
}
// Authentication *{
auth: [...{ path: string | *"Dockerfile"
target: string } | {
username: string contents: string
secret: string | #Secret
}]
// FIXME: options ported from op.#DockerBuild
platforms?: [...string]
target?: string
buildArg?: [string]: string
label?: [string]: string
hosts?: [string]: string
} }
// Root filesystem produced by build // Authentication
auth: [...{
target: string
username: string
secret: string | #Secret
}]
platforms?: [...string]
target?: string
buildArg?: [string]: string
label?: [string]: string
hosts?: [string]: string
// Root filesystem produced
output: #FS output: #FS
// Container image config produced by build // Container image config produced
config: #ImageConfig config: #ImageConfig
} }

View File

@ -29,20 +29,6 @@ type dockerfileTask struct {
} }
func (t *dockerfileTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { func (t *dockerfileTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
frontend, err := v.Lookup("frontend").String()
if err != nil {
return nil, err
}
switch frontend {
case "dockerfile":
return t.dockerfile(ctx, pctx, s, v)
default:
return nil, fmt.Errorf("unsupported frontend %q", frontend)
}
}
func (t *dockerfileTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
lg := log.Ctx(ctx) lg := log.Ctx(ctx)
// Read auth info // Read auth info
@ -74,7 +60,7 @@ func (t *dockerfileTask) dockerfile(ctx context.Context, pctx *plancontext.Conte
dockerfileDef := contextDef dockerfileDef := contextDef
// Support inlined dockerfile // Support inlined dockerfile
if dockerfile := v.Lookup("dockerfile.contents"); dockerfile.Exists() { if dockerfile := v.Lookup("contents"); dockerfile.Exists() {
contents, err := dockerfile.String() contents, err := dockerfile.String()
if err != nil { if err != nil {
return nil, err return nil, err
@ -147,7 +133,7 @@ func (t *dockerfileTask) dockerfile(ctx context.Context, pctx *plancontext.Conte
func (t *dockerfileTask) dockerBuildOpts(v *compiler.Value, pctx *plancontext.Context) (map[string]string, error) { func (t *dockerfileTask) dockerBuildOpts(v *compiler.Value, pctx *plancontext.Context) (map[string]string, error) {
opts := map[string]string{} opts := map[string]string{}
if dockerfilePath := v.Lookup("dockerfile.path"); dockerfilePath.Exists() { if dockerfilePath := v.Lookup("path"); dockerfilePath.Exists() {
filename, err := dockerfilePath.String() filename, err := dockerfilePath.String()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -85,9 +85,7 @@ setup() {
"$DAGGER" --europa up ./image_config.cue "$DAGGER" --europa up ./image_config.cue
"$DAGGER" --europa up ./labels.cue "$DAGGER" --europa up ./labels.cue
"$DAGGER" --europa up ./platform.cue "$DAGGER" --europa up ./platform.cue
"$DAGGER" --europa up ./build_auth.cue
cd "$TESTDIR"
"$DAGGER" --europa up ./tasks/dockerfile/build_auth.cue
} }
@test "task: #Scratch" { @test "task: #Scratch" {
cd "$TESTDIR"/tasks/scratch cd "$TESTDIR"/tasks/scratch

View File

@ -9,7 +9,7 @@ engine.#Plan & {
actions: build: engine.#Dockerfile & { actions: build: engine.#Dockerfile & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
dockerfile: contents: """ contents: """
FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
ARG TEST=foo ARG TEST=foo
RUN test "${TEST}" = "bar" RUN test "${TEST}" = "bar"

View File

@ -1,3 +1,5 @@
# generated by dagger # generated by dagger
alpha.dagger.io alpha.dagger.io
dagger.io
dagger.lock dagger.lock
universe.dagger.io

View File

@ -10,7 +10,7 @@ engine.#Plan & {
actions: { actions: {
build: engine.#Dockerfile & { build: engine.#Dockerfile & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
dockerfile: path: "./dockerfilepath/Dockerfile.custom" path: "./dockerfilepath/Dockerfile.custom"
} }
verify: engine.#Exec & { verify: engine.#Exec & {

View File

@ -11,7 +11,7 @@ engine.#Plan & {
// FIXME: this doesn't test anything beside not crashing // FIXME: this doesn't test anything beside not crashing
build: engine.#Dockerfile & { build: engine.#Dockerfile & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
dockerfile: contents: """ contents: """
FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
ENV test foobar ENV test foobar
CMD /test-cmd CMD /test-cmd

View File

@ -10,7 +10,7 @@ engine.#Plan & {
actions: { actions: {
build: engine.#Dockerfile & { build: engine.#Dockerfile & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
dockerfile: contents: """ contents: """
FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
RUN echo foobar > /output RUN echo foobar > /output
""" """

View File

@ -11,7 +11,7 @@ engine.#Plan & {
// FIXME: this doesn't test anything beside not crashing // FIXME: this doesn't test anything beside not crashing
build: engine.#Dockerfile & { build: engine.#Dockerfile & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
dockerfile: contents: """ contents: """
FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
""" """
label: FOO: "bar" label: FOO: "bar"

View File

@ -11,7 +11,7 @@ engine.#Plan & {
// FIXME: this doesn't test anything beside not crashing // FIXME: this doesn't test anything beside not crashing
build: engine.#Dockerfile & { build: engine.#Dockerfile & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
dockerfile: contents: """ contents: """
FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
""" """
platforms: ["linux/amd64"] platforms: ["linux/amd64"]