Change "arch" into "platform" because it's more accurate.
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
de6afee89c
commit
a63c4e989a
@ -43,9 +43,9 @@ var computeCmd = &cobra.Command{
|
|||||||
doneCh := common.TrackCommand(ctx, cmd)
|
doneCh := common.TrackCommand(ctx, cmd)
|
||||||
|
|
||||||
st := &state.State{
|
st := &state.State{
|
||||||
Name: "FIXME",
|
Name: "FIXME",
|
||||||
Architecture: platforms.Format(specs.Platform{OS: "linux", Architecture: "amd64"}),
|
Platform: platforms.Format(specs.Platform{OS: "linux", Architecture: "amd64"}),
|
||||||
Path: args[0],
|
Path: args[0],
|
||||||
Plan: state.Plan{
|
Plan: state.Plan{
|
||||||
Module: args[0],
|
Module: args[0],
|
||||||
},
|
},
|
||||||
|
@ -73,7 +73,7 @@ var editCmd = &cobra.Command{
|
|||||||
lg.Fatal().Err(err).Msg("failed to decode file")
|
lg.Fatal().Err(err).Msg("failed to decode file")
|
||||||
}
|
}
|
||||||
st.Name = newState.Name
|
st.Name = newState.Name
|
||||||
st.Architecture = newState.Architecture
|
st.Platform = newState.Platform
|
||||||
st.Plan = newState.Plan
|
st.Plan = newState.Plan
|
||||||
st.Inputs = newState.Inputs
|
st.Inputs = newState.Inputs
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ var newCmd = &cobra.Command{
|
|||||||
|
|
||||||
st, err := project.Create(ctx, name, state.Plan{
|
st, err := project.Create(ctx, name, state.Plan{
|
||||||
Package: viper.GetString("package"),
|
Package: viper.GetString("package"),
|
||||||
}, viper.GetString("architecture"))
|
}, viper.GetString("platform"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("failed to create environment")
|
lg.Fatal().Err(err).Msg("failed to create environment")
|
||||||
@ -46,7 +46,7 @@ var newCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
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("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 {
|
if err := viper.BindPFlags(newCmd.Flags()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ func (e *Environment) Up(ctx context.Context, s solver.Solver) error {
|
|||||||
flow := cueflow.New(
|
flow := cueflow.New(
|
||||||
&cueflow.Config{},
|
&cueflow.Config{},
|
||||||
e.src.Cue(),
|
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 {
|
if err := flow.Run(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -200,6 +200,7 @@ func newPipelineRunner(computed *compiler.Value, s solver.Solver, platform strin
|
|||||||
}
|
}
|
||||||
v := compiler.Wrap(t.Value())
|
v := compiler.Wrap(t.Value())
|
||||||
|
|
||||||
|
fmt.Println(platform)
|
||||||
var pipelinePlatform specs.Platform
|
var pipelinePlatform specs.Platform
|
||||||
if platform == "" {
|
if platform == "" {
|
||||||
pipelinePlatform = specs.Platform{OS: "linux", Architecture: "amd64"}
|
pipelinePlatform = specs.Platform{OS: "linux", Architecture: "amd64"}
|
||||||
|
@ -46,7 +46,7 @@ type Pipeline struct {
|
|||||||
name string
|
name string
|
||||||
s solver.Solver
|
s solver.Solver
|
||||||
state llb.State
|
state llb.State
|
||||||
platform specs.Platform // Architecture constraint
|
platform specs.Platform // Platform constraint
|
||||||
result bkgw.Reference
|
result bkgw.Reference
|
||||||
image dockerfile2llb.Image
|
image dockerfile2llb.Image
|
||||||
computed *compiler.Value
|
computed *compiler.Value
|
||||||
|
@ -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.
|
// 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) {
|
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))
|
def, err := s.Marshal(ctx, st, llb.Platform(platform))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -235,7 +235,7 @@ func (w *Project) Save(ctx context.Context, st *State) error {
|
|||||||
return nil
|
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 {
|
if _, err := w.Get(ctx, name); err == nil {
|
||||||
return nil, ErrExist
|
return nil, ErrExist
|
||||||
}
|
}
|
||||||
@ -263,8 +263,8 @@ func (w *Project) Create(ctx context.Context, name string, plan Plan, arch strin
|
|||||||
Plan: Plan{
|
Plan: Plan{
|
||||||
Package: pkg,
|
Package: pkg,
|
||||||
},
|
},
|
||||||
Name: name,
|
Name: name,
|
||||||
Architecture: arch,
|
Platform: platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := yaml.Marshal(st)
|
data, err := yaml.Marshal(st)
|
||||||
|
@ -35,7 +35,7 @@ func TestProject(t *testing.T) {
|
|||||||
}, "linux/amd64")
|
}, "linux/amd64")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "test", st.Name)
|
require.Equal(t, "test", st.Name)
|
||||||
require.Equal(t, "linux/amd64", st.Architecture)
|
require.Equal(t, "linux/amd64", st.Platform)
|
||||||
|
|
||||||
// Open
|
// Open
|
||||||
project, err = Open(ctx, root)
|
project, err = Open(ctx, root)
|
||||||
@ -52,7 +52,7 @@ func TestProject(t *testing.T) {
|
|||||||
env, err := project.Get(ctx, "test")
|
env, err := project.Get(ctx, "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "test", env.Name)
|
require.Equal(t, "test", env.Name)
|
||||||
require.Equal(t, "linux/amd64", env.Architecture)
|
require.Equal(t, "linux/amd64", env.Platform)
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
require.NoError(t, env.SetInput("foo", TextInput("bar")))
|
require.NoError(t, env.SetInput("foo", TextInput("bar")))
|
||||||
|
@ -24,8 +24,8 @@ type State struct {
|
|||||||
// FIXME: store multiple names?
|
// FIXME: store multiple names?
|
||||||
Name string `yaml:"name,omitempty"`
|
Name string `yaml:"name,omitempty"`
|
||||||
|
|
||||||
// Architecture execution
|
// Platform execution
|
||||||
Architecture string `yaml:"architecture,omitempty"`
|
Platform string `yaml:"platform,omitempty"`
|
||||||
|
|
||||||
// User Inputs
|
// User Inputs
|
||||||
Inputs map[string]Input `yaml:"inputs,omitempty"`
|
Inputs map[string]Input `yaml:"inputs,omitempty"`
|
||||||
|
@ -159,26 +159,26 @@ setup() {
|
|||||||
"$DAGGER" up
|
"$DAGGER" up
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "core: arch config" {
|
@test "core: platform config" {
|
||||||
dagger init
|
dagger init
|
||||||
|
|
||||||
# Test for amd64 architecture
|
# Test for amd64 platform
|
||||||
dagger_new_with_plan test-amd "$TESTDIR"/core/arch-config "linux/amd64"
|
dagger_new_with_plan test-amd "$TESTDIR"/core/platform-config "linux/amd64"
|
||||||
|
|
||||||
# Set arch expected value
|
# Set arch expected value
|
||||||
"$DAGGER" -e test-amd input text targetArch "x86_64"
|
"$DAGGER" -e test-amd input text targetArch "x86_64"
|
||||||
|
|
||||||
# Up amd
|
# Up amd
|
||||||
"$DAGGER" -e test-amd up
|
"$DAGGER" -e test-amd up --no-cache
|
||||||
|
|
||||||
# Test for amd64 architecture
|
# Test for amd64 platform
|
||||||
dagger_new_with_plan test-arm "$TESTDIR"/core/arch-config "linux/arm64"
|
dagger_new_with_plan test-arm "$TESTDIR"/core/platform-config "linux/arm64"
|
||||||
|
|
||||||
# Set arch expected value
|
# Set arch expected value
|
||||||
"$DAGGER" -e test-arm input text targetArch "aarch64"
|
"$DAGGER" -e test-arm input text targetArch "aarch64"
|
||||||
|
|
||||||
# Up arm
|
# Up arm
|
||||||
"$DAGGER" -e test-arm up
|
"$DAGGER" -e test-arm up --no-cache
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "compute: exclude" {
|
@test "compute: exclude" {
|
||||||
|
@ -13,13 +13,13 @@ TestFetch: #up: [
|
|||||||
},
|
},
|
||||||
|
|
||||||
op.#Exec & {
|
op.#Exec & {
|
||||||
args: ["/bin/sh", "-c", "echo $(uname -a) >> /arch.txt"]
|
args: ["/bin/sh", "-c", "echo $(uname -a) >> /platform.txt"]
|
||||||
always: true
|
always: true
|
||||||
},
|
},
|
||||||
|
|
||||||
op.#Exec & {
|
op.#Exec & {
|
||||||
args: ["/bin/sh", "-c", """
|
args: ["/bin/sh", "-c", """
|
||||||
cat /arch.txt | grep "$TARGET_ARCH"
|
cat /platform.txt | grep "$TARGET_ARCH"
|
||||||
"""]
|
"""]
|
||||||
env: TARGET_ARCH: targetArch
|
env: TARGET_ARCH: targetArch
|
||||||
},
|
},
|
||||||
@ -30,13 +30,13 @@ TestBuild: #up: [
|
|||||||
dockerfile: """
|
dockerfile: """
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
RUN echo $(uname -a) > /arch.txt
|
RUN echo $(uname -a) > /platform.txt
|
||||||
"""
|
"""
|
||||||
},
|
},
|
||||||
|
|
||||||
op.#Exec & {
|
op.#Exec & {
|
||||||
args: ["/bin/sh", "-c", """
|
args: ["/bin/sh", "-c", """
|
||||||
cat /arch.txt | grep "$TARGET_ARCH"
|
cat /platform.txt | grep "$TARGET_ARCH"
|
||||||
"""]
|
"""]
|
||||||
env: TARGET_ARCH: targetArch
|
env: TARGET_ARCH: targetArch
|
||||||
},
|
},
|
||||||
@ -49,7 +49,7 @@ TestLoad: #up: [
|
|||||||
|
|
||||||
// Compare arch
|
// Compare arch
|
||||||
op.#Exec & {
|
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: {
|
mount: {
|
||||||
"/build": from: TestBuild
|
"/build": from: TestBuild
|
||||||
"/fetch": from: TestFetch
|
"/fetch": from: TestFetch
|
@ -20,17 +20,17 @@ common_setup() {
|
|||||||
dagger_new_with_plan() {
|
dagger_new_with_plan() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local sourcePlan="$2"
|
local sourcePlan="$2"
|
||||||
local arch="$3"
|
local platform="$3"
|
||||||
|
|
||||||
cp -a "$sourcePlan"/* "$DAGGER_PROJECT"
|
cp -a "$sourcePlan"/* "$DAGGER_PROJECT"
|
||||||
|
|
||||||
local opts=""
|
local opts=""
|
||||||
if [ -n "$arch" ];
|
if [ -n "$platform" ];
|
||||||
then
|
then
|
||||||
opts="-a $arch"
|
opts="--platform $platform"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Need word splitting to take in account "-a" and "$arch"
|
# Need word splitting to take in account "-a" and "$platform"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
"$DAGGER" new "$name" ${opts}
|
"$DAGGER" new "$name" ${opts}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user