Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 53 additions & 30 deletions .github/workflows/dockerbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: Docker Build & Push (Multi-Service)
on:
workflow_call:
inputs:
repo_name:
description: "Final Repo name"
type: string
default: ''
required: false
repo_name:
description: "Final Repo name"
type: string
default: ''
required: false
build_args:
description: 'Optional Docker build arguments in format key=value,key=value'
type: string
Expand Down Expand Up @@ -37,13 +37,19 @@ on:
type: string
default: "."
required: false
secrets:
HARBOR_HOST:
required: false
HARBOR_CREDENTIALS:
required: false

jobs:
setup:
uses: eclipse-xfsc/dev-ops/.github/workflows/build-context.yml@main
secrets: inherit
with:
repo_name: ${{ inputs.repo_name }}
repo_name: ${{ inputs.repo_name }}

docker-build:
needs: setup
runs-on: ubuntu-latest
Expand All @@ -52,52 +58,69 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Find and build Docker images (multi-arch)
env:
env:
HARBOR_HOST: ${{ secrets.HARBOR_HOST }}
HARBOR_CREDENTIALS: ${{ secrets.HARBOR_CREDENTIALS }}
run: |
run: |
git clone https://github.com/eclipse-xfsc/dev-ops.git devops
echo "clone successfull"
chmod +x ./devops/scripts/harborconfig.sh
. ./devops/scripts/harborconfig.sh ${{ inputs.harbor_config}}
echo "harborconfig loaded"
echo "Connect $HARBOR_HOST"
echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST --username "$HARBOR_USERNAME" --password-stdin

echo "clone successful"

IMAGE_TAG="${{ needs.setup.outputs.image_tag }}"
PLATFORMS="${{ inputs.platforms }}"
echo "🔖 Tag: $IMAGE_TAG"
echo "🧬 Platforms: $PLATFORMS"
REPO_NAME="${{ needs.setup.outputs.repo_name }}"
SERVICE_NAME="${{ inputs.service }}"

if [[ "$SERVICE_NAME" == "." ]]; then
FINAL_NAME="$REPO_NAME"
else
FINAL_NAME="$SERVICE_NAME"
fi

# Convert comma-separated build_args string to space-separated --build-arg args
BUILD_ARGS=""
if [[ -n "${{ inputs.build_args }}" ]]; then
IFS=',' read -ra ARGS <<< "${{ inputs.build_args }}"
for arg in "${ARGS[@]}"; do
BUILD_ARGS+="--build-arg $arg "
done
fi

REPO_NAME=${{ needs.setup.outputs.repo_name }}
SERVICE_NAME="${{ inputs.service }}"

if [[ "$SERVICE_NAME" == "." ]]; then
FINAL_NAME="$REPO_NAME"

if [[ -n "$HARBOR_HOST" && -n "$HARBOR_CREDENTIALS" ]]; then
chmod +x ./devops/scripts/harborconfig.sh
. ./devops/scripts/harborconfig.sh ${{ inputs.harbor_config }}

echo "harborconfig loaded"
echo "Connect $HARBOR_HOST"

echo "$HARBOR_PASSWORD" | docker login "$HARBOR_HOST" --username "$HARBOR_USERNAME" --password-stdin

IMAGE="$HARBOR_HOST/$HARBOR_PROJECT/$FINAL_NAME:$IMAGE_TAG"
OUTPUT_ARG="--push"
else
FINAL_NAME="$SERVICE_NAME"
fi
echo "Harbor secrets not provided. Building image without push."

IMAGE="$FINAL_NAME:$IMAGE_TAG"
OUTPUT_ARG="--load"

IMAGE="$HARBOR_HOST/$HARBOR_PROJECT/$FINAL_NAME:$IMAGE_TAG"
if [[ "$PLATFORMS" == *","* ]]; then
echo "Multi-platform build without push is not supported with --load."
echo "Falling back to linux/amd64."
PLATFORMS="linux/amd64"
fi
fi

echo "🐳 Building $FINAL_NAME → $IMAGE"
echo "Tag: $IMAGE_TAG"
echo "Platforms: $PLATFORMS"
echo "Building $FINAL_NAME → $IMAGE"

docker buildx build \
--platform "$PLATFORMS" \
--file ${{ inputs.dockerfile}} \
--file ${{ inputs.dockerfile }} \
$BUILD_ARGS \
--push \
$OUTPUT_ARG \
--tag "$IMAGE" \
${{ inputs.buildContext }}