-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
65 lines (55 loc) · 1.3 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
export GOPROXY=https://goproxy.cn
BIN_FILE="oam"
while [ $# -gt 0 ]
do
key="$1"
case $key in
--image-name)
export IMAGE_NAME=$2
shift
;;
--version)
export VERSION=$2
shift
;;
--repo)
export IMAGE_REPO=$2
shift
;;
*)
echo "unknown option [$key]"
exit 1
;;
esac
shift
done
if [ -z "$IMAGE_NAME" ]; then
IMAGE_NAME='lsh-cluster-oam-kubernetes-runtime'
fi
if [ -z "$VERSION" ]; then
VERSION='v100r001c02b081'
fi
if [ -z "$IMAGE_REPO" ]; then
IMAGE_REPO='registry.cn-beijing.aliyuncs.com/launcher-agent-only-dev'
# IMAGE_REPO='registry.cn-hangzhou.aliyuncs.com/launcher-agent-only-test'
fi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/${BIN_FILE} ./main.go
if [ $? -ne 0 ]; then
echo "compile ERROR"
exit 1
fi
echo build success
cat <<EOF > Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/launcher/alpine:latest
COPY ./bin/${BIN_FILE} /
WORKDIR /
ENTRYPOINT ["/${BIN_FILE}"]
EOF
if [ $? -ne 0 ]; then
echo "build image ERROR"
exit 1
fi
docker build -t ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION} ./
docker push ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}
docker rmi ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}