diff --git a/README.md b/README.md index 9291775e9..9bf0e5499 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ which you can use for any environment variables not supported by CR field. The o ## How to Build Operator Image ```bash -docker build -t $registry/$repo:$tag +docker build -t $registry/$repo:$tag . ``` You can then use the resulting image in operator deployment (deploy/operator.yaml) diff --git a/cico_build_nightly.sh b/cico_build_nightly.sh new file mode 100644 index 000000000..76103b712 --- /dev/null +++ b/cico_build_nightly.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Copyright (c) 2012-2019 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# + +# Output command before executing +set -x + +# Exit on error +set -e + +SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) +export SCRIPT_DIR + +# shellcheck disable=SC1090 +. "${SCRIPT_DIR}"/cico_functions.sh + +load_jenkins_vars +install_deps +set_nightly_tag +build_and_push diff --git a/cico_functions.sh b/cico_functions.sh new file mode 100644 index 000000000..5ac3816c9 --- /dev/null +++ b/cico_functions.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# +# Copyright (c) 2012-2019 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# + +# Output command before executing +set -x + +# Exit on error +set -e + +# Source environment variables of the jenkins slave +# that might interest this worker. +function load_jenkins_vars() { + if [ -e "jenkins-env.json" ]; then + eval "$(./env-toolkit load -f jenkins-env.json \ + DEVSHIFT_TAG_LEN \ + QUAY_ECLIPSE_CHE_USERNAME \ + QUAY_ECLIPSE_CHE_PASSWORD \ + JENKINS_URL \ + GIT_BRANCH \ + GIT_COMMIT \ + BUILD_NUMBER \ + ghprbSourceBranch \ + ghprbActualCommit \ + BUILD_URL \ + ghprbPullId)" + fi +} + +function install_deps() { + # We need to disable selinux for now, XXX + /usr/sbin/setenforce 0 || true + + # Get all the deps in + yum install -y yum-utils device-mapper-persistent-data lvm2 + yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + yum install -y docker-ce \ + git + + service docker start + echo 'CICO: Dependencies installed' +} + +function set_nightly_tag() { + # Let's set the tag as nightly + export TAG="nightly" +} + +function tag_push() { + local TARGET=$1 + docker tag "${IMAGE}" "$TARGET" + docker push "$TARGET" +} + +function build_and_push() { + REGISTRY="quay.io" + ORGANIZATION="eclipse" + IMAGE="che-operator" + QUAY_USERNAME=${QUAY_ECLIPSE_CHE_USERNAME} + QUAY_PASSWORD=${QUAY_ECLIPSE_CHE_PASSWORD} + + if [ -n "${QUAY_USERNAME}" ] && [ -n "${QUAY_PASSWORD}" ]; then + docker login -u "${QUAY_USERNAME}" -p "${QUAY_PASSWORD}" "${REGISTRY}" + else + echo "Could not login, missing credentials for pushing to the '${ORGANIZATION}' organization" + fi + + # Let's build and push images to 'quay.io' + docker build -t ${IMAGE} . + tag_push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" + echo "CICO: '${TAG}' version of image pushed to '${REGISTRY}/${ORGANIZATION}' organization" +}