buildall-common.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. ##############################################################################
  3. #
  4. # HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ##############################################################################
  18. # Build script to create and publish Docker containers corresponding to a GitHub tag
  19. # This script is normally invoked via GitHub actions, whenever a new tag is pushed
  20. BASE_VER=8.6 # The docker hub label for the platform-build-base image. Changes rarely.
  21. BUILD_TAG=$(git describe --exact-match --tags || true) # The git tag for the images we are building
  22. BUILD_LABEL=${BUILD_TAG} # The docker hub label for all other components
  23. BUILD_USER=hpcc-systems # The github repo owner
  24. BUILD_TYPE= # Set to Debug for a debug build, leave blank for default (RelWithDebInfo)
  25. DOCKER_REPO=hpccsystems
  26. DEST_DOCKER_REGISTRY=docker.io
  27. USE_CPPUNIT=1
  28. # These values are set in a GitHub workflow build
  29. [[ -n ${INPUT_BUILD_USER} ]] && BUILD_USER=${INPUT_BUILD_USER}
  30. [[ -n ${INPUT_BUILD_VER} ]] && BUILD_TAG=${INPUT_BUILD_VER}
  31. [[ -n ${INPUT_DOCKER_REPO} ]] && DOCKER_REPO=${INPUT_DOCKER_REPO}
  32. DEST_DOCKER_REPO=${DOCKER_REPO}
  33. [[ -n ${INPUT_LN_DOCKER_REPO} ]] && DEST_DOCKER_REPO=${INPUT_LN_DOCKER_REPO}
  34. [[ -n ${INPUT_LN_REGISTRY} ]] && DEST_DOCKER_REGISTRY=${INPUT_LN_REGISTRY}
  35. if [[ -n ${INPUT_BUILD_THREADS} ]] ; then
  36. BUILD_THREADS=$INPUT_BUILD_THREADS
  37. fi
  38. if [[ -z ${BUILD_TAG} ]] ; then
  39. echo Current tag could not be located
  40. echo Perhaps you meant to run incr.sh ?
  41. exit 2
  42. fi
  43. if [[ -z ${INPUT_BUILD_LABEL} ]]; then
  44. BUILD_LABEL=${HPCC_SHORT_TAG}
  45. else
  46. BUILD_LABEL=${INPUT_BUILD_LABEL}
  47. fi
  48. if [[ -n ${INPUT_BUILD_TYPE} ]] ; then
  49. BUILD_LABEL=${BUILD_LABEL}-$INPUT_BUILD_TYPE
  50. BUILD_TYPE=$INPUT_BUILD_TYPE
  51. else
  52. BUILD_TYPE=RelWithDebInfo
  53. USE_CPPUNIT=0
  54. fi
  55. if [[ "$HPCC_MATURITY" = "release" ]] && [[ "$INPUT_LATEST" = "1" ]] ; then
  56. LATEST=1
  57. fi
  58. build_image() {
  59. local name=$1
  60. local label=$2
  61. local buildTag=$3
  62. local rebuild=0
  63. local rest=${@:4}
  64. if [[ -z ${label} ]] ; then
  65. label=$BUILD_LABEL
  66. if [[ "$HPCC_MATURITY" = "release" ]] && [[ "$HPCC_SEQUENCE" != "1" ]] ; then
  67. rebuild=1
  68. fi
  69. fi
  70. [[ -z ${buildTag} ]] && buildTag=$BUILD_TAG
  71. if [ "$rebuild" = "1" ] || ! docker pull ${DEST_DOCKER_REGISTRY}/${DOCKER_REPO}/${name}:${label} ; then
  72. docker image build -t ${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO}/${name}:${label} \
  73. --build-arg BASE_VER=${BASE_VER} \
  74. --build-arg DOCKER_REPO=${DOCKER_REPO} \
  75. --build-arg DEST_DOCKER_REPO=${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO} \
  76. --build-arg BUILD_TAG=${buildTag} \
  77. --build-arg BUILD_LABEL=${BUILD_LABEL} \
  78. --build-arg BUILD_USER=${BUILD_USER} \
  79. --build-arg BUILD_TYPE=${BUILD_TYPE} \
  80. --build-arg USE_CPPUNIT=${USE_CPPUNIT} \
  81. --build-arg BUILD_THREADS=${BUILD_THREADS} \
  82. --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} \
  83. ${rest} ${name}/
  84. push_image $name $label
  85. fi
  86. }
  87. push_image() {
  88. local name=$1
  89. local label=$2
  90. if [ "$LATEST" = "1" ] ; then
  91. docker tag ${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO}/${name}:${label} ${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO}/${name}:latest
  92. if [ "$PUSH" = "1" ] ; then
  93. docker push ${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO}/${name}:${label}
  94. docker push ${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO}/${name}:latest
  95. fi
  96. else
  97. if [ "$PUSH" = "1" ] ; then
  98. docker push ${DEST_DOCKER_REGISTRY}/${DEST_DOCKER_REPO}/${name}:${label}
  99. fi
  100. fi
  101. }