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