-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
docker-it.sh
executable file
·84 lines (66 loc) · 2.39 KB
/
docker-it.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
#!/bin/sh
#########################
# based on docker bin
packageName=$1
imageVersion=$2
dockerDestFolder=$3
env=$4
packageTZ=Asia/Shanghai
if [ "${packageName}" = "" ]; then
echo [ERROR] "Please provide image name as first param"
exit 1
fi
if [ "${imageVersion}" = "" ]; then
echo [ERROR] "Please provide image version as second param"
exit 1
fi
if [ "${dockerDestFolder}" = "" ]; then
echo [ERROR] "Please provide docker dest folder"
exit 1
fi
if [ "${env}" = "" ]; then
echo [ERROR] "Please provide env folder"
exit 1
fi
COUNT=`docker -v 2>&1 | grep 'version' | grep -v grep | wc -l`
if [ ${COUNT} != 1 ]; then
echo [ERROR] "Cannot find docker command"
exit 1
fi
echo [INFO] "Remove old image from docker repository..."
count=`docker images | grep "${packageName}" | grep "${imageVersion}" | wc -l`
if [ ${count} != 1 ]; then
echo [WARN] "image ${packageName} with version ${imageVersion} does not exist in docker repo"
else
docker rmi -f ${packageName}:${imageVersion}
fi
#generate Dockerfile dynamically
echo [INFO] "generating Dockerfile..."
warName=${packageName}-${imageVersion}.war
dateVersion=`date +%Y%m%d-%H%M%S`
#cat out to Dockerfile with content begin/end with EOF
cat > target/Dockerfile <<EOF
FROM debian:jessie
MAINTAINER Cliff Ma
COPY target/${warName} ${dockerDestFolder}/${dateVersion}/
ENV LANG C.UTF-8
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/${packageTZ} /etc/localtime && echo ${packageTZ} > /etc/timezone
RUN cd ${dockerDestFolder} \
&& ln -svnf ${dateVersion} current \
&& cd current \
&& touch docker-entrypoint.sh \
&& chmod +x docker-entrypoint.sh \
&& echo "/opt/apps/java/bin/java -jar ${dockerDestFolder}/current/*.war --spring.config.location=${dockerDestFolder}/current/env/application.properties >/dev/null 2>&1" > docker-entrypoint.sh
CMD .${dockerDestFolder}/current/docker-entrypoint.sh
EOF
# echo $TZ > /etc/timezone TO someString to one file.
# To set the right time.
# ENV TZ=Asia/Shanghai
# RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone
# COPY conf/${env}/*.cer ${dockerDestFolder}/${dateVersion}/
#read Dockerfile
echo [INFO] "Building image..."
docker build -t ${packageName}:${imageVersion} -f target/Dockerfile . || exit 1
echo [INFO] "Exporting image to target folder..."
docker save ${packageName}:${imageVersion} > target/${packageName}-${imageVersion}.image