changed to unmaintained
[aaf/authz.git] / auth / docker / dbuild.sh
1
2 #########
3 #  ============LICENSE_START====================================================
4 #  org.onap.aaf
5 #  ===========================================================================
6 #  Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 #  ===========================================================================
8 #  Licensed under the Apache License, Version 2.0 (the "License");
9 #  you may not use this file except in compliance with the License.
10 #  You may obtain a copy of the License at
11 #
12 #       http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #  Unless required by applicable law or agreed to in writing, software
15 #  distributed under the License is distributed on an "AS IS" BASIS,
16 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 #  See the License for the specific language governing permissions and
18 #  limitations under the License.
19 #  ============LICENSE_END====================================================
20 #
21 # Docker Building Script.  Reads all the components generated by install, on per-version basis
22 #
23
24 # Pull in Variables from d.props
25 if [ ! -e ./d.props ]; then
26     cp d.props.init d.props
27 fi
28
29 . ./d.props
30
31 # Remove "SNAPSHOT" from AAF Jars in Containers
32 JAR_VERSION=${VERSION/-SNAPSHOT/}
33
34 function SCP() {
35   SANS=${1/-SNAPSHOT/}
36   echo $1 = $SANS
37   if [ -e $SANS ]; then
38     cp $SANS $2
39   else 
40  
41     ln $1 $SANS
42     cp $SANS $2
43     rm $SANS
44   fi
45 }
46
47 # process input. originally, an optional positional parameter is used to designate a component.
48 # A flagged parameter has been added to optionally indicate docker pull registry. Ideally, options
49 # would be flagged but we're avoiding ripple effect of changing original usage
50 if [ $# -gt 0 ]; then
51     if [ "$1" == "-r" ]; then
52         DOCKER_PULL_REGISTRY=$2
53     else
54         AAF_COMPONENTS=$1
55         if [[ $# -gt 1 && $2 == "-r" ]]; then
56             # If docker.io is indicated, registry var is void as that is docker default
57             if [ $3 == "docker.io" ]; then
58                 DOCKER_PULL_REGISTRY=''
59             else
60                 DOCKER_PULL_REGISTRY=$3
61             fi
62            shift
63         fi
64     fi
65 fi
66
67 grep -v '#' d.props | grep '=' | grep -v -e "=$"
68
69 DOCKER=${DOCKER:=docker}
70
71 ########
72 # Preliminary: if Cass exists, build that first
73 if [[ -z "$1" || "$1" = "cass" ]]; then
74   echo "#### Delegate to Cassandra build"
75   echo "Building Containers for aaf components, version $VERSION"
76   # AAF_cass now needs a version...
77   echo "### Build Cass"
78   cd ../auth-cass/docker
79   bash ./dbuild.sh $DOCKER_PULL_REGISTRY
80   cd -
81 fi
82
83 if [[ -z "$1" || "$1" = "base" ]]; then
84   ########
85   # First, build a AAF Base version - set the core image, etc
86   echo "### Build Base"
87   sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
88       -e 's/${JAR_VERSION}/'${JAR_VERSION}'/g' \
89       -e 's/${DUSER}/'${DUSER}'/g' \
90       -e 's/${REGISTRY}/'${DOCKER_PULL_REGISTRY}'/g' \
91       Dockerfile.base > Dockerfile
92   $DOCKER build -t ${ORG}/${PROJECT}/aaf_base:${VERSION} .
93   $DOCKER tag ${ORG}/${PROJECT}/aaf_base:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_base:${VERSION}
94   $DOCKER tag ${ORG}/${PROJECT}/aaf_base:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_base:latest
95   rm Dockerfile
96 fi  
97   
98 # Common copies
99 cd ..
100 SCP ../cadi/aaf/target/aaf-cadi-aaf-${VERSION}-full.jar sample/bin
101
102 if [[ -z "$1" || "$1" = "config" ]]; then
103   ########
104   # Second, Create the AAF Config (Security) Images
105   # Note: only 2 jars each in Agent/Config
106   SCP auth-cmd/target/aaf-auth-cmd-$VERSION-full.jar sample/bin
107   SCP auth-batch/target/aaf-auth-batch-$VERSION-full.jar sample/bin
108   SCP ../cadi/servlet-sample/target/aaf-cadi-servlet-sample-${VERSION}-sample.jar sample/bin
109   cp -Rf ../conf/CA sample
110   
111   # AAF Config image (for AAF itself)
112   echo "### Build Config"
113   sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
114       -e 's/${JAR_VERSION}/'${JAR_VERSION}'/g' \
115       -e 's/${AAF_COMPONENT}/'${AAF_COMPONENT}'/g' \
116       -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
117       -e 's/${DUSER}/'${DUSER}'/g' \
118       docker/Dockerfile.config > sample/Dockerfile
119   # Note: do Config as Root, to get directories correct
120   $DOCKER build -t ${ORG}/${PROJECT}/aaf_config:${VERSION} sample
121   $DOCKER tag ${ORG}/${PROJECT}/aaf_config:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_config:${VERSION}
122   $DOCKER tag ${ORG}/${PROJECT}/aaf_config:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_config:latest
123 fi  
124
125 if [[ -z "$1" || "$1" = "agent" ]]; then
126   # AAF Agent Image (for Clients)
127   echo "### Build Agent"
128   sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
129       -e 's/${JAR_VERSION}/'${JAR_VERSION}'/g' \
130       -e 's/${AAF_COMPONENT}/'${AAF_COMPONENT}'/g' \
131       -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
132       -e 's/${DUSER}/'${DUSER}'/g' \
133       docker/Dockerfile.agent > sample/Dockerfile
134   #if [ -n "$DUSER" ]; then
135   # echo "USER $DUSER" >> sample/Dockerfile
136   #fi
137   $DOCKER build -t ${ORG}/${PROJECT}/aaf_agent:${VERSION} sample
138   $DOCKER tag ${ORG}/${PROJECT}/aaf_agent:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_agent:${VERSION}
139   $DOCKER tag ${ORG}/${PROJECT}/aaf_agent:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_agent:latest
140
141 fi
142
143 # Clean up 
144 rm -Rf sample/Dockerfile sample/bin/aaf-*-*.jar sample/CA
145 cd -
146
147 ########
148 # Third Copy AAF Executables to a BUILD Directory, for easy Cleanup
149 echo "### Copy to aaf_DBUILD"
150 if [ -e "../aaf_$VERSION" ]; then
151   cp -Rf ../aaf_$VERSION ../aaf_DBUILD
152 elif [ -e "../aaf_$JAR_VERSION" ]; then
153   cp -Rf ../aaf_$JAR_VERSION ../aaf_DBUILD
154 else
155   echo "ERROR: No AAF Built.  use Maven"
156   exit
157 fi
158 if [ ! "$VERSION" = "$JAR_VERSION" ]; then 
159   START_DIR=$(pwd)
160   # Convert SNAPSHOT issues
161   cp -Rf ../aaf_$VERSION ../aaf_DBUILD
162   cd ../aaf_DBUILD/lib
163   # If Built Jars are "SNAPSHOT", convert to NON SNAPSHOT
164   for J in $(ls *-SNAPSHOT*); do mv $J ${J/-SNAPSHOT/}; done
165   cd ../bin
166   rm *.bat
167   for S in $(ls); do
168      sed -e "/$VERSION/s/$VERSION/$JAR_VERSION/g" $S > tmp
169      mv tmp $S
170   done
171   cd ${START_DIR}
172 fi
173 cp ../sample/bin/pod_wait.sh  ../aaf_DBUILD/bin
174
175 if [[ -z "$1" || "$1" = "core" ]]; then
176   ########
177   # Fourth, build a core Docker Image to be used for all AAF Components
178   # Apply currrent Properties to Docker file, and put in place.
179   sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
180       -e 's/${JAR_VERSION}/'${JAR_VERSION}'/g' \
181       -e 's/${AAF_COMPONENT}/'${AAF_COMPONENT}'/g' \
182       -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
183       -e 's/${DUSER}/'${DUSER}'/g' \
184       Dockerfile.core >../aaf_DBUILD/Dockerfile
185   if [ -n "$DUSER" ]; then
186     echo "USER $DUSER" >> ../aaf_DBUILD/Dockerfile
187   fi
188   cd ..
189
190   $DOCKER build -t ${ORG}/${PROJECT}/aaf_core:${VERSION} aaf_DBUILD
191   $DOCKER tag ${ORG}/${PROJECT}/aaf_core:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_core:${VERSION}
192   $DOCKER tag ${ORG}/${PROJECT}/aaf_core:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_core:latest
193   rm aaf_DBUILD/Dockerfile
194  
195   cd -
196 fi
197
198 if [[ -z "$1" || "$1" = "hello" ]]; then
199   ########
200   # Fifth, do Hello
201   # Apply currrent Properties to Docker file, and put in place.
202   echo "### Building Hello"
203   cp ../sample/bin/client.sh  ../aaf_DBUILD/bin
204   cp ../sample/hello/init.sh  ../aaf_DBUILD/bin/hello_init.sh
205   SCP ../../cadi/aaf/target/aaf-cadi-aaf-${VERSION}-full.jar ../aaf_DBUILD/bin
206
207   sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
208       -e 's/${JAR_VERSION}/'${JAR_VERSION}'/g' \
209       -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
210       -e 's/${DUSER}/'${DUSER}'/g' \
211       Dockerfile.hello >../aaf_DBUILD/Dockerfile
212   #if [ -n "$DUSER" ]; then
213   #  echo "USER $DUSER" >> ../aaf_DBUILD/Dockerfile
214   #fi
215
216   cd ..
217   cp -Rf sample/etc aaf_DBUILD
218   cp -Rf sample/logs aaf_DBUILD
219   cp -Rf sample/cert aaf_DBUILD
220   
221   for C in cass certman cmd deforg fs gui locate oauth service; do
222      rm aaf_DBUILD/lib/aaf-auth-$C-*
223   done
224
225   $DOCKER build -t ${ORG}/${PROJECT}/aaf_hello:${VERSION} aaf_DBUILD
226   if [ -n ${DOCKER_REPOSITORY} ]; then
227     $DOCKER tag ${ORG}/${PROJECT}/aaf_hello:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_hello:${VERSION}
228     $DOCKER tag ${ORG}/${PROJECT}/aaf_hello:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_hello:latest
229   fi
230   cd -
231 fi
232 # Final cleanup
233 rm -Rf ../aaf_DBUILD
234