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

Add flag for build container

parent e72ae607
No related branches found
No related tags found
No related merge requests found
# Build the containers with:
# docker run --privileged --rm -v "$(pwd)":/workspace -v /var/run/docker.sock:/var/run/docker.sock -w /workspace container_build_container ./build.sh <some_tag> --latest --push --login --no-cache
FROM docker:24.0
FROM docker:27
RUN apk update && \
apk add --no-cache jq curl git bash nodejs npm
RUN docker buildx version
apk add --no-cache bash curl jq nodejs npm
WORKDIR /workspace
CMD ["/bin/bash"]
\ No newline at end of file
......@@ -9,6 +9,8 @@ REGISTRY=registry.gitlab.tugraz.at/oop1ws/container
NO_CACHE=false
LOGIN=false
BUILD_WITH_CONTAINER=false
print_usage() {
echo "
$SCRIPT v$VERSION
......@@ -31,13 +33,15 @@ print_usage() {
--push Push the build result to the registry
--registry Use a custom container registry
--no-cache Do not use cache when building the images
--login Use the environment variables 'DOCKER_USERNAME'
and 'DOCKER_PASSWORD' to automatically login to the
registry
--login Use the environment variables 'DOCKER_USERNAME' and
'DOCKER_PASSWORD' to automatically login to the registry
--use-container Perform the building steps within a dedicated container
that already has all required build dependencies installed
"
}
ARGS=()
ALL_ARGS="$@"
while [[ $# -gt 0 ]]; do
case $1 in
......@@ -61,6 +65,9 @@ while [[ $# -gt 0 ]]; do
--login)
LOGIN=true
;;
--use-container)
BUILD_WITH_CONTAINER=true
;;
-*|--*)
echo "ERROR: Unknown option $1"
exit 1
......@@ -92,6 +99,16 @@ check_command() {
}
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 "jq" "jq"
......@@ -100,18 +117,20 @@ if [ $? -ne 0 ]; then
echo "ERROR: The Docker CLI plugin 'buildx' is not installed"
exit 1
fi
fi
# =============================
# prepare environment
# =============================
if $LOGIN; then
if [ -v $DOCKER_PASSWORD ]; then
echo "ERROR: Variable 'DOCKER_PASSWORD' not set"
exit 1
elif [ -v $DOCKER_USERNAME ]; then
if [ -z $DOCKER_USERNAME ]; then
echo "ERROR: Variable 'DOCKER_USERNAME' not set"
exit 1
elif [ -z $DOCKER_PASSWORD ]; then
echo "ERROR: Variable 'DOCKER_PASSWORD' not set"
exit 1
fi
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