-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiarch-alpine-build.sh
executable file
·84 lines (61 loc) · 2.43 KB
/
multiarch-alpine-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
TAG=socks5balancerasio
TAGB=socks5balancerasio-build
PLATFORM=("linux/amd64" "linux/arm64" "linux/arm/v7")
ARCH=("amd64" "arm64" "arm-v7")
# Check for & setup Docker BuildX to perform multi-architecture build
docker buildx create --name multiarchbuilder --platform linux/amd64,linux/arm64,linux/arm/v7
docker buildx use multiarchbuilder
docker buildx inspect --bootstrap
# Download sources into build directory
cd alpine-build
# Socks5BalancerAsio - v1.1 (with fixes)
git clone https://github.com/fossforreal/Socks5BalancerAsio
cd Socks5BalancerAsio
#git checkout 37b8cff06bdb7f8c892754e2c8fcf5dc743cf31c
cd ..
# For each PLATFORM <=> ARCH perform build
for idx in {0..2}; do
echo Building \"builder\" image for platform \"${PLATFORM[$idx]}\" and architecture \"${ARCH[$idx]}\"
sleep 1
cp -r Socks5BalancerAsio Socks5BalancerAsio-${ARCH[$idx]}
# Build builder docker image
docker buildx build --platform ${PLATFORM[$idx]} --load -t $TAGB:latest-${ARCH[$idx]} .
# Run builder to output binary
mkdir output-${ARCH[$idx]}
docker run -v $(pwd)/Socks5BalancerAsio:/Socks5BalancerAsio -v $(pwd)/output-${ARCH[$idx]}:/output $TAGB:latest-${ARCH[$idx]} /build.sh
done;
# Then finally build runner image
cd ..
cd alpine-run
# For each PLATFORM <=> ARCH perform build
for idx in {0..2}; do
echo Building \"runner\" image for platform \"${PLATFORM[$idx]}\" and architecture \"${ARCH[$idx]}\"
sleep 1
mkdir ${ARCH[$idx]}
cd ${ARCH[$idx]}
cp ../../alpine-build/output-${ARCH[$idx]}/Socks5BalancerAsio ./
cp ../entry.sh ./
cp ../Dockerfile ./
docker buildx build --platform ${PLATFORM[$idx]} --load -t $TAG:latest-${ARCH[$idx]} .
cd ..
done;
# Prepare files for demo run
cd ..
cp -r alpine-build/Socks5BalancerAsio/html/ ./html
cp alpine-build/Socks5BalancerAsio/example-config/FullConfig.json ./config.json
# Give help on how to use this & demo
echo
echo We have successfully built Socks5BalancerAsio
echo \(hopefully you have not encountered any errors\)
echo
echo Resulting images:
# For each PLATFORM <=> ARCH perform build
for idx in {0..2}; do
echo Platform \"${PLATFORM[$idx]}\", arch \"${ARCH[$idx]}\" \=\> $(docker images $TAG:latest-${ARCH[$idx]} --format "{{.Repository}}:{{.Tag}} -> {{.Size}}")
done;
echo
echo You can test them by running \(ARCH = amd64, arm64, arm-v7\):
echo
echo docker run -v \$\(pwd\)/html:/html -v \$\(pwd\)/config.json:/config.json -it $TAG:latest-ARCH
echo