github.com/secure-build/gitlab-runner@v12.5.0+incompatible/ci/release_docker_images (about)

     1  #!/usr/bin/env bash
     2  
     3  set -eo pipefail
     4  
     5  DOCKER_MACHINE_VERSION=${DOCKER_MACHINE_VERSION:-0.14.0}
     6  DOCKER_MACHINE_CHECKSUM=${DOCKER_MACHINE_CHECKSUM:-a4c69bffb78d3cfe103b89dae61c3ea11cc2d1a91c4ff86e630c9ae88244db02}
     7  DUMB_INIT_VERSION=${DUMB_INIT_VERSION:-1.0.2}
     8  DUMB_INIT_CHECKSUM=${DUMB_INIT_CHECKSUM:-a8defac40aaca2ca0896c7c5adbc241af60c7c3df470c1a4c469a860bd805429}
     9  GIT_LFS_VERSION=${GIT_LFS_VERSION:-2.7.1}
    10  GIT_LFS_CHECKSUM=${GIT_LFS_CHECKSUM:-c8952ee72af214e3669f834d829e8a0a3becd160dead18237f99e40d75a3e920}
    11  
    12  RUNNER_BINARY=${RUNNER_BINARY:-out/binaries/gitlab-runner-linux-amd64}
    13  
    14  IS_LATEST=${IS_LATEST:-}
    15  
    16  ref_tag=${CI_COMMIT_TAG}
    17  if [[ -z "${ref_tag}" ]]; then
    18      ref_tag=${CI_COMMIT_REF_SLUG:-master}
    19  fi
    20  
    21  if [[ "${ref_tag}" = "master" ]]; then
    22      ref_tag=bleeding
    23  fi
    24  
    25  REVISION=${REVISION:-}
    26  if [[ -z "${REVISION}" ]]; then
    27    REVISION=$(git rev-parse --short=8 HEAD || echo "unknown")
    28  fi
    29  
    30  _docker() {
    31      docker ${@}
    32  }
    33  
    34  build() {
    35      echo -e "\033[1mBuilding image: \033[32m${1}\033[0m"
    36      _docker build \
    37          --no-cache \
    38          --build-arg DOCKER_MACHINE_VERSION="${DOCKER_MACHINE_VERSION}" \
    39          --build-arg DUMB_INIT_VERSION="${DUMB_INIT_VERSION}" \
    40          --build-arg GIT_LFS_VERSION="${GIT_LFS_VERSION}" \
    41          -t "${1}" \
    42          "${2}"
    43  }
    44  
    45  import() {
    46      echo -e "\033[1mImporting image: \033[32m${2}\033[0m"
    47      _docker import "${1}" "${2}"
    48  }
    49  
    50  tag() {
    51      echo -e "\033[1mTagging image: \033[32m${2}\033[0m"
    52      _docker tag "${1}" "${2}"
    53  }
    54  
    55  tag_latest() {
    56      if [[ -z "${IS_LATEST}" ]]; then
    57          return
    58      fi
    59  
    60      tag "${@}"
    61  }
    62  
    63  push() {
    64      echo -e "\033[1mPushing image: \033[32m${1}\033[0m"
    65      _docker push "${1}"
    66  }
    67  
    68  push_latest() {
    69      if [[ -z "${IS_LATEST}" ]]; then
    70          return
    71      fi
    72  
    73      push "${@}"
    74  }
    75  
    76  release_docker_helper_images() {
    77      helper_image_x86_64="gitlab/gitlab-runner-helper:x86_64-${REVISION}"
    78      helper_image_x86_64_latest="gitlab/gitlab-runner-helper:x86_64-latest"
    79      helper_image_arm="gitlab/gitlab-runner-helper:arm-${REVISION}"
    80      helper_image_arm_latest="gitlab/gitlab-runner-helper:arm-latest"
    81  
    82      import out/helper-images/prebuilt-x86_64.tar.xz ${helper_image_x86_64}
    83      import out/helper-images/prebuilt-arm.tar.xz ${helper_image_arm}
    84  
    85      tag_latest ${helper_image_x86_64} ${helper_image_x86_64_latest}
    86      tag_latest ${helper_image_arm} ${helper_image_arm_latest}
    87  
    88  
    89      push ${helper_image_x86_64}
    90      push ${helper_image_arm}
    91  
    92      push_latest ${helper_image_x86_64_latest}
    93      push_latest ${helper_image_arm_latest}
    94  }
    95  
    96  login() {
    97      _docker login --username "${1}" --password "${2}" "${3}"
    98  }
    99  
   100  logout() {
   101      _docker logout "${1}"
   102  }
   103  
   104  echo -n > dockerfiles/checksums
   105  echo "${DOCKER_MACHINE_CHECKSUM}  /usr/bin/docker-machine" >> dockerfiles/checksums
   106  echo "${DUMB_INIT_CHECKSUM}  /usr/bin/dumb-init" >> dockerfiles/checksums
   107  echo "${GIT_LFS_CHECKSUM}  /usr/bin/git-lfs" >> dockerfiles/checksums
   108  cat dockerfiles/checksums
   109  
   110  cp out/deb/gitlab-runner_amd64.deb dockerfiles/ubuntu/gitlab-runner_amd64.deb
   111  cp dockerfiles/checksums dockerfiles/ubuntu
   112  cp ${RUNNER_BINARY} dockerfiles/alpine/gitlab-runner-linux-amd64
   113  cp dockerfiles/checksums dockerfiles/alpine
   114  
   115  build "gitlab/gitlab-runner:ubuntu-${ref_tag}" dockerfiles/ubuntu
   116  build "gitlab/gitlab-runner:alpine-${ref_tag}" dockerfiles/alpine
   117  
   118  tag "gitlab/gitlab-runner:ubuntu-${ref_tag}" "gitlab/gitlab-runner:${ref_tag}"
   119  
   120  tag_latest "gitlab/gitlab-runner:ubuntu-${ref_tag}" gitlab/gitlab-runner:ubuntu
   121  tag_latest "gitlab/gitlab-runner:ubuntu-${ref_tag}" gitlab/gitlab-runner:latest
   122  tag_latest "gitlab/gitlab-runner:alpine-${ref_tag}" gitlab/gitlab-runner:alpine
   123  
   124  if [[ -z "${PUBLISH_IMAGES}" ]] || [[ "${PUBLISH_IMAGES}" != "true" ]]; then
   125      echo "Skipping images pushing"
   126      exit 0
   127  fi
   128  
   129  if [[ -n "${CI_REGISTRY}" ]] && [[ -n "${CI_REGISTRY_IMAGE}" ]]; then
   130      tag "gitlab/gitlab-runner:ubuntu-${ref_tag}" "${CI_REGISTRY_IMAGE}:ubuntu-${ref_tag}"
   131      tag "gitlab/gitlab-runner:alpine-${ref_tag}" "${CI_REGISTRY_IMAGE}:alpine-${ref_tag}"
   132      tag "gitlab/gitlab-runner:${ref_tag}" "${CI_REGISTRY_IMAGE}:${ref_tag}"
   133  
   134      tag_latest gitlab/gitlab-runner:ubuntu "${CI_REGISTRY_IMAGE}:ubuntu"
   135      tag_latest gitlab/gitlab-runner:latest "${CI_REGISTRY_IMAGE}:latest"
   136      tag_latest gitlab/gitlab-runner:alpine "${CI_REGISTRY_IMAGE}:alpine"
   137  
   138      if [[ -n "${CI_REGISTRY_USER}" ]] && [[ -n "${CI_REGISTRY_PASSWORD}" ]]; then
   139          login "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
   140  
   141          push "${CI_REGISTRY_IMAGE}:ubuntu-${ref_tag}"
   142          push "${CI_REGISTRY_IMAGE}:alpine-${ref_tag}"
   143          push "${CI_REGISTRY_IMAGE}:${ref_tag}"
   144  
   145          push_latest "${CI_REGISTRY_IMAGE}:ubuntu"
   146          push_latest "${CI_REGISTRY_IMAGE}:latest"
   147          push_latest "${CI_REGISTRY_IMAGE}:alpine"
   148  
   149          logout "${CI_REGISTRY}"
   150      fi
   151  fi
   152  
   153  if [[ -z "${PUSH_TO_DOCKER_HUB}" ]] || [[ "${PUSH_TO_DOCKER_HUB}" != "true" ]]; then
   154      echo "Skipping push to Docker Hub"
   155      exit 0
   156  fi
   157  
   158  if [[ -n "${DOCKER_HUB_USER}" ]] && [[ -n "${DOCKER_HUB_PASSWORD}" ]]; then
   159      login "${DOCKER_HUB_USER}" "${DOCKER_HUB_PASSWORD}"
   160  
   161      push "gitlab/gitlab-runner:ubuntu-${ref_tag}"
   162      push "gitlab/gitlab-runner:alpine-${ref_tag}"
   163      push "gitlab/gitlab-runner:${ref_tag}"
   164  
   165      push_latest gitlab/gitlab-runner:ubuntu
   166      push_latest gitlab/gitlab-runner:latest
   167      push_latest gitlab/gitlab-runner:alpine
   168  
   169      release_docker_helper_images
   170  
   171      logout
   172  fi