forked from ServerContainers/samba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·84 lines (58 loc) · 2.95 KB
/
build.sh
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
#!/bin/sh -x
[ -z "$DOCKER_REGISTRY" ] && echo "error please specify docker-registry DOCKER_REGISTRY" && exit 1
IMG="$DOCKER_REGISTRY/samba"
PLATFORM="linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6"
rm -rf variants.tar variants/ 2>/dev/null >/dev/null
TAG=$(./get-version.sh)
if echo "$@" | grep -v "force" 2>/dev/null >/dev/null; then
# if there was a commit within the last hour, rebuild the container - even if it's already build
ONE_HOUR_IN_SECONDS=3600
EPOCH_SINCE_LAST_PUSH=$(git log -1 --format=%cd --date=iso | xargs -I {} date -d "{}" +%s || git log -1 --format=%cd --date=iso | xargs -I {} date -jf '%Y-%m-%d %H:%M:%S %z' "{}" +%s)
SECONDS_SINCE_LAST_PUSH=$(expr $(date +%s) - $EPOCH_SINCE_LAST_PUSH)
if [ "$SECONDS_SINCE_LAST_PUSH" -gt "$ONE_HOUR_IN_SECONDS" ]; then
echo "check if image was already build and pushed - skip check on release version"
echo "$@" | grep -v "release" && docker pull "$IMG:$TAG" 2>/dev/null >/dev/null && echo "image already build" && exit 1
else
echo "commit within the last hour, we skip the version check and try to overwrite current build"
fi
fi
docker buildx build -q --pull --no-cache --platform "$PLATFORM" -t "$IMG:$TAG" --push .
echo "$@" | grep "release" 2>/dev/null >/dev/null && echo ">> releasing new latest" && docker buildx build -q --pull --platform "$PLATFORM" -t "$IMG:latest" --push .
# make sure to exit if this is only version check
echo "$@" | grep "version-check" && exit 0
# make sure this is only executed in main script
echo "$@" | grep "variant" && exit 0
tar cf variants.tar --exclude .git/ --exclude variants.tar .
mkdir -p variants/smbd-only variants/smbd-avahi variants/smbd-wsdd2
cd variants/smbd-only
tar xf ../../variants.tar
cat Dockerfile | grep -v avahi | grep -v wsdd2 > Dockerfile.new
echo "ENV WSDD2_DISABLE=disabled" >> Dockerfile.new
echo "ENV AVAHI_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/avahi config/runit/avahi
rm -rf config/runit/wsdd2
sed -i.bak 's/:$TAG" --push/:smbd-only-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-only-latest/g' build.sh && rm build.sh.bak
./build.sh "variant" "$@"
cd ../../
cd variants/smbd-avahi
tar xf ../../variants.tar
cat Dockerfile | grep -v wsdd2 > Dockerfile.new
echo "ENV WSDD2_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/runit/wsdd2
sed -i.bak 's/:$TAG" --push/:smbd-avahi-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-avahi-latest/g' build.sh && rm build.sh.bak
./build.sh "variant" "$@"
cd ../../
cd variants/smbd-wsdd2
tar xf ../../variants.tar
cat Dockerfile | grep -v avahi > Dockerfile.new
echo "ENV AVAHI_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/avahi config/runit/avahi
sed -i.bak 's/:$TAG" --push/:smbd-wsdd2-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-wsdd2-latest/g' build.sh && rm build.sh.bak
./build.sh "variant" "$@"
cd ../../