a2a17e639553d45e7ee1599ea5dfce4b802deefe
[aaf/authz.git] / auth / docker / dbuild.sh
1 #!/bin/bash
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 # process input. originally, an optional positional parameter is used to designate a component.
32 # A flagged parameter has been added to optionally indicate docker pull registry. Ideally, options
33 # would be flagged but we're avoiding ripple effect of changing original usage
34 if [ $# -gt 0 ]; then
35     if [ "$1" == "-r" ]; then
36         DOCKER_PULL_REGISTRY=$2
37     else
38         AAF_COMPONENTS=$1
39         if [[ $# -gt 1 && $2 == "-r" ]]; then
40             # If docker.io is indicated, registry var is void as that is docker default
41             if [ $3 == "docker.io" ]; then
42                 DOCKER_PULL_REGISTRY=''
43             else
44                 DOCKER_PULL_REGISTRY=$3
45             fi
46         fi
47     fi
48 fi
49
50 grep -v '#' d.props | grep '=' | grep -v -e "=$"
51
52 DOCKER=${DOCKER:=docker}
53
54 echo "Building Containers for aaf components, version $VERSION"
55 # AAF_cass now needs a version...
56 cd ../auth-cass/docker
57 pwd
58 bash ./dbuild.sh $DOCKER_PULL_REGISTRY
59 cd -
60
61 ########
62 # First, build a AAF Base version - set the core image, etc
63 sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
64     -e 's/${DUSER}/'${DUSER}'/g' \
65     -e 's/${REGISTRY}/'${DOCKER_PULL_REGISTRY}'/g' \
66     Dockerfile.base > Dockerfile
67 $DOCKER build -t ${ORG}/${PROJECT}/aaf_base:${VERSION} .
68 $DOCKER tag ${ORG}/${PROJECT}/aaf_base:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_base:${VERSION}
69 $DOCKER tag ${ORG}/${PROJECT}/aaf_base:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_base:latest
70 rm Dockerfile
71
72 # Tack the "SNAPSHOT" out of name
73 function SCP() {
74   SANS=${1/-SNAPSHOT/}
75   if [ -e $SANS ]; then
76     cp $SANS $2
77   else 
78     ln $1 $SANS
79     cp $SANS $2
80     rm $SANS
81   fi
82 }
83
84 ########
85 # Second, Create the AAF Config (Security) Images
86 cd ..
87 # Note: only 2 jars each in Agent/Config
88 SCP auth-cmd/target/aaf-auth-cmd-$VERSION-full.jar sample/bin
89 SCP auth-batch/target/aaf-auth-batch-$VERSION-full.jar sample/bin
90 SCP ../cadi/aaf/target/aaf-cadi-aaf-${VERSION}-full.jar sample/bin
91 SCP ../cadi/servlet-sample/target/aaf-cadi-servlet-sample-${VERSION}-sample.jar sample/bin
92 cp -Rf ../conf/CA sample
93
94 # AAF Config image (for AAF itself)
95 sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
96     -e 's/${AAF_COMPONENT}/'${AAF_COMPONENT}'/g' \
97     -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
98     -e 's/${DUSER}/'${DUSER}'/g' \
99     docker/Dockerfile.config > sample/Dockerfile
100 $DOCKER build -t ${ORG}/${PROJECT}/aaf_config:${VERSION} sample
101 $DOCKER tag ${ORG}/${PROJECT}/aaf_config:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_config:${VERSION}
102 $DOCKER tag ${ORG}/${PROJECT}/aaf_config:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_config:latest
103
104
105 # AAF Agent Image (for Clients)
106 sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
107     -e 's/${AAF_COMPONENT}/'${AAF_COMPONENT}'/g' \
108     -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
109     -e 's/${DUSER}/'${DUSER}'/g' \
110     docker/Dockerfile.agent > sample/Dockerfile
111 $DOCKER build -t ${ORG}/${PROJECT}/aaf_agent:${VERSION} sample
112 $DOCKER tag ${ORG}/${PROJECT}/aaf_agent:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_agent:${VERSION}
113 $DOCKER tag ${ORG}/${PROJECT}/aaf_agent:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_agent:latest
114
115 # Clean up 
116 rm sample/Dockerfile sample/bin/aaf-*-*.jar 
117 rm -Rf sample/CA
118 cd -
119
120 ########
121 # Third, build a core Docker Image to be used for all AAF Components
122 echo Building aaf_$AAF_COMPONENT...
123 cp ../sample/bin/pod_wait.sh  ../aaf_${VERSION}/bin
124 # Apply currrent Properties to Docker file, and put in place.
125 sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
126     -e 's/${AAF_COMPONENT}/'${AAF_COMPONENT}'/g' \
127     -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
128     -e 's/${DUSER}/'${DUSER}'/g' \
129     Dockerfile.core >../aaf_${VERSION}/Dockerfile
130 cd ..
131 echo "#######"
132 pwd
133 echo "#######"
134 $DOCKER build -t ${ORG}/${PROJECT}/aaf_core:${VERSION} aaf_${VERSION}
135 $DOCKER tag ${ORG}/${PROJECT}/aaf_core:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_core:${VERSION}
136 $DOCKER tag ${ORG}/${PROJECT}/aaf_core:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_core:latest
137 rm aaf_${VERSION}/Dockerfile
138
139 ########
140 # Fourth, do Hello
141 # Apply currrent Properties to Docker file, and put in place.
142 cd -
143 sed -e 's/${AAF_VERSION}/'${VERSION}'/g' \
144     -e 's/${DOCKER_REPOSITORY}/'${DOCKER_REPOSITORY}'/g' \
145     -e 's/${DUSER}/'${DUSER}'/g' \
146     Dockerfile.hello >../aaf_${VERSION}/Dockerfile
147 cd ..
148 echo "#######"
149 pwd
150 echo "#######"
151 cp -Rf sample/etc aaf_${VERSION}
152 cp -Rf sample/logs aaf_${VERSION}
153 $DOCKER build -t ${ORG}/${PROJECT}/aaf_hello:${VERSION} aaf_${VERSION}
154 $DOCKER tag ${ORG}/${PROJECT}/aaf_hello:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_hello:${VERSION}
155 $DOCKER tag ${ORG}/${PROJECT}/aaf_hello:${VERSION} ${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/aaf_hello:latest
156 rm -Rf aaf_${VERSION}/Dockerfile aaf_${VERSION}/etc
157
158 # Final cleanup
159 rm aaf_${VERSION}/bin/pod_wait.sh
160
161 cd -