Skip to content

Commit 64043fe

Browse files
author
Thomas Goodwin
committed
Changed to manual 'deploy' of docker image
DockerHub does not support deploy keys or anything quite like it, only short-lived tokens returned once you log in with a user/pass combination, which means the CI setup would have to expose those keys for an actual user on their site that has write access to the image in question. The work-around right now is to make the deploy create the tagged image and push it to the local repo. "Someone" will need to set their notifications to hear successful pipeline completions and do the work of then pushing it to the public repo and cleaning the internal registry. Also changed the 'clean' script since the variables aren't expanding quite as expected.
1 parent fb7cf2f commit 64043fe

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

.gitlab-ci.yml

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
variables:
44
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
55
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
6+
CONTAINER_TAGGED_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
67
DOCKERHUB_IMAGE: geontech/redhawk-webserver
8+
REDHAWK_VERSION: 2.0.8
79

810
stages:
911
- build
@@ -46,10 +48,10 @@ test:
4648
script:
4749
# Install docker-compose
4850
- apk add --no-cache py2-pip && pip install docker-compose
49-
5051
# Pull the test image and start the stack without rebuilding it.
5152
- cd tests
5253
- docker pull ${CONTAINER_TEST_IMAGE}
54+
- export REDHAWK_VERSION=$REDHAWK_VERSION
5355
- export CONTAINER_TEST_IMAGE=$CONTAINER_TEST_IMAGE
5456
- docker-compose -p ${CI_COMMIT_SHA} up -d --no-build
5557
- docker-compose -p ${CI_COMMIT_SHA} images
@@ -77,26 +79,18 @@ release:
7779
- docker push $CONTAINER_RELEASE_IMAGE
7880
- docker rmi $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
7981

80-
# Push the released image to DockerHub on tags
82+
# Deploy internally, tagged.
8183
deploy-image:
8284
stage: deploy
8385
only:
8486
- tags
8587
<<: *container_registry
86-
variables:
87-
dockerhub_image_tag: geontech/redhawk-webserver:$CI_COMMIT_TAG
88-
dockerhub_image_latest: geontech/redhawk-webserver:latest
8988
script:
90-
# Use JQ to patch in our dockerhub credentials for the public push
91-
- apk add --no-cache jq
92-
- "jq --arg token \"$DOCKERHUB_TOKEN\" '.auths[\"https://index.docker.io/v1\"] = { auth: $token }' ~/.docker/config.json > ~/.docker/config.json"
9389
# Pull the release image, re-tag it to the dockerhub name and push it.
9490
- docker pull $CONTAINER_RELEASE_IMAGE
95-
- docker tag $CONTAINER_RELEASE_IMAGE ${dockerhub_image_tag}
96-
- docker tag $CONTAINER_RELEASE_IMAGE ${dockerhub_image_latest}
97-
- docker push ${dockerhub_image_tag}
98-
- docker push ${dockerhub_image_latest}
99-
- docker rmi ${CONTAINER_RELEASE_IMAGE} ${dockerhub_image_tag} ${dockerhub_image_latest}
91+
- docker tag $CONTAINER_RELEASE_IMAGE $CONTAINER_TAGGED_IMAGE
92+
- docker push $CONTAINER_TAGGED_IMAGE
93+
- docker rmi $CONTAINER_RELEASE_IMAGE $CONTAINER_TAGGED_IMAGE
10094

10195
# Push to GitHub
10296
deploy-github:
@@ -105,9 +99,9 @@ deploy-github:
10599
- tags
106100
image: alpine
107101
script:
108-
- apk add --no-cache openssh-client git
102+
- apk add --no-cache openssh-client git bash
109103
- eval $(ssh-agent -s)
110-
- echo "$GITHUB_TOKEN" | ssh-add -
104+
- bash -c 'ssh-add <(echo "$GITHUB_TOKEN")'
111105
- mkdir -p ~/.ssh
112106
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
113107
# Configure git and push w/ tag(s)
@@ -116,29 +110,28 @@ deploy-github:
116110
- git remote set-url origin ${GITHUB_REPO}
117111
- git push origin ${GITHUB_BRANCH} --follow-tags
118112

119-
# Template for cleaning the image registry
120-
.clean-image: &clean-image
121-
stage: cleanup
122-
<<: *container_registry
123-
script:
124-
- apk add --no-cache git bash curl
125-
- git clone ${DOCKER_UTILS} docker-util
126-
- docker-util/delete-image.sh $clean_target_image
127-
128113
# Clean dev/test images not on master branch
129114
clean-dev:
115+
stage: cleanup
116+
<<: *container_registry
130117
when: always
131-
variables:
132-
clean_target_image: $CONTAINER_TEST_IMAGE
133118
except:
134119
- master
135120
- tags
136-
<<: *clean-image
121+
script:
122+
- apk add --no-cache git bash curl
123+
- git clone ${DOCKER_UTILS} docker-util
124+
- docker-util/delete-image.sh $CONTAINER_TEST_IMAGE
137125

138126
# Cleanup the locally stored image after tagging and pushing to public
127+
# This has to be manual since deploying to Dockerhub is manual too.
139128
clean-internal:
140-
variables:
141-
clean_target_image: $CONTAINER_RELEASE_IMAGE
129+
stage: cleanup
130+
<<: *container_registry
131+
when: manual
142132
only:
143133
- tags
144-
<<: *clean-image
134+
script:
135+
- apk add --no-cache git bash curl
136+
- git clone ${DOCKER_UTILS} docker-util
137+
- docker-util/delete-image.sh $CONTAINER_RELEASE_IMAGE

0 commit comments

Comments
 (0)