Skip to content

Commit

Permalink
- renamed helper.go to imageutil.go
Browse files Browse the repository at this point in the history
- image property in hydra.yaml now supports environment variables
  • Loading branch information
Ben Keil committed Mar 10, 2018
1 parent afaf65b commit fcc3efb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
14 changes: 7 additions & 7 deletions cmd/cmd-build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

type buildCmd struct {
version string
out io.Writer
workdir string
imageHelper ImageHelper
push bool
version string
out io.Writer
workdir string
imageUtil ImageUtil
push bool
}

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

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

cmd := &cobra.Command{
Use: "build VERSION",
Expand Down Expand Up @@ -94,7 +94,7 @@ func (c *buildCmd) run() error {
// Build image
buildResponse, err := cli.ImageBuild(context.Background(), tarfile, types.ImageBuildOptions{
PullParent: true,
Tags: c.imageHelper.getImageTags(config, tags),
Tags: c.imageUtil.getImageTags(config, tags),
Context: tarfile,
Dockerfile: dockerfile,
})
Expand Down
12 changes: 6 additions & 6 deletions cmd/cmd-push.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
)

type pushCmd struct {
version string
out io.Writer
workdir string
imageHelper ImageHelper
version string
out io.Writer
workdir string
imageUtil ImageUtil
}

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

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

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

// Build image
logger.Debugf("response from docker daemon:")
for _, image := range c.imageHelper.getImageTags(config, tags) {
for _, image := range c.imageUtil.getImageTags(config, tags) {
fmt.Printf("push %s\n", image)
pushResponse, err := cli.ImagePush(context.Background(), image, types.ImagePushOptions{
RegistryAuth: "hydra",
Expand Down
31 changes: 0 additions & 31 deletions cmd/helper.go

This file was deleted.

32 changes: 32 additions & 0 deletions cmd/imageutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"os"
)

// ImageUtil provides some helper methods
type ImageUtil interface {
getImageTags(config Config, tags []string) []string
}

// DefaultImageUtil is the default implementation for the ImageUtil interface
type DefaultImageUtil struct {
}

// NewDefaultImageUtil creates a new instance of DefaultImageUtil
func NewDefaultImageUtil() *DefaultImageUtil {
return new(DefaultImageUtil)
}

// getImageTags returns the complete image name (including registry url, image name and tag)
func (helper *DefaultImageUtil) getImageTags(config Config, tags []string) []string {
// Define all images we want to build
imageTags := []string{}
for _, image := range config.Image {
for _, tag := range tags {
imageTags = append(imageTags, fmt.Sprintf("%s:%s", os.ExpandEnv(image), tag))
}
}
return imageTags
}
7 changes: 2 additions & 5 deletions examples/nginx-base/hydra.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
image:
- my.private.registry:5000/docker-common/nginx-base
- ${DOCKER_REGISTRY}/docker-common/nginx-base
versions:
- directory: .
args:
dockerfile:
tags:
- tags:
- semver-nginx
- semver
- nginx
Expand Down

0 comments on commit fcc3efb

Please sign in to comment.