From 6cdab8d225a6daa2fa89abffc248b592e3102d79 Mon Sep 17 00:00:00 2001 From: Tjaarda1 <100383348@alumnos.uc3m.es> Date: Wed, 24 Jan 2024 12:58:02 +0100 Subject: [PATCH] build: Added build_and_push_images.sh script This commit introduces a new bash script, build_and_push_images.sh, which automates the process of building and pushing Docker images for l2sm-switch, l2sm-controller, and l2sm-operator. This script simplifies the image creation and push workflow, providing options for building images, pushing images, or both. --- build/build_images.sh | 52 +++++++++++++++++++++++++++++++++++++++++ build/switch/Dockerfile | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 build/build_images.sh diff --git a/build/build_images.sh b/build/build_images.sh new file mode 100755 index 0000000..e37ce89 --- /dev/null +++ b/build/build_images.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Set environment variables +export VERSION="2.2" +export DOCKERHUB_REPO="alexdecb" + +# Function to build image +build_image() { + local image_name="$1" + local folder_name="$2" + + echo "Building ${image_name}..." + docker build -t "${DOCKERHUB_REPO}/${image_name}:${VERSION}" -f "./build/${folder_name}/Dockerfile" . +} + +# Function to push image +push_image() { + local image_name="$1" + + echo "Pushing ${image_name}..." + docker push "${DOCKERHUB_REPO}/${image_name}:${VERSION}" +} + +# Option 1: Build image +if [ "$1" == "build" ]; then + build_image "l2sm-switch" "switch" + build_image "l2sm-controller" "controller" + build_image "l2sm-operator" "operator" + echo "Images have been built successfully." + +# Option 2: Push image +elif [ "$1" == "push" ]; then + push_image "l2sm-switch" + push_image "l2sm-controller" + push_image "l2sm-operator" + echo "Images have been pushed successfully." + +# Option 3: Build and push image +elif [ "$1" == "build_push" ]; then + build_image "l2sm-switch" "switch" + push_image "l2sm-switch" + build_image "l2sm-controller" "controller" + push_image "l2sm-controller" + build_image "l2sm-operator" "operator" + push_image "l2sm-operator" + echo "Images have been built and pushed successfully." + +# Invalid option +else + echo "Invalid option. Please use 'build', 'push', or 'build_push'." + exit 1 +fi diff --git a/build/switch/Dockerfile b/build/switch/Dockerfile index 3d62217..8e96044 100644 --- a/build/switch/Dockerfile +++ b/build/switch/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /usr/src/l2sm-switch COPY ./src/switch/ ./build/switch/build-go.sh ./ -RUN ./build-go.sh +RUN chmod +x ./build-go.sh && ./build-go.sh FROM ubuntu:latest -- GitLab