Skip to content

Commit

Permalink
Merge pull request #66 from concourse/multi-platform
Browse files Browse the repository at this point in the history
Add IMAGE_PLATFORM param
  • Loading branch information
taylorsilva authored Jul 16, 2021
2 parents b5c639e + e0ea63e commit 7068da6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ Next, any of the following optional parameters may be specified:
name. For example, `IMAGE_ARG_base_image=ubuntu/image.tar` will set
`base_image` to a local image reference for using `ubuntu/image.tar`.
* `IMAGE_PLATFORM`: Specify the target platform to build the image for. For
example `IMAGE_PLATFORM=linux/arm64` will build the image for the Linux OS
and `arm64` architecture. By default, images will be built for the current
worker's platform that the task is running on.
* `$LABEL_*`: params prefixed with `LABEL_` will be set as image labels.
For example `LABEL_foo=bar`, will set the `foo` label to `bar`.
Expand Down
6 changes: 6 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ func Build(buildkitd *Buildkitd, outputsDir string, req Request) (Response, erro
)
}

if req.Config.ImagePlatform != "" {
buildctlArgs = append(buildctlArgs,
"--opt", "platform="+req.Config.ImagePlatform,
)
}

builds = append(builds, buildctlArgs)
targets = append(targets, "")

Expand Down
17 changes: 17 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@ func (s *TaskSuite) TestAddHosts() {
s.NoError(err)
}

func (s *TaskSuite) TestImagePlatform() {
s.req.Config.ContextDir = "testdata/basic"
s.req.Config.ImagePlatform = "linux/arm64"

_, err := s.build()
s.NoError(err)

image, err := tarball.ImageFromPath(s.imagePath("image.tar"), nil)
s.NoError(err)

configFile, err := image.ConfigFile()
s.NoError(err)

s.Equal("linux", configFile.OS)
s.Equal("arm64", configFile.Architecture)
}

func (s *TaskSuite) build() (task.Response, error) {
return task.Build(s.buildkitd, s.outputsDir, s.req)
}
Expand Down
2 changes: 2 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type Config struct {
ImageArgs []string `json:"image_args" envconfig:"optional"`

AddHosts string `json:"add_hosts" envconfig:"BUILDKIT_ADD_HOSTS,optional"`

ImagePlatform string `json:"image_platform" envconfig:"optional"`
}

// ImageMetadata is the schema written to manifest.json when producing the
Expand Down

0 comments on commit 7068da6

Please sign in to comment.