Implement Docker build arguments

This commit is contained in:
Radu Matei 2018-05-20 18:46:19 +03:00
Родитель 0770658363
Коммит 433dac9a07
4 изменённых файлов: 29 добавлений и 17 удалений

Просмотреть файл

@ -40,6 +40,7 @@ The format of this file is as follows:
custom-tags = ["latest", "backend-staging"]
override-ports = ["8080:8080"]
chart = "my-app-staging"
image-build-args = { BUILD_TIME_ARG = "build-time-argument-value", HTTP_PROXY = "http://my-proxy" }
```
Let's break it down by section:
@ -76,6 +77,7 @@ name at runtime using `draft up --environment=staging`.
custom-tags = ["latest", "backend-staging"]
chart = "javascript"
dockerfile = "Dockerfile"
image-build-args = { BUILD_TIME_ARG = "build-time-argument-value", HTTP_PROXY = "http://my-proxy" }
resource-group-name = "foo"
```
@ -98,6 +100,7 @@ Here is a run-down on each of the fields:
- `custom-tags`: specifies the custom tags Draft will push to the container registry. Note that Draft will push and use the computed SHA of the application as the tag of your image for the Helm chart.
- `chart`: the name of the directory in `charts/` that will be used to release the application for this environment
- `dockerfile`: the name of the Dockerfile that will be used to build the image for this environment
- `image-build-args`: arguments to pass at image build time. [Follow Docker best practices about passing build time argumetns][docker-build-args]
- `resource-group-name`: the name of the resource group hosting the container registry. Only used when the container builder is set to `acrbuild`
> Note: It is recommended to [avoid fixed image tags (like `latest`, `canary`, `dev`) in production](https://kubernetes.io/docs/concepts/configuration/overview#container-images), and if the image tag is the same in your chart, Helm will not upgrade your release.
@ -140,5 +143,6 @@ JSON certainly has its place and is stricter than YAML on field types, but it is
[ACR Build]: https://aka.ms/acr/build
[helm#1707]: https://github.com/kubernetes/helm/issues/1707#issuecomment-268347183
[toml]: https://github.com/toml-lang/toml
[docker-build-args]: https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg
[dep007]: dep-007.md
[dep009]: dep-009.md

Просмотреть файл

@ -32,9 +32,16 @@ func (b *Builder) Build(ctx context.Context, app *builder.AppContext, out chan<-
msgc := make(chan string)
errc := make(chan error)
go func() {
args := make(map[string]*string)
for k := range app.Ctx.Env.ImageBuildArgs {
v := app.Ctx.Env.ImageBuildArgs[k]
args[k] = &v
}
buildopts := types.ImageBuildOptions{
Tags: app.Images,
Dockerfile: app.Ctx.Env.Dockerfile,
BuildArgs: args,
}
resp, err := b.DockerClient.Client().ImageBuild(ctx, app.Buf, buildopts)

Просмотреть файл

@ -25,22 +25,23 @@ type Manifest struct {
// Environment represents the environment for a given app at build time
type Environment struct {
Name string `toml:"name,omitempty"`
ContainerBuilder string `toml:"container-builder,omitempty"`
Registry string `toml:"registry,omitempty"`
ResourceGroupName string `toml:"resource-group-name,omitempty"`
BuildTarPath string `toml:"build-tar,omitempty"`
ChartTarPath string `toml:"chart-tar,omitempty"`
Namespace string `toml:"namespace,omitempty"`
Values []string `toml:"set,omitempty"`
Wait bool `toml:"wait"`
Watch bool `toml:"watch"`
WatchDelay int `toml:"watch-delay,omitempty"`
OverridePorts []string `toml:"override-ports,omitempty"`
AutoConnect bool `toml:"auto-connect"`
CustomTags []string `toml:"custom-tags,omitempty"`
Dockerfile string `toml:"dockerfile"`
Chart string `toml:"chart"`
Name string `toml:"name,omitempty"`
ContainerBuilder string `toml:"container-builder,omitempty"`
Registry string `toml:"registry,omitempty"`
ResourceGroupName string `toml:"resource-group-name,omitempty"`
BuildTarPath string `toml:"build-tar,omitempty"`
ChartTarPath string `toml:"chart-tar,omitempty"`
Namespace string `toml:"namespace,omitempty"`
Values []string `toml:"set,omitempty"`
Wait bool `toml:"wait"`
Watch bool `toml:"watch"`
WatchDelay int `toml:"watch-delay,omitempty"`
OverridePorts []string `toml:"override-ports,omitempty"`
AutoConnect bool `toml:"auto-connect"`
CustomTags []string `toml:"custom-tags,omitempty"`
Dockerfile string `toml:"dockerfile"`
Chart string `toml:"chart"`
ImageBuildArgs map[string]string `toml:"image-build-args,omitempty"`
}
// New creates a new manifest with the Environments intialized.

Просмотреть файл

@ -8,7 +8,7 @@ import (
func TestNew(t *testing.T) {
m := New()
m.Environments[DefaultEnvironmentName].Name = "foobar"
expected := "&{foobar default [] true false 2 [] false [] }"
expected := "&{foobar default [] true false 2 [] false [] map[]}"
actual := fmt.Sprintf("%v", m.Environments[DefaultEnvironmentName])
if expected != actual {