This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·49 lines (40 loc) · 1.97 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Author: Peter Schussheim
# Purpose: This script is intended to run towards to end of a CI/CD pipeline.
# Image we have a CI process that builds/tests source code, then in another
# step, we initiate a process to build, tag and push docker 'parent' images to
# a registry. Using a hash provided by our CI platform (CIRCLE_SHA1), we can use
# this as a tag for images.
# In an effort to automate as much as possible, and due to limitations of
# the 'zeit now' deployment platform, we need to define a mechanism to
# dynamically inject the CIRCLE_SHA1 variable into a Dockerfile 'template',
# which produces a minimal 'child' image for a given CIRCLE_SHA1 base_image.
# For example, imagine we have the following Dockerfile 'template':
################################################################################
# FROM gammaprod/%%BASE%%:%%TAG%%
# ENV TAG %%TAG%%
################################################################################
# Example (provided by our CI config and env):
################################################################################
# $BASE=web
# $TAG=5b0e8b2
################################################################################
# We want to call this script to update local template Dockerfiles, eg:
################################################################################
# FROM gammaprod/web:5b0e8b2
################################################################################
# Now that we have a 'fresh' Dockerfile with the desired build, we can deploy
# the application normally (as normal os possible) using now-cli using an
# additional job in our CI platform.
# USAGE:
# ./update.sh web ${TAG} ${DOCKER_HUB_ORG}
set -Eeuo pipefail
BASE_IMAGE=${1?Error: BASE_IMAGE not given}
TAG=${2-:Error: TAG not given}
DOCKER_HUB_ORG=${3-:Error: DOCKER_HUB_ORG not given}
IMAGE_VERSION=$BASE_IMAGE:$TAG
cat <<EOF > Dockerfile
# DO NOT MODIFY THIS FILE. THIS FILE HAS BEEN AUTOGENERATED
FROM $DOCKER_HUB_ORG/$IMAGE_VERSION
EOF
exit 0