#!/usr/bin/env bash

#
#	MetaCall Build Bash Script by Parra Studios
#	Build and install bash script utility for MetaCall.
#
#	Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
#
#	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.
#

# Load environment variables
source ./hooks/env

# Show message
echo "[***] Build hook running"
echo "[***]  - Building $IMAGE_NAME from dockerfile $DOCKERFILE_PATH"
echo "[***]  - Running build script from `pwd`"

# Link docker ignore for the context
ln -sf "`pwd`/.dockerignore" ../../.dockerignore

# TODO
# 	--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
# 	--build-arg "SOURCE_COMMIT=$GIT_SHA1" \
# 	--build-arg "DOCKERFILE_PATH=$DOCKERFILE_PATH" \
# 	--build-arg "SOURCE_TYPE=$SOURCE_TYPE" \
# 	${VERSION:+--build-arg "VERSION=$VERSION"} \

# Build dev image
docker build \
	--cache-from registry.hub.docker.com/$IMAGE_NAME \
	--build-arg "METACALL_PATH=$METACALL_PATH" \
	--build-arg "METACALL_BUILD_TYPE=$METACALL_BUILD_TYPE" \
	--build-arg "METACALL_BUILD_OPTIONS=$METACALL_BUILD_OPTIONS" \
	-t $IMAGE_NAME \
	-f $DOCKERFILE_PATH ../..
