chore(build): Updating build script to take custom docker runtimes
Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com>
This commit is contained in:
parent
9e7f1971dd
commit
ea54ab181b
1 changed files with 71 additions and 60 deletions
131
backend/build.sh
131
backend/build.sh
|
|
@ -14,80 +14,91 @@ image_tag=${IMAGE_TAG:-$git_sha}
|
||||||
ee="false"
|
ee="false"
|
||||||
# Possible values: amd64, arm64
|
# Possible values: amd64, arm64
|
||||||
arch="${ARCH:-"amd64"}"
|
arch="${ARCH:-"amd64"}"
|
||||||
|
docker() {
|
||||||
|
local docker_cmd=${DOCKER_RUNTIME}
|
||||||
|
[[ $docker_cmd == "docker" ]] && docker_cmd=$(which docker)
|
||||||
|
if [[ "$1" == "build" ]]; then
|
||||||
|
shift
|
||||||
|
# Reconstruct command with DOCKER_ARGS before the '.'
|
||||||
|
$docker_cmd build "${DOCKER_BUILD_ARGS}" "$@"
|
||||||
|
else
|
||||||
|
$docker_cmd "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
check_prereq() {
|
check_prereq() {
|
||||||
which docker || {
|
which docker || {
|
||||||
echo "Docker not installed, please install docker."
|
echo "Docker not installed, please install docker."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $1 == ee ]] && ee=true
|
[[ $1 == ee ]] && ee=true
|
||||||
[[ $PATCH -eq 1 ]] && {
|
[[ $PATCH -eq 1 ]] && {
|
||||||
chart=$2
|
chart=$2
|
||||||
image_tag="$(grep -ER ^.ppVersion ../scripts/helmcharts/openreplay/charts/$chart | xargs | awk '{print $2}' | awk -F. -v OFS=. '{$NF += 1 ; print}')"
|
image_tag="$(grep -ER ^.ppVersion ../scripts/helmcharts/openreplay/charts/$chart | xargs | awk '{print $2}' | awk -F. -v OFS=. '{$NF += 1 ; print}')"
|
||||||
[[ $ee == "true" ]] && {
|
[[ $ee == "true" ]] && {
|
||||||
image_tag="${image_tag}-ee"
|
image_tag="${image_tag}-ee"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_helm_release() {
|
update_helm_release() {
|
||||||
chart=$1
|
chart=$1
|
||||||
HELM_TAG="$(grep -iER ^version ../scripts/helmcharts/openreplay/charts/$chart | awk '{print $2}' | awk -F. -v OFS=. '{$NF += 1 ; print}')"
|
HELM_TAG="$(grep -iER ^version ../scripts/helmcharts/openreplay/charts/$chart | awk '{print $2}' | awk -F. -v OFS=. '{$NF += 1 ; print}')"
|
||||||
# Update the chart version
|
# Update the chart version
|
||||||
sed -i "s#^version.*#version: $HELM_TAG# g" ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
sed -i "s#^version.*#version: $HELM_TAG# g" ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
||||||
# Update image tags
|
# Update image tags
|
||||||
sed -i "s#ppVersion.*#ppVersion: \"$image_tag\"#g" ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
sed -i "s#ppVersion.*#ppVersion: \"$image_tag\"#g" ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
||||||
# Commit the changes
|
# Commit the changes
|
||||||
git add ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
git add ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
||||||
git commit -m "chore(helm): Updating $chart image release"
|
git commit -m "chore(helm): Updating $chart image release"
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_service() {
|
function build_service() {
|
||||||
image="$1"
|
image="$1"
|
||||||
echo "BUILDING $image"
|
echo "BUILDING $image"
|
||||||
docker build -t ${DOCKER_REPO:-'local'}/$image:${image_tag} --platform linux/$arch --build-arg ARCH=$arch --build-arg SERVICE_NAME=$image --build-arg GIT_SHA=$git_sha --build-arg GSSAPI=${GSSAPI:-'false'} .
|
docker build -t ${DOCKER_REPO:-'local'}/$image:${image_tag} --platform linux/$arch --build-arg ARCH=$arch --build-arg SERVICE_NAME=$image --build-arg GIT_SHA=$git_sha .
|
||||||
[[ $PUSH_IMAGE -eq 1 ]] && {
|
[[ $PUSH_IMAGE -eq 1 ]] && {
|
||||||
docker push ${DOCKER_REPO:-'local'}/$image:${image_tag}
|
docker push ${DOCKER_REPO:-'local'}/$image:${image_tag}
|
||||||
}
|
}
|
||||||
[[ $SIGN_IMAGE -eq 1 ]] && {
|
[[ $SIGN_IMAGE -eq 1 ]] && {
|
||||||
cosign sign --key $SIGN_KEY ${DOCKER_REPO:-'local'}/$image:${image_tag}
|
cosign sign --key $SIGN_KEY ${DOCKER_REPO:-'local'}/$image:${image_tag}
|
||||||
}
|
}
|
||||||
echo "Build completed for $image"
|
echo "Build completed for $image"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_api() {
|
function build_api() {
|
||||||
destination="_backend"
|
destination="_backend"
|
||||||
[[ $1 == "ee" ]] && {
|
[[ $1 == "ee" ]] && {
|
||||||
destination="_backend_ee"
|
destination="_backend_ee"
|
||||||
}
|
}
|
||||||
[[ -d ../${destination} ]] && {
|
[[ -d ../${destination} ]] && {
|
||||||
echo "Removing previous build cache"
|
echo "Removing previous build cache"
|
||||||
rm -rf ../${destination}
|
rm -rf ../${destination}
|
||||||
}
|
}
|
||||||
cp -R ../backend ../${destination}
|
cp -R ../backend ../${destination}
|
||||||
cd ../${destination}
|
cd ../${destination}
|
||||||
# Copy enterprise code
|
# Copy enterprise code
|
||||||
[[ $1 == "ee" ]] && {
|
[[ $1 == "ee" ]] && {
|
||||||
cp -r ../ee/backend/* ./
|
cp -r ../ee/backend/* ./
|
||||||
ee="true"
|
ee="true"
|
||||||
}
|
}
|
||||||
[[ $2 != "" ]] && {
|
[[ $2 != "" ]] && {
|
||||||
build_service $2
|
build_service $2
|
||||||
[[ $PATCH -eq 1 ]] && update_helm_release $2
|
[[ $PATCH -eq 1 ]] && update_helm_release $2
|
||||||
cd ../backend
|
cd ../backend
|
||||||
rm -rf ../${destination}
|
rm -rf ../${destination}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for image in $(ls cmd); do
|
for image in $(ls cmd); do
|
||||||
build_service $image
|
build_service $image
|
||||||
echo "::set-output name=image::${DOCKER_REPO:-'local'}/$image:${image_tag}"
|
echo "::set-output name=image::${DOCKER_REPO:-'local'}/$image:${image_tag}"
|
||||||
[[ $PATCH -eq 1 ]] && update_helm_release $image
|
[[ $PATCH -eq 1 ]] && update_helm_release $image
|
||||||
done
|
done
|
||||||
cd ../backend
|
cd ../backend
|
||||||
rm -rf ../${destination}
|
rm -rf ../${destination}
|
||||||
echo "backend build completed"
|
echo "backend build completed"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_prereq
|
check_prereq
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue