|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +repo="hyperhq/test-installer-centos" |
| 6 | +tag="6.8" |
| 7 | +image=${repo}:${tag} |
| 8 | +container="test-installer-centos-6" |
| 9 | + |
| 10 | +# DOCKER0=$(ifconfig | grep docker0 -A1 | grep "inet " | awk '{print $2}') |
| 11 | +# PROXY="http://${DOCKER0}:8118" |
| 12 | + |
| 13 | +function build(){ |
| 14 | + echo "starting build..." |
| 15 | + echo "==============================================================" |
| 16 | + CMD="docker build --build-arg http_proxy=${PROXY} --build-arg https_proxy=${PROXY} -t ${image} ." |
| 17 | + echo "CMD: [ ${CMD} ]" |
| 18 | + eval $CMD |
| 19 | +} |
| 20 | + |
| 21 | +function push(){ |
| 22 | + echo -e "\nstarting push [${image}] ..." |
| 23 | + echo "==============================================================" |
| 24 | + docker push ${image} |
| 25 | +} |
| 26 | + |
| 27 | +function run() { |
| 28 | + echo -e "\ncheck old conainer from [${image}] ..." |
| 29 | + cnt=`docker ps -a --filter="name=${container}" | wc -l` |
| 30 | + if [ $cnt -ne 1 ];then |
| 31 | + docker rm -fv ${container} |
| 32 | + fi |
| 33 | + echo -e "\nrun conainer from [${image}] ..." |
| 34 | + docker run -d -t \ |
| 35 | + --privileged \ |
| 36 | + --hostname ${container} \ |
| 37 | + --name ${container} \ |
| 38 | + --env HTTP_PROXY=$HTTP_PROXY --env HTTPS_PROXY=$HTTPS_PROXY \ |
| 39 | + -v `pwd`/../../../../hyper-installer:/hyper-installer \ |
| 40 | + $image top |
| 41 | + echo "---------------------------------------------------" |
| 42 | + docker ps -a --filter="name=${container}" |
| 43 | + cat <<EOF |
| 44 | +
|
| 45 | +--------------------------------------------------- |
| 46 | +Run the following command to enter container: |
| 47 | + docker exec -it ${container} bash |
| 48 | +EOF |
| 49 | +} |
| 50 | + |
| 51 | +function test_hyper() { |
| 52 | + echo -e "\ncheck conainer from [${image}] ..." |
| 53 | + cnt=`docker ps -a --filter="name=${container}" | wc -l` |
| 54 | + if [ $cnt -eq 1 ];then |
| 55 | + run |
| 56 | + fi |
| 57 | + docker exec -it ${container} bash -c "curl -sSL https://hyper.sh/install | bash" |
| 58 | +} |
| 59 | + |
| 60 | +function test_hypercontainer() { |
| 61 | + echo -e "\ncheck conainer from [${image}] ..." |
| 62 | + cnt=`docker ps -a --filter="name=${container}" | wc -l` |
| 63 | + if [ $cnt -eq 1 ];then |
| 64 | + run |
| 65 | + fi |
| 66 | + docker exec -it ${container} bash -c "curl -sSL https://hypercontainer.io/install | bash" |
| 67 | +} |
| 68 | + |
| 69 | +case "$1" in |
| 70 | + "build") |
| 71 | + build |
| 72 | + ;; |
| 73 | + "push") |
| 74 | + build |
| 75 | + push |
| 76 | + ;; |
| 77 | + "run") |
| 78 | + run |
| 79 | + ;; |
| 80 | + "test_hyper") |
| 81 | + test_hyper |
| 82 | + ;; |
| 83 | + "test_hypercontainer") |
| 84 | + test_hypercontainer |
| 85 | + ;; |
| 86 | + *) |
| 87 | + cat <<EOF |
| 88 | +usage: |
| 89 | + ./util.sh build # build only |
| 90 | + ./util.sh push # build and push |
| 91 | + ./util.sh run # run only |
| 92 | + ./util.sh test_hyper # test install script for hypercli of Hyper.sh |
| 93 | + ./util.sh test_hypercontainer # test install script for hypercontainer |
| 94 | +EOF |
| 95 | + exit 1 |
| 96 | + ;; |
| 97 | +esac |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +echo -e "\n==============================================================" |
| 102 | +echo "Done!" |
0 commit comments