Merge pull request #1300 from TomChv/europa/plan-platform-configuration
Config platform in #Plan
This commit is contained in:
commit
bbec566bb5
29
plan/plan.go
29
plan/plan.go
@ -48,6 +48,10 @@ func Load(ctx context.Context, args ...string) (*Plan, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := p.configPlatform(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@ -59,6 +63,31 @@ func (p *Plan) Source() *compiler.Value {
|
||||
return p.source
|
||||
}
|
||||
|
||||
// configPlatform load the platform specified in the context
|
||||
// Buildkit will then run every operation using that platform
|
||||
// If platform is not define, context keep default platform
|
||||
func (p *Plan) configPlatform() error {
|
||||
platformField := p.source.Lookup("platform")
|
||||
|
||||
// Ignore if platform is not set in `#Plan`
|
||||
if !platformField.Exists() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert platform to string
|
||||
platform, err := platformField.String()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set platform to context
|
||||
err = p.context.Platform.Set(platform)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// registerLocalDirectories scans the context for local imports.
|
||||
// BuildKit requires to known the list of directories ahead of time.
|
||||
func (p *Plan) registerLocalDirs() error {
|
||||
|
@ -27,6 +27,9 @@ package engine
|
||||
// Forward network services to and from the client
|
||||
proxy: [endpoint=string]: _#proxyEndpoint
|
||||
|
||||
// Configure platform execution
|
||||
platform?: string
|
||||
|
||||
// Execute actions in containers
|
||||
actions: {
|
||||
...
|
||||
|
@ -77,3 +77,17 @@ setup() {
|
||||
"$DAGGER" --europa up ./outputs.cue
|
||||
assert [ -f "./out/test" ]
|
||||
}
|
||||
|
||||
@test "plan/platform" {
|
||||
cd "$TESTDIR"
|
||||
|
||||
# Run with amd64 platform
|
||||
run "$DAGGER" --europa up ./plan/platform/config_platform_linux_amd64.cue
|
||||
|
||||
# Run with arm64 platform
|
||||
run "$DAGGER" --europa up ./plan/platform/config_platform_linux_arm64.cue
|
||||
|
||||
# Run with invalid platform
|
||||
run "$DAGGER" --europa up ./plan/platform/config_platform_failure_invalid_platform.cue
|
||||
assert_failure
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
platform: "linux/unknown"
|
||||
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0"
|
||||
}
|
||||
|
||||
writeArch: engine.#Exec & {
|
||||
input: image.output
|
||||
always: true
|
||||
args: [
|
||||
"sh", "-c", #"""
|
||||
echo -n $(uname -m) >> /arch.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#ReadFile & {
|
||||
input: writeArch.output
|
||||
path: "/arch.txt"
|
||||
} & {
|
||||
contents: "s390x"
|
||||
}
|
||||
}
|
||||
}
|
32
tests/plan/platform/config_platform_linux_amd64.cue
Normal file
32
tests/plan/platform/config_platform_linux_amd64.cue
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
platform: "linux/amd64"
|
||||
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0"
|
||||
}
|
||||
|
||||
writeArch: engine.#Exec & {
|
||||
input: image.output
|
||||
always: true
|
||||
args: [
|
||||
"sh", "-c", #"""
|
||||
echo -n $(uname -m) >> /arch.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#ReadFile & {
|
||||
input: writeArch.output
|
||||
path: "/arch.txt"
|
||||
} & {
|
||||
contents: "x86_64"
|
||||
}
|
||||
}
|
||||
}
|
32
tests/plan/platform/config_platform_linux_arm64.cue
Normal file
32
tests/plan/platform/config_platform_linux_arm64.cue
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
platform: "linux/arm64"
|
||||
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0"
|
||||
}
|
||||
|
||||
writeArch: engine.#Exec & {
|
||||
input: image.output
|
||||
always: true
|
||||
args: [
|
||||
"sh", "-c", #"""
|
||||
echo -n $(uname -m) >> /arch.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#ReadFile & {
|
||||
input: writeArch.output
|
||||
path: "/arch.txt"
|
||||
} & {
|
||||
contents: "aarch64"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user