Protect vs Bucket containing html chars
[functest-xtesting.git] / build.sh
1 #!/bin/bash
2
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7
8 set -xe
9
10 repo=${REPO:-opnfv}
11 tag=${BRANCH:-jerma}
12 arch=${arch-"\
13 amd64 \
14 arm64 \
15 arm"}
16 amd64_dirs=${amd64_dirs-"\
17 docker/core \
18 docker/mts"}
19 arm_dirs=${arm_dirs-${amd64_dirs}}
20 arm64_dirs=${arm64_dirs-${amd64_dirs}}
21 image="xtesting"
22 build_opts=(--pull=true --no-cache --force-rm=true)
23
24 for arch in ${arch}; do
25     if [[ ${arch} == arm64 ]]; then
26         find . -name Dockerfile -exec sed -i \
27             -e "s|alpine:3.10|arm64v8/alpine:3.10|g" {} +
28         find . -name Dockerfile -exec sed -i \
29             -e "s|opnfv/xtesting:${tag}|${repo}/xtesting:arm64-${tag}|g" {} +
30     elif [[ ${arch} == arm ]]; then
31         find . -name Dockerfile -exec sed -i \
32             -e "s|alpine:3.10|arm32v6/alpine:3.10|g" {} +
33         find . -name Dockerfile -exec sed -i \
34             -e "s|opnfv/xtesting:${tag}|${repo}/xtesting:arm-${tag}|g" {} +
35     else
36         find . -name Dockerfile -exec sed -i \
37             -e "s|opnfv/xtesting:${tag}|${repo}/xtesting:amd64-${tag}|g" {} +
38     fi
39     dirs=${arch}_dirs
40     for dir in ${!dirs}; do
41         if [[ ${dir} == docker/core ]]; then
42             image=xtesting
43         else
44             image=xtesting-${dir##**/}
45         fi
46         (cd "${dir}" &&
47             docker build "${build_opts[@]}" \
48                 -t "${repo}/${image}:${arch}-${tag}" . &&
49             docker push "${repo}/${image}:${arch}-${tag}")
50         [ "${dir}" != "docker/core" ] &&
51             (docker rmi \
52                 "${repo}/${image}:${arch}-${tag}" || true)
53     done
54     [ "$?" == "0" ] &&
55         (sudo docker rmi "${repo}/xtesting:${arch}-${tag}"|| true)
56     find . -name Dockerfile -exec git checkout \{\} +;
57 done
58 exit $?