blob: 8023014a950a0ae4b2c89452f73d561e0ad1de20 [file] [log] [blame]
#!/bin/bash
# ============LICENSE_START=======================================================
# Copyright (C) 2020 The Nordix Foundation. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
set -o errexit
set -o pipefail
set -o nounset
# navigate to root of the git clone
cd "$WORKSPACE"
# TODO (fdegir): the versions need to be parameterized
# they are hardcoded in the script to get the basic builds working
# the job and script will be updated once the build is working and the versions are confirmed
# set openjdk and maven versions
OPENJDK_VERSION="8u265-b01-0ubuntu2~20.04"
MAVEN_VERSION="3.6.3-1"
# set maven build command
MAVEN_BUILD_CMD="mvn --quiet --batch-mode package -DskipTests"
# install openjdk and maven
echo "Info : Installing openjdk and maven"
echo "----------------------------------------------------------------"
sudo apt install -y -qq openjdk-8-jdk-headless="$OPENJDK_VERSION" maven="$MAVEN_VERSION"
echo "----------------------------------------------------------------"
echo "Info : Building the project with the command"
echo " $MAVEN_BUILD_CMD"
echo "----------------------------------------------------------------"
$MAVEN_BUILD_CMD
# find the warfile - we need to be in the folder where the service code is located
cd publish-service
PROJECT_WAR_FILE=$(ls target/*.war)
echo "----------------------------------------------------------------"
echo "Info : Build successful! Artifact is available as"
ls -al $PROJECT_WAR_FILE
echo "----------------------------------------------------------------"
# the Dockerfile to use for building the container image
IMAGE_DOCKERFILE="${IMAGE_DOCKERFILE:?IMAGE_DOCKERFILE is unset!}"
# the name of the container image
IMAGE_NAME="${IMAGE_NAME:?IMAGE_NAME is unset!}"
# the tag to apply to the container image
IMAGE_TAG="${IMAGE_TAG:-latest}"
# set image name
IMAGE_NAME_TAG="$NORDIX_REGISTRY/$HARBOR_EIFFEL_PROJECT/$IMAGE_NAME:$IMAGE_TAG"
# set the build command so we can log it to console
PODMAN_BUILD_CMD="podman build --build-arg URL=$PROJECT_WAR_FILE --file $IMAGE_DOCKERFILE --log-level $PODMAN_LOG_LEVEL --tag $IMAGE_NAME_TAG ."
echo "Info : Building the container image with the command"
echo " $PODMAN_BUILD_CMD"
echo "----------------------------------------------------------------"
$PODMAN_BUILD_CMD
echo "----------------------------------------------------------------"
echo "Info : Build successful! List of container images is"
echo "----------------------------------------------------------------"
podman images --log-level $PODMAN_LOG_LEVEL
echo "----------------------------------------------------------------"
echo "Info : Logging in to registry.nordix.org and pushing the image"
echo "----------------------------------------------------------------"
podman login --log-level "$PODMAN_LOG_LEVEL" "$NORDIX_REGISTRY" --username "$HARBOR_USERNAME" --password "$HARBOR_PASSWORD"
podman push --log-level "$PODMAN_LOG_LEVEL" "$IMAGE_NAME_TAG"
podman logout --log-level "$PODMAN_LOG_LEVEL" "$NORDIX_REGISTRY"
echo "----------------------------------------------------------------"
echo "Info : Done!"
# vim: set ts=2 sw=2 expandtab: