-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdx.sh
109 lines (90 loc) · 3.02 KB
/
dx.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# /bin/bash
# the docker hub account where the images are hosted
DOCKER_HUB_ACCOUNT="krsyoung"
DEFAULT_IMAGE="rails-dev"
function help () {
echo "** rails docker image tooling **"
echo
echo "commands:"
echo " build <image> <version> - build the image and tag as latest"
echo " freshen <image> <version> - build the image, tag as latest and push to Docker Hub"
echo " push <image> <version> - push the version to Docker Hub"
echo " release <image> <version> - add the version tag to latest and push to Docker Hub"
echo " update <image> <version> - build, tag with latest, push and tag with the version"
echo " images - list the available images"
echo
echo "example (test and release): "
echo "1. install latest packages for rails-dev 3.3.6 image"
echo " > freshen rails-dev 3.3.6"
echo "2. after testing, promote latest image to new 3.3.6 tag"
echo " > release rails-dev 3.3.6"
echo
echo "example (full send, skips testing): "
echo "1. build, tag and deploy an updated image rails-dev 3.3.6 image"
echo " > update rails-dev 3.3.6"
echo
}
function images () {
echo "images:"
echo " - rails-dev"
}
# login to docker
function login () {
docker login --username=$DOCKER_HUB_ACCOUNT
}
# build image
function build () {
image=$1
version=$2
[ -z "$image" ] && echo "Error: need an image." && return 1
[ -z "$version" ] && echo "Error: need a version." && return 1
echo "Building $image:$version"
dockerfile="$image/Dockerfile-$version"
if [ ! -f $dockerfile ]; then
echo "Error: no Dockerfile found at $dockerfile"
return 1
fi
# build, without cache and apply a version tag based on the ruby version
docker build --no-cache -f $dockerfile -t $DOCKER_HUB_ACCOUNT/$image:$version $image/
}
# build image and tag with current date
function freshen () {
image=$1
version=$2
[ -z "$image" ] && echo "Error: need an image." && return 1
[ -z "$version" ] && echo "Error: need a version." && return 1
echo "Freshening $image-$version"
build $image $version
push $image latest
}
function push () {
image=$1
version=$2
[ -z "$image" ] && echo "Error: need an image." && return 1
[ -z "$version" ] && echo "Error: need a version." && return 1
echo "Pushing $image:$version"
docker push "$DOCKER_HUB_ACCOUNT/$image:$version"
}
# tag an exiting image as latest and push
function release () {
image=$1
version=$2
[ -z "$image" ] && echo "Error: need an image." && return 1
[ -z "$version" ] && echo "Error: need a version." && return 1
echo "Releasing $image:$version"
# tag the specific version with latest
push $image $version
docker tag $DOCKER_HUB_ACCOUNT/$image:$version $DOCKER_HUB_ACCOUNT/${image}:latest
push $image latest
}
# build image and tag with current date
function update () {
image=$1
version=$2
[ -z "$image" ] && echo "Error: need an image." && return 1
[ -z "$version" ] && echo "Error: need a version." && return 1
echo "Updating $image:$version"
build $image $version
release $image $version
}
help