aboutsummaryrefslogtreecommitdiff
blob: 0fabd00de4926c470a8c52bf5aad791af9bccccf (plain)
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
#!/bin/bash

# Used to create Gentoo stage3 and portage containers simply by specifying a
# TARGET env variable.
# Example usage: TARGET=stage3-amd64 ./build.sh

set -e

if [[ -z "$TARGET" ]]; then
	echo "TARGET environment variable must be set e.g. TARGET=stage3-amd64-openrc."
	exit 1
fi

# Split the TARGET variable into three elements separated by hyphens
IFS=- read -r NAME ARCH SUFFIX <<< "${TARGET}"

VERSION=${VERSION:-$(date -u +%Y%m%d)}
if [[ "${NAME}" == "portage" ]]; then
	VERSION_SUFFIX=":${VERSION}"
else
	VERSION_SUFFIX="-${VERSION}"
fi

ORG=${ORG:-gentoo}

case $ARCH in
	"amd64" | "arm64")
		DOCKER_ARCH="${ARCH}"
		MICROARCH="${ARCH}"
		;;
	"armv"*)
		# armv6j_hardfp -> arm/v6
		# armv7a_hardfp -> arm/v7
		DOCKER_ARCH=$(echo "$ARCH" | sed -e 's#arm\(v.\).*#arm/\1#g')
		MICROARCH="${ARCH}"
		ARCH="arm"
		;;
	"i686")
		DOCKER_ARCH="386"
		MICROARCH="${ARCH}"
		ARCH="x86"
		;;
	"ppc64le")
		DOCKER_ARCH="${ARCH}"
		MICROARCH="${ARCH}"
		ARCH="ppc"
		;;
	"rv64_"*)
		# only support riscv64 for now
		DOCKER_ARCH=riscv64
		MICROARCH="${ARCH}"
		ARCH="riscv"
		;;
	"s390x")
		DOCKER_ARCH="${ARCH}"
		MICROARCH="${ARCH}"
		ARCH="s390"
		;;
	*)  # portage
		DOCKER_ARCH="amd64"
		;;
esac

# Prefix the suffix with a hyphen to make sure the URL works
if [[ -n "${SUFFIX}" ]]; then
	SUFFIX="-${SUFFIX}"
fi

docker buildx build \
	--file "${NAME}.Dockerfile" \
	--build-arg ARCH="${ARCH}" \
	--build-arg MICROARCH="${MICROARCH}" \
	--build-arg SUFFIX="${SUFFIX}" \
	--tag "${ORG}/${TARGET/-/:}" \
	--tag "${ORG}/${TARGET/-/:}${VERSION_SUFFIX}" \
	--platform "linux/${DOCKER_ARCH}" \
	--progress plain \
	--load \
	.