Skip to content

Commit

Permalink
test: add installer e2e test
Browse files Browse the repository at this point in the history
refactor: release
  • Loading branch information
QianChenglong committed Dec 5, 2019
1 parent b811fd9 commit 23b56bc
Show file tree
Hide file tree
Showing 17 changed files with 842 additions and 178 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ jobs:
password: ${{ secrets.REGISTRY_PASSWORD }}

- run: |
VERSION=$(git describe --dirty --always --tags | sed 's/-/./g')
make release
make release-test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

# Misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ test:
## quick-release: Quick release tke
.PHONY: quick-release
quick-release:
build/docker/tools/tke-installer/build.sh -q
build/docker/tools/tke-installer/release.sh -q

## release: Release tke
.PHONY: release
release:
build/docker/tools/tke-installer/build.sh
build/docker/tools/tke-installer/release.sh

## release-test: test release
.PHONY: release
release-test:
go test tkestack.io/tke/test/e2e_installer

## help: Show this help info.
.PHONY: help
Expand Down
101 changes: 22 additions & 79 deletions build/docker/tools/tke-installer/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#! /usr/bin/env bash

# Tencent is pleased to support the open source community by making TKEStack
# available.
Expand All @@ -16,93 +16,36 @@
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.


set -o errexit
set -o nounset
set -o pipefail

REGISTRY_PREFIX=tkestack
VERSION=$(git describe --dirty --always --tags | sed 's/-/./g')
PROVIDER_RES_VERSION=v1.14.6-1
K8S_VERION=${PROVIDER_RES_VERSION%-*}
OUTPUT_DIR=_output/
DST_DIR=$(mktemp -d)
#DST_DIR="/var/folders/20/n4jpmhjs0hd9hjxg80yr2nww0000gn/T/tmp.uN71o6ID"
echo "$DST_DIR" || exit
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")

function usage() {
cat <<EOF
Usage: ${0} Release TKE
-h, --help help
-q, --quick quick release
EOF
}

function prepare_baremetal_provider() {
mkdir -p "$DST_DIR"/provider/baremetal/

cp -rv pkg/platform/provider/baremetal/conf "$DST_DIR"/provider/baremetal
cp -rv pkg/platform/provider/baremetal/manifests "$DST_DIR"/provider/baremetal
ls -l "$DST_DIR"/provider/baremetal

id=$(docker create $REGISTRY_PREFIX/provider-res:"$PROVIDER_RES_VERSION")
docker cp "$id":/data/res "$DST_DIR"/provider/baremetal/
docker rm "$id"
}

function prepare_tke_installer() {
mkdir -p "$DST_DIR"/{bin,conf,data,hooks}

ls -l "$DST_DIR"

curl -L https://storage.googleapis.com/kubernetes-release/release/"$K8S_VERION"/bin/linux/amd64/kubectl -o "$DST_DIR"/bin/kubectl
chmod +x "$DST_DIR"/bin/kubectl

cp -v "$OUTPUT_DIR"/linux/amd64/tke-installer "$DST_DIR"/bin
cp -rv cmd/tke-installer/app/installer/manifests "$DST_DIR"
cp -rv cmd/tke-installer/app/installer/hooks "$DST_DIR"
}

function build_installer_image() {
docker build --pull -t "$REGISTRY_PREFIX"/tke-installer:"$VERSION" -f "$SCRIPT_DIR"/Dockerfile "$DST_DIR"
docker push "$REGISTRY_PREFIX"/tke-installer:"$VERSION"
}
umask 0022
unset IFS
unset OFS
unset LD_PRELOAD
unset LD_LIBRARY_PATH

function prepare_images() {
make push VERSION="$VERSION"
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

GENERATE_IMAGES_BIN="$OUTPUT_DIR"/$(go env GOOS)/$(go env GOARCH)/tke-generate-images
make build BINS=tke-generate-images VERSION="$VERSION"
target=${1:-tke-installer}

$GENERATE_IMAGES_BIN
$GENERATE_IMAGES_BIN | sed "s;^;$REGISTRY_PREFIX/;" | xargs -n1 -I{} sh -c "docker pull {} || exit 1"
$GENERATE_IMAGES_BIN | sed "s;^;$REGISTRY_PREFIX/;" | xargs docker save | gzip -c >"$DST_DIR"/images.tar.gz
}
cd $(dirname $0)

pwd
echo "===> Begin to create $target in $(pwd)"

quick=false
while getopts "hq" o; do
case "${o}" in
h)
usage
;;
q)
quick=true
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
echo "Step.1 cleanup"
rm -f $target

make build BINS="tke-installer" OS=linux ARCH=amd64 VERSION="$VERSION"
echo "Step.2 prepare package"
chmod +x *.sh
cp -f init_installer.sh $target
tar -czf package.tgz install.sh res

prepare_baremetal_provider
prepare_tke_installer
if [[ "${quick}" == "false" ]]; then
prepare_images
fi
echo "Step.3 generate installer"
cat package.tgz >>$target
chmod +x $target
rm -f package.tgz

build_installer_image
echo "===> Success to create $target"
56 changes: 56 additions & 0 deletions build/docker/tools/tke-installer/init_installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! /usr/bin/env bash

# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
# this file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/Apache-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

umask 0022
unset IFS
unset OFS
unset LD_PRELOAD
unset LD_LIBRARY_PATH

export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

die()
{
echo '[FAIL] Operation failed.' >&2
exit 1
}

cd `dirname "${0}"` || exit 1
cwd=`pwd` || exit 1
file=`basename "${0}"` || exit 1

me="${cwd}/${file}"
tmp="${me}.tmp"

rm -rf "${tmp}" || die
mkdir "${tmp}" && cd "${tmp}" || die

tailNum=`sed -n '/^#real installing packages append below/{=;q;}' ${me}`
tailNum=$((tailNum +1))
tail -n +${tailNum} "${me}" >package.tgz || die
tar -zxf package.tgz || die

./install.sh || die
cd "${cwd}" || die
exit 0

#real installing packages append below
129 changes: 129 additions & 0 deletions build/docker/tools/tke-installer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#! /usr/bin/env bash

# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2019 Tencent. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
# this file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/Apache-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

umask 0022
unset IFS
unset OFS
unset LD_PRELOAD
unset LD_LIBRARY_PATH

export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

VERSION=latest

INSTALL_DIR=/opt/tke-installer
DATA_DIR=$INSTALL_DIR/data
OPTIONS="--name tke-installer -d --privileged --net=host -v/etc/hosts:/app/hosts -v/var/run/docker.sock:/var/run/docker.sock -v$DATA_DIR:/app/data -v$INSTALL_DIR/conf:/app/conf"

function prefight() {
echo "Step.1 prefight"

if [ "root" != "$(whoami)" ]; then
echo "only root can execute this script"
exit 1
fi
}

function ensure_docker() {
echo "Step.2 ensure docker is ok"

if ! [ -x "$(command -v docker)" ]; then
echo "command docker not find"
install_docker
fi
if ! systemctl is-active --quiet docker; then
echo "docker status is not running"
install_docker
fi
}

function install_docker() {
echo "install docker [doing]"

tar xvaf "res/docker.tgz" -C /usr/bin --strip-components=1
cp -v res/docker.service /etc/systemd/system

systemctl daemon-reload

# becuase first start docker may be restart some times
systemctl start docker || :
for i in {1..60}; do
if systemctl is-active --quiet docker; then
break
fi
sleep 1
done
if (( i == 10)); then
echo "start docker failed, please check docker service."
exit 1
fi

echo "install docker [ok]"
}

function load_image() {
echo "Step.3 load tke-installer image [doing]"

docker load -i res/tke-installer.tgz

echo "Step.3 load tke-installer image [ok]"
}

function clean_old_data() {
echo "Step.4 clean old data [doing]"

rm -rf $DATA_DIR || :
docker rm -f tke-installer || :

echo "Step.4 clean old data [ok]"
}

function start_installer() {
echo "Step.5 start tke-installer [doing]"

docker run $OPTIONS tkestack/tke-installer:$VERSION

echo "Step.5 start tke-installer [ok]"
}

function check_installer() {
echo "Step.6 check tke-installer status [doing]"

ip=$(ip route get 1 | awk '{print $NF;exit}')
url="http:https://$ip:8080/index.html"
if ! curl -sSf $url >/dev/null; then
echo "check installer status error"
docker logs tke-installer
exit 1
fi

echo "Step.6 check tke-installer status [ok]"

echo "Please use your browser which can connect this machine to open $url for install TKE!"
}

prefight
ensure_docker
load_image
clean_old_data
start_installer
check_installer
Loading

0 comments on commit 23b56bc

Please sign in to comment.