From 38daadf82239e69ae24e3763ba3c350c97f41716 Mon Sep 17 00:00:00 2001 From: Yilong Ren Date: Wed, 7 Apr 2021 11:43:55 +0800 Subject: [PATCH] update build/build.sh --- build/Dockerfile | 1 - Makefile => build/Makefile | 4 +-- build/build.sh | 67 ++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 23 deletions(-) rename Makefile => build/Makefile (75%) mode change 100644 => 100755 build/build.sh diff --git a/build/Dockerfile b/build/Dockerfile index 5a9feef..a2d9814 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -2,6 +2,5 @@ FROM alpine:3.10 ADD https://releases.hashicorp.com/packer/1.6.0/packer_1.6.0_linux_amd64.zip /packer_1.6.0_linux_amd64.zip RUN unzip packer_1.6.0_linux_amd64.zip && mv packer /bin/packer -COPY scripts/init.sh scripts/init.sh ENTRYPOINT ["packer", "build"] diff --git a/Makefile b/build/Makefile similarity index 75% rename from Makefile rename to build/Makefile index 7d779a9..82f7f99 100644 --- a/Makefile +++ b/build/Makefile @@ -4,6 +4,6 @@ PREFIX?=registry.aliyuncs.com/acs VERSION?=v1.0.0 docker-container: - docker build --pull -t $(PREFIX)/ack-image-builder:$(VERSION) -f build/Dockerfile . + docker build --pull -t $(PREFIX)/ack-image-builder:$(VERSION) . -.PHONY: all docker-container \ No newline at end of file +.PHONY: all docker-container diff --git a/build/build.sh b/build/build.sh old mode 100644 new mode 100755 index 3804c2b..fabe359 --- a/build/build.sh +++ b/build/build.sh @@ -1,25 +1,52 @@ #!/bin/bash -## -read -p "Please input the AliCloud access_key:" ACCESS_KEY -read -p "Please input the AliCloud secret_key:" SECRET_KEY -read -p "The Alicloud region is: " REGION -read -p "The Docker version is:" DOCKER_VERSION -read -p "The kubernetes version is:" KUBE_VERSION -## check params -if [[ -z $ACCESS_KEY || -z $SECRET_KEY || -z $REGION || -z $DOCKER_VERSION || -z $KUBE_VERSION ]]; then - echo -e "[ERROR] $(date '+%F %T') following parameters is empty: -access_key=${ACCESS_KEY} -secret_key=${SECRET_KEY} -region=${REGION} -docker_version=${DOCKER_VERSION} -kube_version=${KUBE_VERSION}" - exit 0 -fi +set -x +set -e +CUR_DIR=$(dirname $(readlink -e -v ${BASH_SOURCE[0]})) +SRC_DIR=$(dirname $CUR_DIR) -file_path="$(pwd)/$1" +usage() { + cat >&2 <<-EOF +Usage: + $0 build_template_file +Example: + $0 $SRC_DIR/examples/ack-aliyunlinux2.json +EOF +} + +check_params() { + BUILD_TEMPLATE_FILE="$1" + + if [[ -z $BUILD_TEMPLATE_FILE ]]; then + echo "ERROR: must be specify one template file" + usage + return 1 + fi + + if ! [[ -f $BUILD_TEMPLATE_FILE ]]; then + echo "ERROR: cannot find file: $BUILD_TEMPLATE_FILE" + return 1 + fi +} + +check_docker_image() { + if docker inspect registry.aliyuncs.com/acs/ack-image-builder:v1.0.0 &>/dev/null; then + : + else + make + fi +} + +build_os_image() { + docker run -v $BUILD_TEMPLATE_FILE:$BUILD_TEMPLATE_FILE registry.aliyuncs.com/acs/ack-image-builder:v1.0.0 $file_path +} + +main() { + check_params "$@" + check_docker_image + build_os_image +} + +main "$@" -##build OS image -docker run -e ALICLOUD_ACCESS_KEY=$ACCESS_KEY -e ALICLOUD_SECRET_KEY=$SECRET_KEY -e REGION=$REGION -e KUBE_VERSION=$KUBE_VERSION \ --e DOCKER_VERSION=$DOCKER_VERSION -v $file_path:$file_path registry.aliyuncs.com/acs/ack-image-builder:v1.0.0 $file_path