#!/bin/bash # # Copyright (c) 2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # # This utility builds the StarlingX wheel tarball # MY_SCRIPT_DIR=$(dirname $(readlink -f $0)) # Required env vars if [ -z "${MY_WORKSPACE}" -o -z "${MY_REPO}" ]; then echo "Environment not setup for builds" >&2 exit 1 fi SUPPORTED_OS_ARGS=('centos') OS=centos OS_VERSION=7.5.1804 IMAGE_VERSION= PUSH=no DOCKER_USER=${USER} DOCKER_REGISTRY= declare -a REPO_LIST REPO_OPTS= LOCAL=no CLEAN=no function usage { cat >&2 <&2 echo "Supported OS options: ${SUPPORTED_OS_ARGS[@]}" >&2 exit 1 fi if [ -z "${IMAGE_VERSION}" ]; then IMAGE_VERSION=${OS_VERSION} fi if [ ${#REPO_LIST[@]} -eq 0 ]; then # Either --repo or --local must be specified if [ "${LOCAL}" = "yes" ]; then REPO_LIST+=("local-std,http://${HOSTNAME}:8088${MY_WORKSPACE}/std/rpmbuild/RPMS") REPO_LIST+=("stx-distro,http://${HOSTNAME}:8088${MY_REPO}/cgcs-centos-repo/Binary") else echo "Either --local or --repo must be specified" >&2 exit 1 fi else if [ "${LOCAL}" = "yes" ]; then echo "Cannot specify both --local and --repo" >&2 exit 1 fi fi BUILDDIR=${MY_WORKSPACE}/std/build-images/stx-${OS} if [ -d ${BUILDDIR} ]; then # Leftover from previous build rm -rf ${BUILDDIR} fi mkdir -p ${BUILDDIR} if [ $? -ne 0 ]; then echo "Failed to create ${BUILDDIR}" >&2 exit 1 fi # Get the Dockerfile SRC_DOCKERFILE=${MY_SCRIPT_DIR}/stx-${OS}/Dockerfile cp ${SRC_DOCKERFILE} ${BUILDDIR} # Generate the stx.repo file STX_REPO_FILE=${BUILDDIR}/stx.repo for repo in ${REPO_LIST[@]}; do repo_name=$(echo $repo | awk -F, '{print $1}') repo_baseurl=$(echo $repo | awk -F, '{print $2}') if [ -z "${repo_name}" -o -z "${repo_baseurl}" ]; then echo "Invalid repo specified: ${repo}" >&2 echo "Expected format: name,baseurl" >&2 exit 1 fi cat >>${STX_REPO_FILE} <&2 exit 1 fi if [ "${PUSH}" = "yes" ]; then # Push the image echo "Pushing image: ${IMAGE_NAME}" docker push ${IMAGE_NAME} if [ $? -ne 0 ]; then echo "Failed running docker push command" >&2 exit 1 fi fi if [ "${CLEAN}" = "yes" ]; then # Delete the images echo "Deleting image: ${IMAGE_NAME}" docker image rm ${IMAGE_NAME} if [ $? -ne 0 ]; then echo "Failed running docker image rm command" >&2 exit 1 fi if [ ${BASE_IMAGE_PRESENT} -ne 0 ]; then # The base image was not already present, so delete it echo "Removing docker image ${OS}:${OS_VERSION}" docker image rm ${OS}:${OS_VERSION} if [ $? -ne 0 ]; then echo "Failed to delete base image from docker" >&2 fi fi fi