gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+incompatible/ci/release_docker_images (about)

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