You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

build-allinone-image.sh 4.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/bin/bash
  2. # Copyright 2021 The KubeEdge Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # This script builds the node image for all-in-one Sedna.
  16. set -o errexit
  17. set -o nounset
  18. set -o pipefail
  19. # just reuse kind image
  20. # https://github.com/kubernetes-sigs/kind/blob/4910c3e221a858e68e29f9494170a38e1c4e8b80/pkg/build/nodeimage/defaults.go#L23
  21. #
  22. # Note: here use v1.21.1 of kindest/node, because kubeedge-1.8.0 still uses apiextensions.k8s.io/v1beta1 of CRD, which will be removed in k8s 1.22.0
  23. readonly BASE_IMAGE=kindest/node:v1.21.1
  24. readonly BUILD_IMAGE_NAME=sedna-edge-build-$RANDOM
  25. function get_latest_version() {
  26. # get the latest version of specified gh repo
  27. local repo=${1}
  28. # output of this latest page:
  29. # ...
  30. # "tag_name": "v1.0.0",
  31. # ...
  32. curl -s https://api.github.com/repos/$repo/releases/latest | awk '/"tag_name":/&&$0=$2' | sed 's/[",]//g'
  33. }
  34. function create_build_container() {
  35. docker run --rm --name $BUILD_IMAGE_NAME -d --entrypoint sleep $BASE_IMAGE inf || true
  36. if [ -z "$RETAIN_BUILD_CONTAINER" ]; then
  37. trap clean_build_container EXIT
  38. fi
  39. }
  40. function clean_build_container() {
  41. docker stop $BUILD_IMAGE_NAME
  42. }
  43. function run_in_build_container() {
  44. docker exec -i $BUILD_IMAGE_NAME "$@"
  45. }
  46. function commit_build_container() {
  47. local commit_args=(
  48. docker commit
  49. # put entrypoint back
  50. # https://github.com/kubernetes-sigs/kind/blob/4910c3e221a858e68e29f9494170a38e1c4e8b80/images/base/Dockerfile#L203
  51. --change 'ENTRYPOINT [ "/usr/local/bin/entrypoint", "/sbin/init" ]'
  52. $BUILD_IMAGE_NAME $ALLINONE_NODE_IMAGE
  53. )
  54. "${commit_args[@]}"
  55. }
  56. function gen_edgecore_config_template() {
  57. run_in_build_container mkdir -p /etc/kubeedge
  58. cat | run_in_build_container mkdir -p /etc/kubeedge
  59. }
  60. function arch() {
  61. local arch=$(uname -m)
  62. case "$arch" in
  63. x86_64) arch=amd64;;
  64. *);;
  65. esac
  66. echo "$arch"
  67. }
  68. function install_keadm() {
  69. # download the specified keadm binary
  70. local arch=$(arch) version=${KUBEEDGE_VERSION}
  71. local tarfile=keadm-$version-linux-$arch.tar.gz
  72. local path=keadm-$version-linux-$arch/keadm/keadm
  73. local configdir=/etc/kubeedge
  74. run_in_build_container bash -euc "
  75. # copy kube config file
  76. # install keadm
  77. curl --fail -LSO https://github.com/kubeedge/kubeedge/releases/download/$version/$tarfile
  78. tar -xvf $tarfile $path
  79. mv $path /usr/local/bin/
  80. rm $tarfile
  81. # install dependencies of keadm init/join
  82. apt update -y
  83. apt install -y wget sudo mosquitto
  84. systemctl enable mosquitto
  85. # install debug tools
  86. apt install -y less sqlite3
  87. # add convenient command
  88. echo 'alias docker=crictl' > ~/.bash_aliases
  89. "
  90. # download the kubeedge into the docker image in advance
  91. download_kubeedge
  92. }
  93. function download_kubeedge() {
  94. # download the specified kubeedge package for keadm
  95. local arch=$(arch) version=${KUBEEDGE_VERSION}
  96. local tarfile=kubeedge-$version-linux-$arch.tar.gz
  97. local configdir=/etc/kubeedge
  98. run_in_build_container bash -euc "
  99. mkdir -p $configdir; cd $configdir
  100. curl --fail -LSO https://github.com/kubeedge/kubeedge/releases/download/$version/$tarfile
  101. "
  102. }
  103. function install_edgecore() {
  104. # download the specified edgecore binary
  105. local arch=$(arch) version=${KUBEEDGE_VERSION}
  106. local tarfile=kubeedge-$version-linux-$arch.tar.gz
  107. local edgecorepath=kubeedge-$version-linux-$arch/edge/edgecore
  108. local configdir=/etc/kubeedge
  109. run_in_build_container bash -euc "
  110. mkdir -p $configdir; cd $configdir
  111. curl --fail -LSO https://github.com/kubeedge/kubeedge/releases/download/$version/$tarfile
  112. tar -xvf $tarfile $edgecorepath
  113. mv $edgecorepath /usr/local/bin/
  114. rm $tarfile
  115. # install service
  116. curl --fail -LSO https://raw.githubusercontent.com/kubeedge/kubeedge/$version/build/tools/edgecore.service
  117. systemctl enable $configdir/edgecore.service
  118. "
  119. }
  120. : ${KUBEEDGE_VERSION:=$(get_latest_version kubeedge/kubeedge)}
  121. : ${NODE_IMAGE:=kubeedge/sedna-allinone-node:v1.21.1}
  122. : ${RETAIN_BUILD_CONTAINER:=}
  123. create_build_container
  124. install_keadm
  125. commit_build_container