From 25d1656329f79afaf268a5da47f818e4c8f720ac Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 7 Jan 2022 05:04:59 +0000 Subject: [PATCH] Europa: cleanup docker.#Build Signed-off-by: Solomon Hykes --- europa-universe/docker/build.cue | 44 +------ europa-universe/docker/test/build/build.cue | 121 +++++++++----------- 2 files changed, 57 insertions(+), 108 deletions(-) diff --git a/europa-universe/docker/build.cue b/europa-universe/docker/build.cue index f8d41797..373707ec 100644 --- a/europa-universe/docker/build.cue +++ b/europa-universe/docker/build.cue @@ -13,45 +13,11 @@ import ( // Generate build DAG from linerar steps dag: { for idx, step in steps { - ///// FIXME: this section is broken and in the middle of debug + rewrite - //// // 1. image -> input - //// if (step.input == _|_) && ((step.image & #Image) != _|_) { - //// input: image - //// } - - //// // 2. - //// if ((step.output & docker.#Image) == _|_) && ((step.output.rootfs & dagger.#FS) != _|_) { - //// - //// } - - //// // As a special case, wrap #Run into a valid step - //// if step.run != _|_ { - //// "\(idx)": { - //// input: _ - //// run: step & { - //// image: input - //// output: rootfs: _ - //// } - //// output: { - //// config: input.config - //// rootfs: run.output.rootfs - //// } - //// } - //// } - - //// // Otherwise, just use the step as is - //// if step.run == _|_ { - //// "\(idx)": { - //// run: false - //// step - //// } - //// } - - "\(idx)": step - - // Either way, connect input to previous output - if idx > 0 { - "\(idx)": input: dag["\(idx-1)"].output + "\(idx)": step & { + // connect input to previous output + if idx > 0 { + input: dag["\(idx-1)"].output + } } } } diff --git a/europa-universe/docker/test/build/build.cue b/europa-universe/docker/test/build/build.cue index ae6d6f92..3cdc74c1 100644 --- a/europa-universe/docker/test/build/build.cue +++ b/europa-universe/docker/test/build/build.cue @@ -5,78 +5,61 @@ import ( "universe.dagger.io/nginx" ) -build0: #Build & { - steps: [ - { +tests: { + "set config manually": build: #Build & { + steps: [{ output: #Image & { config: user: "foo" } - }, - ] -} - -// Inventory of real-world build use cases -// -// 1. Build netlify image -// - import alpine base -// - execute 'yarn add netlify' - -// 2. Build todoapp dev image -// - import nginx base -// - copy app directory into /usr/share/nginx/html - -build2: { - source: dagger.#FS - - build: #Build & { - steps: [ - nginx.#Build & { - flavor: "alpine" - }, - { - // Custom step to watermark the image - input: _ - output: input & { - config: user: "42" - } - }, - #Copy & { - contents: source - dest: "/usr/share/nginx/html" - }, - ] - } - img: build.output - - // Assert: - img: config: user: "42" -} - -// 3. Build alpine base image -// - pull from docker hub -// - execute 'apk add' once per package - -// 4. Build app from dockerfile - -// 5. execute several commands in a row - -build3: { - build: #Build & { - steps: [ - #Pull & { - source: "alpine" - }, - #Run & { - script: "echo A > /A.txt" - }, - #Run & { - script: "echo B > /B.txt" - }, - #Run & { - script: "echo C > /C.txt" - }, - ] + }] } - result: build.output + // - import nginx base + // - copy app directory into /usr/share/nginx/html + "build static web server": { + source: dagger.#FS + + build: #Build & { + steps: [ + nginx.#Build & { + flavor: "alpine" + }, + { + // Custom step to watermark the image + input: _ + output: input & { + config: user: "42" + } + }, + #Copy & { + contents: source + dest: "/usr/share/nginx/html" + }, + ] + } + + image: build.output + // Assert: + image: config: user: "42" + } + + "Run multiple commands": { + build: #Build & { + steps: [ + #Pull & { + source: "alpine" + }, + #Run & { + script: "echo A > /A.txt" + }, + #Run & { + script: "echo B > /B.txt" + }, + #Run & { + script: "echo C > /C.txt" + }, + ] + } + result: build.output + } }