Skip to content
Snippets Groups Projects
Commit fc701ca6 authored by Christian Winter's avatar Christian Winter
Browse files

create pipeline steps for each container, that only execute if the relevant Dockerfile was changed

parent 6d7862b7
Branches
No related tags found
No related merge requests found
stages: stages:
- build_and_push - 🏗️ build_and_push
- create_jupytermachine_version - create_jupytermachine_version
variables: variables:
DOCKER_REGISTRY: "docker.io" DOCKER_HUB_USER: "jeppelt"
IMAGE_PREFIX: "jeppelt" # Change this to your Docker Hub username
JUPYTERMACHINE_DOCKERFILE: "basic_jupytermachine/Dockerfile"
build_and_push: .common_build:
stage: build_and_push
image: docker:latest image: docker:latest
stage: 🏗️ build_and_push
rules:
- changes:
- $IMAGE_NAME/Dockerfile
before_script:
- docker login -u $DOCKER_HUB_USER -p $DOCKER_TOKEN
script: script:
- | - docker build -t "$DOCKER_HUB_USER/etp_$IMAGE_NAME" $IMAGE_NAME/Dockerfile --no-cache;
export IMAGES=( "basis" "tp" "python311" "basis_jupytermachine") # "tp_herwig") # "tp_geant" "cuda_basis" - docker push "$DOCKER_HUB_USER/etp_$IMAGE_NAME";
docker login -u jeppelt -p $DOCKER_TOKEN;
for image in "${IMAGES[@]}"; do basis:
echo "$image"; variables:
cd "$image"; IMAGE_NAME: "basis"
docker build -t "$IMAGE_PREFIX/etp_${image}" . --no-cache; extends:
docker push "$IMAGE_PREFIX/etp_${image}"; - .common_build
cd ../;
done
tp:
variables:
IMAGE_NAME: "tp"
extends:
- .common_build
python311:
variables:
IMAGE_NAME: "python311"
extends:
- .common_build
basis_jupytermachine:
variables:
IMAGE_NAME: "basis_jupytermachine"
extends:
- .common_build
tp_herwig:
variables:
IMAGE_NAME: "tp_herwig"
extends:
- .common_build
create_jupytermachine_version: create_jupytermachine_version:
stage: create_jupytermachine_version stage: create_jupytermachine_version
...@@ -29,20 +53,21 @@ create_jupytermachine_version: ...@@ -29,20 +53,21 @@ create_jupytermachine_version:
script: script:
- | - |
IMAGES=( "basis" "tp" "python311") # "tp_herwig") # "tp_geant" "cuda_basis" IMAGES=( "basis" "tp" "python311") # "tp_herwig") # "tp_geant" "cuda_basis"
docker login -u jeppelt -p $DOCKER_TOKEN docker login -u $DOCKER_HUB_USER -p $DOCKER_TOKEN
cd basis_jupytermachine cd basis_jupytermachine
for image in "${IMAGES[@]}"; do for image in "${IMAGES[@]}"; do
# Read the existing base image from the Dockerfile # Read the existing base image from the Dockerfile
OLD_BASE_IMAGE=$(grep -E '^\s*FROM\s+.*' Dockerfile | awk '{print $2}'); OLD_BASE_IMAGE=$(grep -E '^\s*FROM\s+.*' Dockerfile | awk '{print $2}');
echo $OLD_BASE_IMAGE; echo $OLD_BASE_IMAGE;
# Replace "basic_jupytermachine" with the new base image name # Replace "basic_jupytermachine" with the new base image name
NEW_BASE_IMAGE=$IMAGE_PREFIX/etp_$image; NEW_BASE_IMAGE=$DOCKER_HUB_USER/etp_$image;
echo $NEW_BASE_IMAGE; echo $NEW_BASE_IMAGE;
sed -i "s#$OLD_BASE_IMAGE#$NEW_BASE_IMAGE#" "Dockerfile" sed -i "s#$OLD_BASE_IMAGE#$NEW_BASE_IMAGE#" "Dockerfile"
cat Dockerfile; cat Dockerfile;
# Build the second version of the container # Build the second version of the container
docker build -t "$IMAGE_PREFIX/jupytermachine_${image}" -f "Dockerfile" . --no-cache; docker build -t "$DOCKER_HUB_USER/jupytermachine_${image}" -f "Dockerfile" . --no-cache;
docker push "$IMAGE_PREFIX/jupytermachine_${image}"; docker push "$DOCKER_HUB_USER/jupytermachine_${image}";
# Revert the Dockerfile to its original state for other iterations # Revert the Dockerfile to its original state for other iterations
sed -i "s#$NEW_BASE_IMAGE#$OLD_BASE_IMAGE#" "Dockerfile" sed -i "s#$NEW_BASE_IMAGE#$OLD_BASE_IMAGE#" "Dockerfile"
done done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment