-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge changes for v1.15 release
- Loading branch information
Showing
102 changed files
with
6,738 additions
and
2,727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"go.amzn.com/lambda/fatalerror" | ||
"go.amzn.com/lambda/interop" | ||
"go.amzn.com/lambda/rapidcore/env" | ||
) | ||
|
||
// the type implement a simpler version of the Bootstrap | ||
// this is useful in the Standalone Core implementation. | ||
type simpleBootstrap struct { | ||
cmd []string | ||
workingDir string | ||
} | ||
|
||
func NewSimpleBootstrap(cmd []string, currentWorkingDir string) interop.Bootstrap { | ||
if currentWorkingDir == "" { | ||
// use the root directory as the default working directory | ||
currentWorkingDir = "/" | ||
} | ||
|
||
// a single candidate command makes it automatically valid | ||
return &simpleBootstrap{ | ||
cmd: cmd, | ||
workingDir: currentWorkingDir, | ||
} | ||
} | ||
|
||
func (b *simpleBootstrap) Cmd() ([]string, error) { | ||
return b.cmd, nil | ||
} | ||
|
||
// Cwd returns the working directory of the bootstrap process | ||
// The path is validated against the chroot identified by `root` | ||
func (b *simpleBootstrap) Cwd() (string, error) { | ||
if !filepath.IsAbs(b.workingDir) { | ||
return "", fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", b.workingDir) | ||
} | ||
|
||
// evaluate the path relatively to the domain's mnt namespace root | ||
if _, err := os.Stat(b.workingDir); os.IsNotExist(err) { | ||
return "", fmt.Errorf("the working directory doesn't exist: %s", b.workingDir) | ||
} | ||
|
||
return b.workingDir, nil | ||
} | ||
|
||
// Env returns the environment variables available to | ||
// the bootstrap process | ||
func (b *simpleBootstrap) Env(e *env.Environment) map[string]string { | ||
return e.RuntimeExecEnv() | ||
} | ||
|
||
// ExtraFiles returns the extra file descriptors apart from 1 & 2 to be passed to runtime | ||
func (b *simpleBootstrap) ExtraFiles() []*os.File { | ||
return make([]*os.File, 0) | ||
} | ||
|
||
func (b *simpleBootstrap) CachedFatalError(err error) (fatalerror.ErrorType, string, bool) { | ||
// not implemented as it is not needed in Core but we need to fullfil the interface anyway | ||
return fatalerror.ErrorType(""), "", false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"go.amzn.com/lambda/rapidcore/env" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSimpleBootstrap(t *testing.T) { | ||
tmpFile, err := os.CreateTemp("", "oci-test-bootstrap") | ||
assert.NoError(t, err) | ||
defer os.Remove(tmpFile.Name()) | ||
|
||
// Setup single cmd candidate | ||
file := []string{tmpFile.Name(), "--arg1 s", "foo"} | ||
cmdCandidate := file | ||
|
||
// Setup working dir | ||
cwd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
|
||
// Setup environment | ||
environment := env.NewEnvironment() | ||
environment.StoreRuntimeAPIEnvironmentVariable("host:port") | ||
environment.StoreEnvironmentVariablesFromInit(map[string]string{}, "", "", "", "", "", "") | ||
|
||
// Test | ||
b := NewSimpleBootstrap(cmdCandidate, cwd) | ||
bCwd, err := b.Cwd() | ||
assert.NoError(t, err) | ||
assert.Equal(t, cwd, bCwd) | ||
assert.True(t, reflect.DeepEqual(environment.RuntimeExecEnv(), b.Env(environment))) | ||
|
||
cmd, err := b.Cmd() | ||
assert.NoError(t, err) | ||
assert.Equal(t, file, cmd) | ||
} | ||
|
||
func TestSimpleBootstrapCmdNonExistingCandidate(t *testing.T) { | ||
// Setup inexistent single cmd candidate | ||
file := []string{"/foo/bar", "--arg1 s", "foo"} | ||
cmdCandidate := file | ||
|
||
// Setup working dir | ||
cwd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
|
||
// Setup environment | ||
environment := env.NewEnvironment() | ||
environment.StoreRuntimeAPIEnvironmentVariable("host:port") | ||
environment.StoreEnvironmentVariablesFromInit(map[string]string{}, "", "", "", "", "", "") | ||
|
||
// Test | ||
b := NewSimpleBootstrap(cmdCandidate, cwd) | ||
bCwd, err := b.Cwd() | ||
assert.NoError(t, err) | ||
assert.Equal(t, cwd, bCwd) | ||
assert.True(t, reflect.DeepEqual(environment.RuntimeExecEnv(), b.Env(environment))) | ||
|
||
// No validations run against single candidates | ||
cmd, err := b.Cmd() | ||
assert.NoError(t, err) | ||
assert.Equal(t, file, cmd) | ||
} | ||
|
||
func TestSimpleBootstrapCmdDefaultWorkingDir(t *testing.T) { | ||
b := NewSimpleBootstrap([]string{}, "") | ||
bCwd, err := b.Cwd() | ||
assert.NoError(t, err) | ||
assert.Equal(t, "/", bCwd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.