Fix README.md Dockerfile sample
[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 arch=${arch-"\
12 amd64 \
13 arm64 \
14 arm"}
15 amd64_dirs=${amd64_dirs-"\
16 docker/core"}
17 arm_dirs=${arm_dirs-${amd64_dirs}}
18 arm64_dirs=${arm64_dirs-${amd64_dirs}}
19 tag=${BRANCH:-latest}
20 image="xtesting"
21 build_opts=(--pull=true --no-cache --force-rm=true)
22
23 for arch in ${arch}; do
24     if [[ ${arch} == arm64 ]]; then
25         find . -name Dockerfile -exec sed -i \
26             -e "s|alpine:3.17|arm64v8/alpine:3.17|g" {} +
27         find . -name Dockerfile -exec sed -i \
28             -e "s|opnfv/xtesting|${repo}/xtesting:arm64-${tag}|g" {} +
29     elif [[ ${arch} == arm ]]; then
30         find . -name Dockerfile -exec sed -i \
31             -e "s|alpine:3.17|arm32v6/alpine:3.17|g" {} +
32         find . -name Dockerfile -exec sed -i \
33             -e "s|opnfv/xtesting|${repo}/xtesting:arm-${tag}|g" {} +
34     else
35         find . -name Dockerfile -exec sed -i \
36             -e "s|opnfv/xtesting|${repo}/xtesting:amd64-${tag}|g" {} +
37     fi
38     dirs=${arch}_dirs
39     for dir in ${!dirs}; do
40         if [[ ${dir} == docker/core ]]; then
41             image=xtesting
42         else
43             image=xtesting-${dir##**/}
44         fi
45         (cd "${dir}" &&
46             docker build "${build_opts[@]}" \
47                 -t "${repo}/${image}:${arch}-${tag}" . &&
48             docker push "${repo}/${image}:${arch}-${tag}")
49         [ "${dir}" != "docker/core" ] &&
50             (docker rmi \
51                 "${repo}/${image}:${arch}-${tag}" || true)
52     done
53     [ "$?" == "0" ] &&
54         (sudo docker rmi "${repo}/xtesting:${arch}-${tag}"|| true)
55     find . -name Dockerfile -exec git checkout \{\} +;
56 done
57 exit $?