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