github.com/alloyci/alloy-runner@v1.0.1-0.20180222164613-925503ccafd6/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          --cache-from "${3}" \
    29          --build-arg DOCKER_MACHINE_VERSION="${DOCKER_MACHINE_VERSION}" \
    30          --build-arg DUMB_INIT_VERSION="${DUMB_INIT_VERSION}" \
    31          -t "${1}" \
    32          "${2}"
    33  }
    34  
    35  import() {
    36      echo -e "\033[1mImporting image: \033[32m${2}\033[0m"
    37      _docker import "${1}" "${2}"
    38  }
    39  
    40  tag() {
    41      echo -e "\033[1mTagging image: \033[32m${2}\033[0m"
    42      _docker tag "${1}" "${2}"
    43  }
    44  
    45  tag_latest() {
    46      if [[ -z "${IS_LATEST}" ]]; then
    47          return
    48      fi
    49  
    50      tag "${@}"
    51  }
    52  
    53  pull() {
    54      echo -e "\033[1mPulling image: \033[32m${1}\033[0m"
    55      _docker pull "${1}"
    56  }
    57  
    58  push() {
    59      echo -e "\033[1mPushing image: \033[32m${1}\033[0m"
    60      _docker push "${1}"
    61  }
    62  
    63  push_latest() {
    64      if [[ -z "${IS_LATEST}" ]]; then
    65          return
    66      fi
    67  
    68      push "${@}"
    69  }
    70  
    71  release_docker_helper_images() {
    72      helper_image_x86_64="alloyci/alloy-runner-helper:x86_64-${REVISION}"
    73      helper_image_x86_64_latest="alloyci/alloy-runner-helper:x86_64-latest"
    74      helper_image_arm="alloyci/alloy-runner-helper:arm-${REVISION}"
    75      helper_image_arm_latest="alloyci/alloy-runner-helper:arm-latest"
    76  
    77      import out/docker/prebuilt-x86_64.tar.xz ${helper_image_x86_64}
    78      import out/docker/prebuilt-arm.tar.xz ${helper_image_arm}
    79  
    80      tag_latest ${helper_image_x86_64} ${helper_image_x86_64_latest}
    81      tag_latest ${helper_image_arm} ${helper_image_arm_latest}
    82  
    83  
    84      push ${helper_image_x86_64}
    85      push ${helper_image_arm}
    86  
    87      push_latest ${helper_image_x86_64_latest}
    88      push_latest ${helper_image_arm_latest}
    89  }
    90  
    91  login() {
    92      _docker login --username "${1}" --password "${2}" "${3}"
    93  }
    94  
    95  logout() {
    96      _docker logout "${1}"
    97  }
    98  
    99  echo "${DOCKER_MACHINE_CHECKSUM}  /usr/bin/docker-machine" >> dockerfiles/checksums
   100  echo "${DUMB_INIT_CHECKSUM}  /usr/bin/dumb-init" >> dockerfiles/checksums
   101  cat dockerfiles/checksums
   102  
   103  cp out/deb/alloy-runner_amd64.deb dockerfiles/ubuntu/
   104  cp dockerfiles/checksums dockerfiles/ubuntu
   105  cp out/binaries/alloy-runner-linux-amd64 dockerfiles/alpine
   106  cp dockerfiles/checksums dockerfiles/alpine
   107  
   108  pull alloyci/alloy-runner:ubuntu
   109  pull alloyci/alloy-runner:alpine
   110  
   111  build "alloyci/alloy-runner:ubuntu-${ref_tag}" dockerfiles/ubuntu alloyci/alloy-runner:ubuntu
   112  build "alloyci/alloy-runner:alpine-${ref_tag}" dockerfiles/alpine alloyci/alloy-runner:alpine
   113  
   114  tag "alloyci/alloy-runner:ubuntu-${ref_tag}" "alloyci/alloy-runner:${ref_tag}"
   115  
   116  tag_latest "alloyci/alloy-runner:ubuntu-${ref_tag}" alloyci/alloy-runner:ubuntu
   117  tag_latest "alloyci/alloy-runner:ubuntu-${ref_tag}" alloyci/alloy-runner:latest
   118  tag_latest "alloyci/alloy-runner:alpine-${ref_tag}" alloyci/alloy-runner:alpine
   119  
   120  if [[ -z "${PUBLISH_IMAGES}" ]] || [[ "${PUBLISH_IMAGES}" != "true" ]]; then
   121      echo "Skipping images pushing"
   122      exit 0
   123  fi
   124  
   125  if [[ -z "${PUSH_TO_DOCKER_HUB}" ]] || [[ "${PUSH_TO_DOCKER_HUB}" != "true" ]]; then
   126      echo "Skipping push to Docker Hub"
   127      exit 0
   128  fi
   129  
   130  if [[ -n "${DOCKER_HUB_USER}" ]] && [[ -n "${DOCKER_HUB_PASSWORD}" ]]; then
   131      echo "Pushing to Docker Hub"
   132      
   133      login "${DOCKER_HUB_USER}" "${DOCKER_HUB_PASSWORD}"
   134  
   135      push "alloyci/alloy-runner:ubuntu-${ref_tag}"
   136      push "alloyci/alloy-runner:alpine-${ref_tag}"
   137      push "alloyci/alloy-runner:${ref_tag}"
   138  
   139      push_latest alloyci/alloy-runner:ubuntu
   140      push_latest alloyci/alloy-runner:latest
   141      push_latest alloyci/alloy-runner:alpine
   142  
   143      release_docker_helper_images
   144  
   145      logout
   146  fi