Skip to content

Commit 99ccce4

Browse files
author
Matthew Fisher
committed
fix(controller): use build image for publishing releases
1 parent b4acf66 commit 99ccce4

3 files changed

Lines changed: 12 additions & 19 deletions

File tree

builder/templates/builder

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ GIT_SHA=$(get_git_sha $REPO_DIR $BRANCH)
6161
SHORT_SHA=${GIT_SHA:0:8}
6262

6363
# define image names
64-
TMP_IMAGE="${APP_NAME}:git-${SHORT_SHA}"
65-
TARGET_IMAGE="{{ .deis_registry_host }}:{{ .deis_registry_port }}/${APP_NAME}"
66-
IMAGE_REFERENCE=$APP_NAME
64+
IMAGE_NAME="$APP_NAME:git-$SHORT_SHA"
65+
TMP_IMAGE="{{ .deis_registry_host }}:{{ .deis_registry_port }}/$IMAGE_NAME"
6766

6867
# create app directories
6968
mkdir -p $BUILD_DIR $CACHE_DIR
@@ -142,10 +141,8 @@ fi
142141
echo
143142
puts-step "Building Docker image"
144143
docker build -t $TMP_IMAGE . 2>&1
145-
docker tag $TMP_IMAGE $TARGET_IMAGE
146-
147144
puts-step "Pushing image to private registry"
148-
docker push $TARGET_IMAGE &>/dev/null
145+
docker push $TMP_IMAGE &>/dev/null
149146
echo
150147

151148
if [ -f $TMP_DIR/slug.tgz ]; then
@@ -169,7 +166,7 @@ DOCKERFILE=$(echo $DOCKERFILE | sed -e 's/\"/\\\"/g')
169166

170167
puts-step "Launching... "
171168
URL="{{ .deis_controller_protocol }}://{{ .deis_controller_host }}:{{ .deis_controller_port }}/api/hooks/build"
172-
DATA="{\"sha\":\"$GIT_SHA\",\"receive_user\":\"$USER\",\"receive_repo\":\"$APP_NAME\",\"image\":\"$IMAGE_REFERENCE\",\"procfile\":\"$RELEASE_INFO\",\"dockerfile\":\"$DOCKERFILE\"}"
169+
DATA="{\"sha\":\"$SHORT_SHA\",\"receive_user\":\"$USER\",\"receive_repo\":\"$APP_NAME\",\"image\":\"$APP_NAME\",\"procfile\":\"$RELEASE_INFO\",\"dockerfile\":\"$DOCKERFILE\"}"
173170

174171
# notify the controller that the push was successful
175172
RESPONSE=$(curl -s -XPOST \
@@ -199,4 +196,4 @@ echo
199196
cd $REPO_DIR
200197
git gc &>/dev/null
201198
docker rm -f $JOB &>/dev/null
202-
docker rmi -f $TMP_IMAGE $TARGET_IMAGE &>/dev/null
199+
docker rmi -f $TMP_IMAGE &>/dev/null

controller/api/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ def create(self, request, *args, **kwargs):
493493
def post_save(self, build, created=False):
494494
if created:
495495
release = build.app.release_set.latest()
496-
new_release = release.new(build.owner, build=build)
496+
source_version = 'latest'
497+
if build.sha:
498+
source_version = 'git-{}'.format(build.sha)
499+
new_release = release.new(build.owner, build=build, source_version=source_version)
497500
initial = True if build.app.structure == {} else False
498501
try:
499502
build.app.deploy(build.owner, new_release, initial=initial)

controller/registry/private.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def publish_release(source, config, target):
5959
image['id'] = _new_id()
6060
config['DEIS_APP'] = target_image
6161
config['DEIS_RELEASE'] = target_tag
62-
image['config']['Env'] = _construct_env(image['config']['Env'], config)
62+
image['config']['Env'] = _construct_env(config)
6363
# update and tag the new image
6464
_commit(target_image, image, _empty_tar_archive(), target_tag)
6565

@@ -162,17 +162,10 @@ def _put_tag(image_id, repository_path, tag):
162162

163163
# utility functions
164164

165-
def _construct_env(env, config):
165+
def _construct_env(config):
166166
"Update current environment with latest config"
167167
new_env = []
168-
# see if we need to update existing ENV vars
169-
for e in env:
170-
k, v = e.split('=', 1)
171-
if k in config:
172-
# update values defined by config
173-
v = config.pop(k)
174-
new_env.append("{}={}".format(encode(k), encode(v)))
175-
# add other config ENV items
168+
# add config ENV items
176169
for k, v in config.items():
177170
new_env.append("{}={}".format(encode(k), encode(v)))
178171
return new_env

0 commit comments

Comments
 (0)