Skip to content

Commit

Permalink
added support for multi arch runtime images (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-astro committed Sep 19, 2022
1 parent 56023cf commit bee657a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
4 changes: 4 additions & 0 deletions airflow/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (d *DockerImage) Build(config airflowTypes.ImageBuildConfig) error {
if config.NoCache {
args = append(args, "--no-cache")
}

if len(config.TargetPlatforms) > 0 {
args = append(args, fmt.Sprintf("--platform=%s", strings.Join(config.TargetPlatforms, ",")))
}
// Build image
var stdout, stderr io.Writer
if config.Output {
Expand Down
5 changes: 3 additions & 2 deletions airflow/docker_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func TestDockerImageBuild(t *testing.T) {
assert.NoError(t, err)

options := airflowTypes.ImageBuildConfig{
Path: cwd,
NoCache: false,
Path: cwd,
TargetPlatforms: []string{"linux/amd64"},
NoCache: false,
}

previousCmdExec := cmdExec
Expand Down
8 changes: 8 additions & 0 deletions airflow/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ func TestCheckWebserverHealth(t *testing.T) {
mockEventsCall.ReturnArguments = mock.Arguments{err}
}

openURL = func(url string) error {
return nil
}

orgInitSetting := initSettings
initSettings = func(id string, version uint64) error {
return nil
Expand Down Expand Up @@ -912,6 +916,10 @@ func TestCheckWebserverHealth(t *testing.T) {
mockEventsCall.ReturnArguments = mock.Arguments{err}
}

openURL = func(url string) error {
return nil
}

err := checkWebserverHealth(&types.Project{Name: "test"}, composeMock, 2)
assert.ErrorIs(t, err, errMockDocker)
})
Expand Down
7 changes: 4 additions & 3 deletions airflow/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package types

// ImageBuildConfig defines options when building a container image
type ImageBuildConfig struct {
Path string
NoCache bool
Output bool
Path string
TargetPlatforms []string
NoCache bool
Output bool
}
4 changes: 3 additions & 1 deletion cloud/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
pytestFile string
dockerfile = "Dockerfile"

deployImagePlatformSupport = []string{"linux/amd64"}

// Monkey patched to write unit tests
airflowImageHandler = airflow.ImageHandlerInit
containerHandlerInit = airflow.ContainerHandlerInit
Expand Down Expand Up @@ -261,7 +263,7 @@ func buildImage(c *config.Context, path, currentVersion, deployImage, imageName
imageHandler := airflowImageHandler(deployImage)

if imageName == "" {
err := imageHandler.Build(types.ImageBuildConfig{Path: path, Output: true})
err := imageHandler.Build(types.ImageBuildConfig{Path: path, Output: true, TargetPlatforms: deployImagePlatformSupport})
if err != nil {
return "", err
}
Expand Down
9 changes: 9 additions & 0 deletions cloud/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ func TestBuildImageFailure(t *testing.T) {
ctx.SetSystemAdmin(true)

mockImageHandler := new(mocks.ImageHandler)

// image build failure
airflowImageHandler = func(image string) airflow.ImageHandler {
mockImageHandler.On("Build", mock.Anything).Return(errMock).Once()
return mockImageHandler
}
_, err = buildImage(&ctx, "./testfiles/", "4.2.5", "", "", nil)
assert.ErrorIs(t, err, errMock)

airflowImageHandler = func(image string) airflow.ImageHandler {
mockImageHandler.On("Build", mock.Anything).Return(nil)
mockImageHandler.On("GetLabel", runtimeImageLabel).Return("4.2.5", nil)
Expand Down
8 changes: 6 additions & 2 deletions software/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (
imageHandlerInit = airflow.ImageHandlerInit

dockerfile = "Dockerfile"

deployImagePlatformSupport = []string{"linux/amd64"}
)

var (
Expand Down Expand Up @@ -216,8 +218,10 @@ func buildPushDockerImage(houstonClient houston.ClientInterface, c *config.Conte
imageHandler := imageHandlerInit(imageName)

buildConfig := types.ImageBuildConfig{
Path: config.WorkingPath,
NoCache: ignoreCacheDeploy,
Path: config.WorkingPath,
NoCache: ignoreCacheDeploy,
TargetPlatforms: deployImagePlatformSupport,
Output: true,
}
err = imageHandler.Build(buildConfig)
if err != nil {
Expand Down

0 comments on commit bee657a

Please sign in to comment.