Skip to content
functions 2.34 KiB
Newer Older
Pierre Ozoux's avatar
Pierre Ozoux committed
function prepare_env() {
  curl https://api.github.com/repos/nextcloud/server/tags?per_page=50 > /tmp/tags
Pierre Ozoux's avatar
Pierre Ozoux committed
  export MINOR_VERSION=`cat /tmp/tags | jq '.[] | select(.name|test(".rc.")|not) |select(.name|test("v'${MARKETTING_VERSION}'.")).name'  | head -n1 | cut -d\" -f2 | cut -c2-`
Pierre Ozoux's avatar
Pierre Ozoux committed
  export PATCH_NUMBER=`curl https://raw.githubusercontent.com/nextcloud/server/v${MINOR_VERSION}/version.php | grep '$OC_Version =' | cut -d, -f4 | cut -d] -f1 | xargs`
  echo "MARKETTING_VERSION=$MARKETTING_VERSION"
  echo "MINOR_VERSION=$MINOR_VERSION"
  echo "PATCH_VERSION=$MINOR_VERSION.$PATCH_NUMBER"
}

function build_kaniko() {
  echo "======Building kaniko with following env:"
  echo $CONTEXT
  echo $DESTINATION
  echo $BASE_TAG
  echo "======"
Timothee Gosselin's avatar
Timothee Gosselin committed
  /kaniko/executor --cache --context ${CONTEXT} ${DESTINATION} --build-arg MARKETTING_VERSION=$MARKETTING_VERSION --build-arg MINOR_VERSION=$MINOR_VERSION --build-arg PATCH_VERSION=$PATCH_VERSION --build-arg BASE_TAG=$BASE_TAG
Pierre Ozoux's avatar
Pierre Ozoux committed
}

function print_versions() {
  echo "======Building the following version:"
  echo $MARKETTING_VERSION
  echo $MINOR_VERSION
  echo $PATCH_VERSION
  echo "======"
}

function build_base() {
  export CONTEXT=${CI_PROJECT_DIR}/base
  cd ${CONTEXT}
  build_kaniko
}

function build_web() {
  export CONTEXT=${CI_PROJECT_DIR}/web
  cd ${CONTEXT}
  build_kaniko
}

function test_build() {
  print_versions
  export DESTINATION="--no-push"
Pierre Ozoux's avatar
Pierre Ozoux committed
  build_base
}

function build() {
  print_versions
  cp $DOCKER_SECRET_CONFIG /kaniko/.docker/config.json
  export DESTINATION_PREFIX="--destination ${DOCKER_HUB_REPO}"
  export DATE=`date "+%Y-%m-%dT%H-%M-%SZ"`
  
Hugo Renard's avatar
Hugo Renard committed
  if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then
Pierre Ozoux's avatar
Pierre Ozoux committed
    export BASE_TAG=${MINOR_VERSION}
    export DESTINATION="\
      ${DESTINATION_PREFIX}:${MINOR_VERSION}\
      ${DESTINATION_PREFIX}:${MINOR_VERSION}-${DATE}\
    "
    build_base
      export DESTINATION="\
      ${DESTINATION_PREFIX}:web-${MINOR_VERSION}\
      ${DESTINATION_PREFIX}:web-${MINOR_VERSION}-${DATE}\
    "
    build_web
  else # feature branch
    export BASE_TAG=${CI_COMMIT_BRANCH}
    export DESTINATION="\
      ${DESTINATION_PREFIX}:${CI_COMMIT_BRANCH}\
      ${DESTINATION_PREFIX}:${CI_COMMIT_BRANCH}-${DATE}\
    "
    build_base
      export DESTINATION="\
      ${DESTINATION_PREFIX}:web-${CI_COMMIT_BRANCH}\
      ${DESTINATION_PREFIX}:web-${CI_COMMIT_BRANCH}-${DATE}\
    "
    build_web
  fi