-
Notifications
You must be signed in to change notification settings - Fork 3
103 lines (94 loc) · 3.2 KB
/
Copy pathdockerbuild.yml
File metadata and controls
103 lines (94 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Docker Build & Push (Multi-Service)
on:
workflow_call:
inputs:
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
required: false
platforms:
description: 'Target platforms (comma-separated, e.g. linux/amd64,linux/arm64)'
type: string
required: false
default: linux/amd64,linux/arm64
harbor_config:
description: 'path to harbor config'
type: string
default: "harbor.config"
required: false
dockerfile:
description: 'path to dockerfile'
type: string
default: "Dockerfile"
required: false
service:
description: 'path for build'
type: string
default: "."
required: false
buildContext:
description: 'path for build'
type: string
default: "."
required: false
jobs:
setup:
uses: eclipse-xfsc/dev-ops/.github/workflows/build-context.yml@main
secrets: inherit
with:
repo_name: ${{ inputs.repo_name }}
docker-build:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout
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:
HARBOR_HOST: ${{ secrets.HARBOR_HOST }}
HARBOR_CREDENTIALS: ${{ secrets.HARBOR_CREDENTIALS }}
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
IMAGE_TAG="${{ needs.setup.outputs.image_tag }}"
PLATFORMS="${{ inputs.platforms }}"
echo "🔖 Tag: $IMAGE_TAG"
echo "🧬 Platforms: $PLATFORMS"
# 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"
else
FINAL_NAME="$SERVICE_NAME"
fi
IMAGE="$HARBOR_HOST/$HARBOR_PROJECT/$FINAL_NAME:$IMAGE_TAG"
echo "🐳 Building $FINAL_NAME → $IMAGE"
docker buildx build \
--platform "$PLATFORMS" \
--file ${{ inputs.dockerfile}} \
$BUILD_ARGS \
--push \
--tag "$IMAGE" \
${{ inputs.buildContext }}