update deployment

This commit is contained in:
zhuyasen
2023-09-02 22:18:32 +08:00
parent e69854a37e
commit 9fc45453b6
12 changed files with 168 additions and 90 deletions

View File

@@ -4,10 +4,10 @@
# use upx to compress the binaries before building the image.
serverName="serverNameExample_mixExample"
# image name of the service, no capital letters
SERVER_NAME="project-name-example.server-name-example"
# image name of the service, prohibit uppercase letters in names.
IMAGE_NAME="project-name-example/server-name-example"
# Dockerfile file directory
DOCKERFILE_PATH="build"
DOCKERFILE_PATH="scripts/build"
DOCKERFILE="${DOCKERFILE_PATH}/Dockerfile"
# image repo address, REPO_HOST="ip or domain", passed in via the first parameter
@@ -22,20 +22,28 @@ if [ "X${TAG}" = "X" ];then
TAG="latest"
fi
# image name and tag
IMAGE_NAME_TAG="${REPO_HOST}/${SERVER_NAME}:${TAG}"
IMAGE_NAME_TAG="${REPO_HOST}/${IMAGE_NAME}:${TAG}"
# binary executable files
BIN_FILE="cmd/${serverName}/${serverName}"
# configuration file directory
CONFIG_PATH="configs"
# only grpc use start
bash scripts/grpc_health_probe.sh
# only grpc use end
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://goproxy.cn,direct go build -o ${BIN_FILE} cmd/${serverName}/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BIN_FILE} cmd/${serverName}/*.go
mv -f ${BIN_FILE} ${DOCKERFILE_PATH}
mkdir -p ${DOCKERFILE_PATH}/${CONFIG_PATH} && cp -f ${CONFIG_PATH}/${serverName}.yml ${DOCKERFILE_PATH}/${CONFIG_PATH}
# todo generate image-build code for http or grpc here
# delete the templates code start
# install grpc-health-probe, for health check of grpc service
rootDockerFilePath=$(pwd)/${DOCKERFILE_PATH}
go install github.com/grpc-ecosystem/grpc-health-probe@v0.4.12
cd $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-health-probe@v0.4.12 \
&& go mod download \
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "all=-s -w" -o "${rootDockerFilePath}/grpc_health_probe"
cd -
# compressing binary file
#cd ${DOCKERFILE_PATH}
#upx -9 ${serverName}
@@ -45,7 +53,23 @@ mkdir -p ${DOCKERFILE_PATH}/${CONFIG_PATH} && cp -f ${CONFIG_PATH}/${serverName}
echo "docker build -f ${DOCKERFILE} -t ${IMAGE_NAME_TAG} ${DOCKERFILE_PATH}"
docker build -f ${DOCKERFILE} -t ${IMAGE_NAME_TAG} ${DOCKERFILE_PATH}
if [ X"${serverName}" = X ];then
exit 0
if [ -f "${DOCKERFILE_PATH}/grpc_health_probe" ]; then
rm -f ${DOCKERFILE_PATH}/grpc_health_probe
fi
rm -rf ./${DOCKERFILE_PATH}/${serverName} ${DOCKERFILE_PATH}/configs ${DOCKERFILE_PATH}/grpc_health_probe
# delete the templates code end
if [ -f "${DOCKERFILE_PATH}/${serverName}" ]; then
rm -f ${DOCKERFILE_PATH}/${serverName}
fi
if [ -d "${DOCKERFILE_PATH}/configs" ]; then
rm -rf ${DOCKERFILE_PATH}/configs
fi
# delete none image
noneImages=$(docker images | grep "<none>" | awk '{print $3}')
if [ "X${noneImages}" != "X" ]; then
docker rmi ${noneImages} > /dev/null
fi
exit 0