Skip to content

Commit fcc3efb

Browse files
author
Ben Keil
committed
- renamed helper.go to imageutil.go
- image property in hydra.yaml now supports environment variables
1 parent afaf65b commit fcc3efb

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

cmd/cmd-build.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
)
1818

1919
type buildCmd struct {
20-
version string
21-
out io.Writer
22-
workdir string
23-
imageHelper ImageHelper
24-
push bool
20+
version string
21+
out io.Writer
22+
workdir string
23+
imageUtil ImageUtil
24+
push bool
2525
}
2626

2727
// BuildResponse contains the response from the docker client for "docker build"
@@ -30,7 +30,7 @@ type BuildResponse struct {
3030
}
3131

3232
func newBuildCmd(out io.Writer, workdir string) *cobra.Command {
33-
c := &buildCmd{out: out, workdir: workdir, imageHelper: NewDefaultImageHelper()}
33+
c := &buildCmd{out: out, workdir: workdir, imageUtil: NewDefaultImageUtil()}
3434

3535
cmd := &cobra.Command{
3636
Use: "build VERSION",
@@ -94,7 +94,7 @@ func (c *buildCmd) run() error {
9494
// Build image
9595
buildResponse, err := cli.ImageBuild(context.Background(), tarfile, types.ImageBuildOptions{
9696
PullParent: true,
97-
Tags: c.imageHelper.getImageTags(config, tags),
97+
Tags: c.imageUtil.getImageTags(config, tags),
9898
Context: tarfile,
9999
Dockerfile: dockerfile,
100100
})

cmd/cmd-push.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
)
1717

1818
type pushCmd struct {
19-
version string
20-
out io.Writer
21-
workdir string
22-
imageHelper ImageHelper
19+
version string
20+
out io.Writer
21+
workdir string
22+
imageUtil ImageUtil
2323
}
2424

2525
// PushResponse contains the response from the docker client for "docker build"
@@ -29,7 +29,7 @@ type PushResponse struct {
2929
}
3030

3131
func newPushCmd(out io.Writer, workdir string) *cobra.Command {
32-
c := &pushCmd{out: out, workdir: workdir, imageHelper: NewDefaultImageHelper()}
32+
c := &pushCmd{out: out, workdir: workdir, imageUtil: NewDefaultImageUtil()}
3333

3434
cmd := &cobra.Command{
3535
Use: "push VERSION",
@@ -70,7 +70,7 @@ func (c *pushCmd) run() error {
7070

7171
// Build image
7272
logger.Debugf("response from docker daemon:")
73-
for _, image := range c.imageHelper.getImageTags(config, tags) {
73+
for _, image := range c.imageUtil.getImageTags(config, tags) {
7474
fmt.Printf("push %s\n", image)
7575
pushResponse, err := cli.ImagePush(context.Background(), image, types.ImagePushOptions{
7676
RegistryAuth: "hydra",

cmd/helper.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

cmd/imageutil.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
// ImageUtil provides some helper methods
9+
type ImageUtil interface {
10+
getImageTags(config Config, tags []string) []string
11+
}
12+
13+
// DefaultImageUtil is the default implementation for the ImageUtil interface
14+
type DefaultImageUtil struct {
15+
}
16+
17+
// NewDefaultImageUtil creates a new instance of DefaultImageUtil
18+
func NewDefaultImageUtil() *DefaultImageUtil {
19+
return new(DefaultImageUtil)
20+
}
21+
22+
// getImageTags returns the complete image name (including registry url, image name and tag)
23+
func (helper *DefaultImageUtil) getImageTags(config Config, tags []string) []string {
24+
// Define all images we want to build
25+
imageTags := []string{}
26+
for _, image := range config.Image {
27+
for _, tag := range tags {
28+
imageTags = append(imageTags, fmt.Sprintf("%s:%s", os.ExpandEnv(image), tag))
29+
}
30+
}
31+
return imageTags
32+
}

examples/nginx-base/hydra.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
image:
2-
- my.private.registry:5000/docker-common/nginx-base
2+
- ${DOCKER_REGISTRY}/docker-common/nginx-base
33
versions:
4-
- directory: .
5-
args:
6-
dockerfile:
7-
tags:
4+
- tags:
85
- semver-nginx
96
- semver
107
- nginx

0 commit comments

Comments
 (0)