forked from oracle/docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerBuild.sh
executable file
·164 lines (150 loc) · 5.16 KB
/
dockerBuild.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
# Since: July, 2017
# Author: Stephen Balousek <[email protected]>
# Description: Create a Docker image from an Oracle GoldenGate ZIP distribution.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
##
## Locate a command on the local system
##
function getCommand {
local primary=$1; shift
local alternate=$*
for check in ${alternate} ${primary}; do
command=$(command -v ${check} 2>/dev/null) && break
done
[[ -z "${command}" ]] && {
[[ -n "${alternate}" ]] && echo "Error: Cannot locate command ${primary} or ${alternate}" \
|| echo "Error: Cannot locate command ${primary}"
exit 1
}
cmdname=$(echo ${primary} | tr a-z A-Z)
eval "${cmdname}=\"${command}\""
}
##
## Required commands
##
getCommand tr
getCommand awk gawk
getCommand basename
getCommand dirname
getCommand docker
getCommand find
getCommand readlink greadlink
getCommand strings
getCommand tar gtar
##
## Display Usage
##
if [[ "${1:--h}" == "-h" ]]; then
echo "Oracle GoldenGate distribution ZIP file not specified."
echo ""
echo "Usage: $(${BASENAME} $0) [-h | <ogg-zip-file-name>] [<docker-build-options> ...]"
echo "Where:"
echo " ogg-zip-file-name Name of OGG ZIP file"
echo " docker-build-options Command line options for Docker build"
echo ""
echo "Example:"
echo " ./$(${BASENAME} $0) ~/Downloads/123014_fbo_ggs_Linux_x64_services_shiphome.zip --no-cache"
exit 1
fi
function getTargetFilename {
local Target="$1"
if [[ "$(uname)" == "Linux" ]]; then
${READLINK} -f "${Target}"
else
while ( true ); do
cd $(${DIRNAME} "${Target}")
Target=$(${BASENAME} "${Target}")
[[ ! -L "${Target}" ]] && break
Target=$(${READLINK} "${Target}")
done
echo $(pwd -P)/${Target}
fi
}
OGG_DISTFILE="$(getTargetFilename $1)"
if [[ ! -f "${OGG_DISTFILE}" ]]; then
echo "Oracle GoldenGate distribution ZIP file '$1' not found."
exit 1
fi
shift
TEMP_DIRECTORY="$(mktemp -d)"
cp -a "$(${DIRNAME} $(command -v $0))"/* "${TEMP_DIRECTORY}"
pushd "${TEMP_DIRECTORY}" &>/dev/null
function cleanupAndExit {
rm -fr "${TEMP_DIRECTORY}"
exit ${1-1}
}
trap cleanupAndExit SIGTERM SIGINT
if [[ "${OGG_DISTFILE/.zip/}" != "${OGG_DISTFILE}" ]]; then
getCommand unzip
targetJAR="*/Disk1/stage/Components/oracle.oggcore.*ora12c/*/1/DataFiles/filegroup1.jar"
OGG_JARFILE="$(${UNZIP} -qp ${OGG_DISTFILE} ${targetJAR} 2>/dev/null > $(${BASENAME} ${targetJAR}) && echo $(${BASENAME} ${targetJAR}) || rm $(${BASENAME} ${targetJAR}))"
[[ "${OGG_JARFILE}" != "" ]] && {
OGG_TARFILE="$(${BASENAME} ${OGG_DISTFILE} .zip).tar"
} || {
OGG_TARFILE="$(${UNZIP} -o ${OGG_DISTFILE} *.tar* 2>/dev/null | ${AWK} '/.*[.]tar/ { print $NF; exit 0 }')"
}
fi
if [[ "${OGG_DISTFILE/.tgz/}" != "${OGG_DISTFILE}" ]]; then
getCommand gzip pigz
OGG_TARFILE="$(${BASENAME} ${OGG_DISTFILE} .tgz).tar"
${GZIP} -d < "${OGG_DISTFILE}" > "${OGG_TARFILE}"
fi
if [[ "${OGG_DISTFILE/.tar/}" != "${OGG_DISTFILE}" ]]; then
OGG_TARFILE="$(${BASENAME} ${OGG_DISTFILE})"
if [[ "${OGG_DISTFILE}" != $(getTargetFilename "${OGG_TARFILE}") ]]; then
cp -a "${OGG_DISTFILE}" "${OGG_TARFILE}"
fi
fi
function getVersion {
local Version=$(${STRINGS} $1 2>/dev/null | ${AWK} '/^Version[ ][12]/ {print $2; exit 0;}')
[[ -n ${Version} ]] && \
echo ${Version}
}
function hasTag {
while [[ -n "$1" ]]; do
[[ "$1" == "--tag" || "$1" == "-t" ]] && return 0
shift
done
return 1
}
mkdir ggstar
[[ -n "${OGG_JARFILE}" ]] && {
getCommand unzip
${UNZIP} -q ${OGG_JARFILE} -d ggstar
rm -f ${OGG_JARFILE}
} || {
[[ ! -z "${OGG_TARFILE}" ]] && ${TAR} Cxf ggstar ${OGG_TARFILE}
}
OGG_VERSION=$(getVersion ggstar/keygen) && {
OGG_EDITION="standard"
} || {
OGG_VERSION=$(getVersion ggstar/bin/keygen) && {
OGG_EDITION="microservices"
} || {
rm -fr ggstar
echo "Distribution file '${OGG_DISTFILE}' does not appear to be a GoldenGate ZIP distribution"
cleanupAndExit 1
}
}
${FIND} ggstar -type f \( -name '*.so*' -o -not -name '*.*' \) -exec chmod +x {} \;
${TAR} Ccf ggstar ${OGG_TARFILE} --owner=54321 --group=54321 .
rm -fr ggstar
[[ -n "${BASE_IMAGE}" ]] && BASE_IMAGE_ARG="--build-arg BASE_IMAGE=${BASE_IMAGE}"
[[ -n "${http_proxy}" ]] && HTTP_PROXY_ARG="--build-arg http_proxy=${http_proxy}"
[[ -n "${https_proxy}" ]] && HTTPS_PROXY_ARG="--build-arg https_proxy=${https_proxy}"
if ( ! hasTag "$@" ); then
DEFAULT_TAG="--tag oracle/goldengate-${OGG_EDITION}:${OGG_VERSION}"
fi
"${DOCKER}" build ${BASE_IMAGE_ARG} \
${HTTP_PROXY_ARG} ${HTTPS_PROXY_ARG} \
--build-arg OGG_VERSION=${OGG_VERSION} \
--build-arg OGG_EDITION=${OGG_EDITION} \
--build-arg OGG_TARFILE=${OGG_TARFILE} \
${DEFAULT_TAG} "$@" .
cleanupAndExit $?