Skip to content
Snippets Groups Projects
Commit 66982741 authored by Hampölz, Rene's avatar Hampölz, Rene
Browse files

build: Add build container

parent d5300166
No related branches found
No related tags found
No related merge requests found
FROM docker:27
RUN apk update && \
apk add --no-cache bash curl jq nodejs npm
WORKDIR /workspace
...@@ -9,6 +9,8 @@ REGISTRY=registry.gitlab.tugraz.at/oop1ws/container ...@@ -9,6 +9,8 @@ REGISTRY=registry.gitlab.tugraz.at/oop1ws/container
NO_CACHE=false NO_CACHE=false
LOGIN=false LOGIN=false
BUILD_WITH_CONTAINER=false
print_usage() { print_usage() {
echo " echo "
$SCRIPT v$VERSION $SCRIPT v$VERSION
...@@ -31,13 +33,15 @@ print_usage() { ...@@ -31,13 +33,15 @@ print_usage() {
--push Push the build result to the registry --push Push the build result to the registry
--registry Use a custom container registry --registry Use a custom container registry
--no-cache Do not use cache when building the images --no-cache Do not use cache when building the images
--login Use the environment variables 'DOCKER_USERNAME' --login Use the environment variables 'DOCKER_USERNAME' and
and 'DOCKER_PASSWORD' to automatically login to the 'DOCKER_PASSWORD' to automatically login to the registry
registry --use-container Perform the building steps within a dedicated container
that already has all required build dependencies installed
" "
} }
ARGS=() ARGS=()
ALL_ARGS="$@"
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
...@@ -61,6 +65,9 @@ while [[ $# -gt 0 ]]; do ...@@ -61,6 +65,9 @@ while [[ $# -gt 0 ]]; do
--login) --login)
LOGIN=true LOGIN=true
;; ;;
--use-container)
BUILD_WITH_CONTAINER=true
;;
-*|--*) -*|--*)
echo "ERROR: Unknown option $1" echo "ERROR: Unknown option $1"
exit 1 exit 1
...@@ -92,6 +99,16 @@ check_command() { ...@@ -92,6 +99,16 @@ check_command() {
} }
check_command "docker" "Docker" check_command "docker" "Docker"
if $BUILD_WITH_CONTAINER; then
WORKSPACE=$(dirname "$0")
BUILD_IMAGE="$REGISTRY/builder"
BUILD_ARGS=${ALL_ARGS//"--use-container "/}
docker build --tag "$BUILD_IMAGE" -f build.Dockerfile .
docker run --rm -e DOCKER_USERNAME -e DOCKER_PASSWORD -v /var/run/docker.sock:/var/run/docker.sock:ro -v "$WORKSPACE":/workspace "$REGISTRY/builder" ./build.sh $BUILD_ARGS
exit $?
else
check_command "npx" "Node.js" check_command "npx" "Node.js"
check_command "jq" "jq" check_command "jq" "jq"
...@@ -100,18 +117,20 @@ if [ $? -ne 0 ]; then ...@@ -100,18 +117,20 @@ if [ $? -ne 0 ]; then
echo "ERROR: The Docker CLI plugin 'buildx' is not installed" echo "ERROR: The Docker CLI plugin 'buildx' is not installed"
exit 1 exit 1
fi fi
fi
# ============================= # =============================
# prepare environment # prepare environment
# ============================= # =============================
if $LOGIN; then if $LOGIN; then
if [ -v $DOCKER_PASSWORD ]; then if [ -z $DOCKER_USERNAME ]; then
echo "ERROR: Variable 'DOCKER_PASSWORD' not set"
exit 1
elif [ -v $DOCKER_USERNAME ]; then
echo "ERROR: Variable 'DOCKER_USERNAME' not set" echo "ERROR: Variable 'DOCKER_USERNAME' not set"
exit 1 exit 1
elif [ -z $DOCKER_PASSWORD ]; then
echo "ERROR: Variable 'DOCKER_PASSWORD' not set"
exit 1
fi fi
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin $REGISTRY echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin $REGISTRY
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment