forked from pflooky/data-caterer
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdocker-action.sh
More file actions
62 lines (53 loc) · 1.9 KB
/
docker-action.sh
File metadata and controls
62 lines (53 loc) · 1.9 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
#!/usr/bin/env bash
# Determine version: use env var if set, otherwise get from gradle.properties with commit hash
if [ -n "$VERSION" ]; then
version="$VERSION"
else
base_version=$(grep version gradle.properties | cut -d= -f2)
commit_hash=$(git rev-parse --short HEAD)
# Check if on main branch
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
version="$base_version"
else
version="$base_version-$commit_hash"
fi
fi
platforms="linux/amd64,linux/arm64"
echo "Building version: $version"
echo "Branch/Ref: ${GITHUB_REF:-local}"
# Only publish to Maven on main branch
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
echo "Creating API jars and publishing to Maven, version=$version"
./gradlew clean :api:javadocJar :api:sourcesJar :api:shadowJar publishToSonatype closeAndReleaseSonatypeStagingRepository
publish_res=$?
if [[ "$publish_res" -ne 0 ]] ; then
echo "Publish API jar failed, exiting"
# exit 1
fi
else
echo "Feature branch detected - skipping Maven publish"
echo "Creating API jars locally, version=$version"
./gradlew clean :api:javadocJar :api:sourcesJar :api:shadowJar
fi
echo "Creating data caterer fat jars, version=$version"
./gradlew clean :app:shadowJar
build_app=$?
if [[ "$build_app" -ne 0 ]] ; then
echo "Failed to build app, exiting"
exit 1
fi
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --use --name builder
docker buildx inspect --bootstrap builder
# Build and tag Docker images
echo "Building and pushing Docker image with tag: $version"
docker buildx build --platform $platforms \
-t datacatering/data-caterer:$version --push .
# Also tag as 'latest' only for main branch
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
echo "Main branch - also tagging as 'latest'"
docker buildx build --platform $platforms \
-t datacatering/data-caterer:latest --push .
else
echo "Feature branch - skipping 'latest' tag"
fi