Proposal: improve multi-arch builds
Projects that want to support multiple architectures often end up with many copies of a very similar Dockerfile , but with minor variations for the platform (notably the base image will be different). docker/docker is an example of such a project.
It would be nice to provide a way to remove that boilerplate and make it easy to build a binary for different architectures.
One option would be to use a job to render a Dockerfile from a template, but that won't work unless you already have some way to pull a multi-arch image.
Another option might be to provide templating for the Dockerfile from dobi itself.
Providing templating for the Dockerfile would also solve the problem of building chains of images where you want each to have a unique ID. There is no other mechanism for resolving a variable in the FROM line of the Dockerfile.
I think templating is a cool feature but maybe we could handle things within dobi.yaml. Because at least with go, a multi-arch Dockerfile contains very few steps, so if we could provide a way to script a dockerfile within dobi would be great. It would also be very nice for things like https://github.com/dnephin/dobi/pull/52 because we wouldnt need to download multiple files. As fas as dockerclient is concerned a dockerfile is a string, it does not matter where it comes from
https://github.com/dnephin/dobi/blob/master/tasks/image/build.go#L81
env=production-vars:
variables: [VERSION=0.2.5]
image=binary-builder:
image: cescoferraro/power
tags: ["builder"]
depends: [production-vars]
context: .
dockerfile:
- FROM: cescoferrar/golang:1.7-{env.VERSION:}
- RUN: apk add -U git bash curl tree
- RUN: go get github.com/franciscocpg/gox && cp /go/bin/gox /usr/bin && rm -rf /go/src/* /go/pkg/* /go/bin/*
//Cool things like provinding custom steps
- GLIDE: 0.12.3
- CMD gox -ldflags "-X github.com/cescoferraro/power/cmd.version={env.VERSION:}" -output="/go/bin/power-{{.Arch}}-{env.VERSION:}" -osarch="linux/armv6" -osarch="linux/armv7" -osarch="linux/amd64" .
// Or even cooler
- GOX:
- ldflags: github.com/cescoferraro/power/cmd.version={env.VERSION:}
- output: /go/bin/power-{{.Arch}}-{env.VERSION:}
- osarch: linux/armv6
- osarch: linux/armv7
job=binary:
use: binary-builder
artifact: ./dist/bin/
mounts: [source, dist]
env:
- "VERSION={env.VERSION:}"
description: "Build the ARM static binary"
it would also to make dobi's footprint smaller as well as providing a very declarative method.Constantly switching files when dealing with dobis workflows is confusing. Not sure but I think that you cant access host's env var from a Dockerfile, with dobi you would/could.
$ tree ./docker
./docker
├── dobi
│ ├── binary.yaml
│ ├── db.yaml
│ ├── deploy.yaml
│ ├── prod.yaml
│ ├── tools.yaml
│ └── watch.yaml
├── files
│ ├── Dockerfile.build
│ ├── Dockerfile.deploy
│ ├── Dockerfile.prod
│ ├── Dockerfile.tools
│ └── Dockerfile.watch
├── kubernetes
│ ├── api.deploy.yaml
│ ├── api.yaml
│ └── scheduler.yaml
└── script
├── build.sh
├── deploy.sh
├── fmt.sh
├── lint.sh
├── test.sh
├── vet.sh
└── watch.sh