Files
CICD-KAJE/.workflow/01_container_build.sh
Karsten Jeppesen e558afec0b 01_container_build.sh: will handle Dockerfile
Repos with Dockerfile in root will be processed
2026-11-25 20:40:09 +01:00

67 lines
2.2 KiB
Bash

#!/bin/bash
/bin/echo "$0 - Building all containers [$(pwd)]"
echo "USER: $UID"
# Parse owner/repo from GIT_URL
: "${GIT_URL:?Missing GIT_URL in Jenkins env}"
# GIT_URL="https://gitea.a.ucnit.eu/DMA-CSD-CICD/Test01.git"
# Handle formats: https://gitea.example.com/owner/repo.git or git@gitea.example.com:owner/repo.git
OWNER=""
REPO=""
GIT=""
if echo "$GIT_URL" | grep -q "^http"; then
GIT=$(echo "$GIT_URL" | cut -f 3 -d '/')
OWNER=$(echo "$GIT_URL" | cut -f 4 -d '/')
REPO=$(echo "$GIT_URL" | cut -f 5 -d '/' | xargs -- basename -s .git)
fi
if echo "$GIT_URL" | grep -q "^git@"; then
GIT=$(echo "$GIT_URL" | cut -f 2 -d '@' | cut -f 1 -d ':')
OWNER=$(echo "$GIT_URL" | cut -f 2 -d ':' | cut -f 1 -d '/')
REPO=$(echo "$GIT_URL" | cut -f 2 -d '/' | xargs -- basename -s .git)
fi
if true; then
echo "GIT: [$GIT]"
echo "OWNER: [$OWNER]"
echo "REPO: [$REPO]"
fi
# if [[ "$GIT_URL" =~ [:\/]([^\/:]+)\/([^\/\.]+)(\.git)?$ ]]; then
# OWNER="${BASH_REMATCH[1]}"
# REPO="${BASH_REMATCH[2]}"
# fi
if [[ -z "$OWNER" || -z "$REPO" ]]; then
echo "[ERROR] Could not determine owner/repo from GIT_URL=$GIT_URL"
exit 1
fi
echo "Will publish package at [$REPO]/[$OWNER]"
echo "Will build:"
/bin/find ./ -type f -name "*.csproj" | while read line; do
solution=$(echo "$line" | cut -f 2 -d '/')
project=$(echo "$line" | cut -f 3 -d '/')
echo "[$solution]:[$project]"
done
/bin/find ./ -type f -name "*.csproj" | while read line; do
solution=$(echo "$line" | cut -f 2 -d '/')
project=$(echo "$line" | cut -f 3 -d '/')
echo "Building [$solution] [$project]"
.workflow/DotDockerbuilder10.sh --solution $solution --project $project --git $GIT --gituser $OWNER --accesstoken $GITEA_API_KEY
done
if [ -f ./Dockerfile ]; then
echo "Dockerfile detected at main level"
### ALL NAMES MUST BE LOWER CASE
imageName=$(echo -n "$GIT/$OWNER/$REPO:$(date +%y%m%d)" | tr '[:upper:]' '[:lower:]')
echo "DEBUG: docker build --tag=$imageName ."
sudo docker build --tag=$imageName .
echo "DEBUG: docker login $GIT --username=$OWNER --password=$GITEA_API_KEY"
sudo docker login $GIT --username=$OWNER --password=$GITEA_API_KEY
echo "DEBUG: docker push $imageName"
sudo docker push $imageName
echo "DEBUG: docker image rm $imageName"
sudo docker image rm $imageName
fi