-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocker-build.rsh
50 lines (40 loc) · 1.63 KB
/
docker-build.rsh
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
# Due to difficulties building cross-platform binaries with Docker,
# I resort here to building locally using `cross` and then copying the
# output into a container.
# Ensure 'cross' is installed
if whereis('cross') == null {
throw 'Please install "cross" to continue.'
}
# Ensure a container engine is installed
if whereis('docker') == null && whereis('podman') == null {
throw 'Please install either "docker" or "podman" to continue.'
}
# Get name and version from the manifest
let manifest = readFile('Cargo.toml').parseToml()
let { name, version } = $manifest.package
# List build targets
let targets = map {
'armv7-unknown-linux-gnueabihf': 'linux/arm/v7',
'aarch64-unknown-linux-musl': 'linux/arm64',
'x86_64-unknown-linux-musl': 'linux/amd64'
}
# Build for every image
let buildDir = 'target/building-for-docker'
for target, dockerPlatform in $targets {
echo "\nBuilding for target: $target...\n"
# We use a different target directory for each crate and each target, otherwise dependencies build
# may clash between platforms
let targetDir = "$buildDir/targets/$target"
mkdir -p -i $targetDir
cross build --release --target $target --target-dir $targetDir
# Put build artifact in the correct directory
let artifactsFile = "$buildDir/artifacts/$dockerPlatform/$name"
mkdir -p (parentDir($artifactsFile))
cp "$targetDir/$target/release/$name" $artifactsFile
}
# Build and publish Docker images
echo '\nPublishing on Docker Hub...\n'
docker buildx build --push . \
--platform ($targets.values().join(',')) \
--tag "clementnerma/$name:$version" \
--tag "clementnerma/$name:latest"