From a63c4e989a1243c06b1166f24a3c9c5a6cc69922 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 5 Nov 2021 16:21:21 +0100 Subject: [PATCH] Change "arch" into "platform" because it's more accurate. Signed-off-by: Tom Chauveau --- cmd/dagger/cmd/compute.go | 6 +++--- cmd/dagger/cmd/edit.go | 2 +- cmd/dagger/cmd/new.go | 4 ++-- environment/environment.go | 3 ++- environment/pipeline.go | 2 +- solver/solver.go | 2 +- state/project.go | 6 +++--- state/project_test.go | 4 ++-- state/state.go | 4 ++-- tests/core.bats | 14 +++++++------- .../platform-config.cue} | 10 +++++----- tests/helpers.bash | 8 ++++---- 12 files changed, 33 insertions(+), 32 deletions(-) rename tests/core/{arch-config/arch-config.cue => platform-config/platform-config.cue} (71%) diff --git a/cmd/dagger/cmd/compute.go b/cmd/dagger/cmd/compute.go index be5c7ddb..d355ca06 100644 --- a/cmd/dagger/cmd/compute.go +++ b/cmd/dagger/cmd/compute.go @@ -43,9 +43,9 @@ var computeCmd = &cobra.Command{ doneCh := common.TrackCommand(ctx, cmd) st := &state.State{ - Name: "FIXME", - Architecture: platforms.Format(specs.Platform{OS: "linux", Architecture: "amd64"}), - Path: args[0], + Name: "FIXME", + Platform: platforms.Format(specs.Platform{OS: "linux", Architecture: "amd64"}), + Path: args[0], Plan: state.Plan{ Module: args[0], }, diff --git a/cmd/dagger/cmd/edit.go b/cmd/dagger/cmd/edit.go index 8a7961c5..d9b885df 100644 --- a/cmd/dagger/cmd/edit.go +++ b/cmd/dagger/cmd/edit.go @@ -73,7 +73,7 @@ var editCmd = &cobra.Command{ lg.Fatal().Err(err).Msg("failed to decode file") } st.Name = newState.Name - st.Architecture = newState.Architecture + st.Platform = newState.Platform st.Plan = newState.Plan st.Inputs = newState.Inputs diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index a658418a..1e3eba77 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -34,7 +34,7 @@ var newCmd = &cobra.Command{ st, err := project.Create(ctx, name, state.Plan{ Package: viper.GetString("package"), - }, viper.GetString("architecture")) + }, viper.GetString("platform")) if err != nil { lg.Fatal().Err(err).Msg("failed to create environment") @@ -46,7 +46,7 @@ var newCmd = &cobra.Command{ func init() { newCmd.Flags().StringP("package", "p", "", "references the name of the Cue package within the module to use as a plan. Default: defer to cue loader") - newCmd.Flags().StringP("architecture", "a", "", "architecture of the running pipeline. Default: host architecture") + newCmd.Flags().String("platform", "", "platform of the running pipeline. Default: host platform") if err := viper.BindPFlags(newCmd.Flags()); err != nil { panic(err) } diff --git a/environment/environment.go b/environment/environment.go index d6419824..f57250f6 100644 --- a/environment/environment.go +++ b/environment/environment.go @@ -139,7 +139,7 @@ func (e *Environment) Up(ctx context.Context, s solver.Solver) error { flow := cueflow.New( &cueflow.Config{}, e.src.Cue(), - newTaskFunc(newPipelineRunner(e.computed, s, e.state.Architecture)), + newTaskFunc(newPipelineRunner(e.computed, s, e.state.Platform)), ) if err := flow.Run(ctx); err != nil { return err @@ -200,6 +200,7 @@ func newPipelineRunner(computed *compiler.Value, s solver.Solver, platform strin } v := compiler.Wrap(t.Value()) + fmt.Println(platform) var pipelinePlatform specs.Platform if platform == "" { pipelinePlatform = specs.Platform{OS: "linux", Architecture: "amd64"} diff --git a/environment/pipeline.go b/environment/pipeline.go index df6dc677..a0cd1fe8 100644 --- a/environment/pipeline.go +++ b/environment/pipeline.go @@ -46,7 +46,7 @@ type Pipeline struct { name string s solver.Solver state llb.State - platform specs.Platform // Architecture constraint + platform specs.Platform // Platform constraint result bkgw.Reference image dockerfile2llb.Image computed *compiler.Value diff --git a/solver/solver.go b/solver/solver.go index 4362c41a..6e11fe4e 100644 --- a/solver/solver.go +++ b/solver/solver.go @@ -127,7 +127,7 @@ func (s Solver) SolveRequest(ctx context.Context, req bkgw.SolveRequest) (*bkgw. } // Solve will block until the state is solved and returns a Reference. -// It takes a platform as argument which correspond to the architecture. +// It takes a platform as argument which correspond to the targeted platform. func (s Solver) Solve(ctx context.Context, st llb.State, platform specs.Platform) (bkgw.Reference, error) { def, err := s.Marshal(ctx, st, llb.Platform(platform)) if err != nil { diff --git a/state/project.go b/state/project.go index f74f5612..274e9938 100644 --- a/state/project.go +++ b/state/project.go @@ -235,7 +235,7 @@ func (w *Project) Save(ctx context.Context, st *State) error { return nil } -func (w *Project) Create(ctx context.Context, name string, plan Plan, arch string) (*State, error) { +func (w *Project) Create(ctx context.Context, name string, plan Plan, platform string) (*State, error) { if _, err := w.Get(ctx, name); err == nil { return nil, ErrExist } @@ -263,8 +263,8 @@ func (w *Project) Create(ctx context.Context, name string, plan Plan, arch strin Plan: Plan{ Package: pkg, }, - Name: name, - Architecture: arch, + Name: name, + Platform: platform, } data, err := yaml.Marshal(st) diff --git a/state/project_test.go b/state/project_test.go index 7eeb7b93..9d3d3223 100644 --- a/state/project_test.go +++ b/state/project_test.go @@ -35,7 +35,7 @@ func TestProject(t *testing.T) { }, "linux/amd64") require.NoError(t, err) require.Equal(t, "test", st.Name) - require.Equal(t, "linux/amd64", st.Architecture) + require.Equal(t, "linux/amd64", st.Platform) // Open project, err = Open(ctx, root) @@ -52,7 +52,7 @@ func TestProject(t *testing.T) { env, err := project.Get(ctx, "test") require.NoError(t, err) require.Equal(t, "test", env.Name) - require.Equal(t, "linux/amd64", env.Architecture) + require.Equal(t, "linux/amd64", env.Platform) // Save require.NoError(t, env.SetInput("foo", TextInput("bar"))) diff --git a/state/state.go b/state/state.go index 75b38423..a6251e59 100644 --- a/state/state.go +++ b/state/state.go @@ -24,8 +24,8 @@ type State struct { // FIXME: store multiple names? Name string `yaml:"name,omitempty"` - // Architecture execution - Architecture string `yaml:"architecture,omitempty"` + // Platform execution + Platform string `yaml:"platform,omitempty"` // User Inputs Inputs map[string]Input `yaml:"inputs,omitempty"` diff --git a/tests/core.bats b/tests/core.bats index 9807e05b..14866bb4 100644 --- a/tests/core.bats +++ b/tests/core.bats @@ -159,26 +159,26 @@ setup() { "$DAGGER" up } -@test "core: arch config" { +@test "core: platform config" { dagger init - # Test for amd64 architecture - dagger_new_with_plan test-amd "$TESTDIR"/core/arch-config "linux/amd64" + # Test for amd64 platform + dagger_new_with_plan test-amd "$TESTDIR"/core/platform-config "linux/amd64" # Set arch expected value "$DAGGER" -e test-amd input text targetArch "x86_64" # Up amd - "$DAGGER" -e test-amd up + "$DAGGER" -e test-amd up --no-cache - # Test for amd64 architecture - dagger_new_with_plan test-arm "$TESTDIR"/core/arch-config "linux/arm64" + # Test for amd64 platform + dagger_new_with_plan test-arm "$TESTDIR"/core/platform-config "linux/arm64" # Set arch expected value "$DAGGER" -e test-arm input text targetArch "aarch64" # Up arm - "$DAGGER" -e test-arm up + "$DAGGER" -e test-arm up --no-cache } @test "compute: exclude" { diff --git a/tests/core/arch-config/arch-config.cue b/tests/core/platform-config/platform-config.cue similarity index 71% rename from tests/core/arch-config/arch-config.cue rename to tests/core/platform-config/platform-config.cue index 23585932..42d79eba 100644 --- a/tests/core/arch-config/arch-config.cue +++ b/tests/core/platform-config/platform-config.cue @@ -13,13 +13,13 @@ TestFetch: #up: [ }, op.#Exec & { - args: ["/bin/sh", "-c", "echo $(uname -a) >> /arch.txt"] + args: ["/bin/sh", "-c", "echo $(uname -a) >> /platform.txt"] always: true }, op.#Exec & { args: ["/bin/sh", "-c", """ - cat /arch.txt | grep "$TARGET_ARCH" + cat /platform.txt | grep "$TARGET_ARCH" """] env: TARGET_ARCH: targetArch }, @@ -30,13 +30,13 @@ TestBuild: #up: [ dockerfile: """ FROM alpine - RUN echo $(uname -a) > /arch.txt + RUN echo $(uname -a) > /platform.txt """ }, op.#Exec & { args: ["/bin/sh", "-c", """ - cat /arch.txt | grep "$TARGET_ARCH" + cat /platform.txt | grep "$TARGET_ARCH" """] env: TARGET_ARCH: targetArch }, @@ -49,7 +49,7 @@ TestLoad: #up: [ // Compare arch op.#Exec & { - args: ["/bin/sh", "-c", "diff /build/arch.txt /fetch/arch.txt"] + args: ["/bin/sh", "-c", "diff /build/platform.txt /fetch/platform.txt"] mount: { "/build": from: TestBuild "/fetch": from: TestFetch diff --git a/tests/helpers.bash b/tests/helpers.bash index 5735963e..2d56e40a 100644 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -20,17 +20,17 @@ common_setup() { dagger_new_with_plan() { local name="$1" local sourcePlan="$2" - local arch="$3" + local platform="$3" cp -a "$sourcePlan"/* "$DAGGER_PROJECT" local opts="" - if [ -n "$arch" ]; + if [ -n "$platform" ]; then - opts="-a $arch" + opts="--platform $platform" fi - # Need word splitting to take in account "-a" and "$arch" + # Need word splitting to take in account "-a" and "$platform" # shellcheck disable=SC2086 "$DAGGER" new "$name" ${opts} }