-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypt-keeper.sh
More file actions
executable file
·172 lines (140 loc) · 5.17 KB
/
Copy pathcrypt-keeper.sh
File metadata and controls
executable file
·172 lines (140 loc) · 5.17 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
set -exo pipefail
DOCKER_REGISTRY_USER=getpagespeed
# Load generated codename -> numeric dist mapping if present
[ -f "./distmap.sh" ] && . ./distmap.sh
# Declare a map for Ubuntu/Debian codename-based releases
declare -A DISTRO_DISTS=( [ubuntu]=ubuntu [debian]=debian )
function generate() {
SOURCES=${SOURCES-/sources}
OUTPUT=${OUTPUT-/output}
WORKSPACE=${WORKSPACE-/workspace}
DEB_BUILD_DIR=${DEB_BUILD_DIR-/debbuild}
DISTRO=${1-ubuntu}
RELEASE=${2-focal}
ROOT=$(pwd)/${DISTRO}/${RELEASE}/
ASSETS=${ROOT}/assets
DOCKERFILE=${ROOT}/Dockerfile
rm -rf "${ROOT}" && mkdir -p "${ROOT}"
# Prepare files
cp -R ./assets "${ROOT}"/.
# Determine base image for the Dockerfile
FROM_DISTRO="${DISTRO_DISTS[$DISTRO]}"
FROM_RELEASE_TAG="${RELEASE}"
# Generate Dockerfile
cat > "${DOCKERFILE}" << EOF
FROM ${FROM_DISTRO}:${FROM_RELEASE_TAG}
LABEL maintainer="Danila Vershinin <info@getpagespeed.com>"
ENV WORKSPACE=${WORKSPACE} \\
SOURCES=${SOURCES} \\
OUTPUT=${OUTPUT} \\
DEB_BUILD_DIR=${DEB_BUILD_DIR}
ENV DEBIAN_FRONTEND=noninteractive
ADD ./assets/build /usr/bin/build
ADD ./assets/check-deps.sh /usr/bin/check-deps.sh
ADD ./assets/plesk-target.py /usr/bin/plesk-target
#ADD ./assets/deblint.config /etc/deblint/config
ADD ./assets/transient/* /tmp/
# Optimize apt settings for faster downloads
RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries && \\
echo 'Acquire::http::Timeout "30";' >> /etc/apt/apt.conf.d/80-retries && \\
echo 'Acquire::ftp::Timeout "30";' >> /etc/apt/apt.conf.d/80-retries && \\
apt-get update
RUN apt-get install -y equivs
RUN DISTRO=${DISTRO} RELEASE=${RELEASE} /tmp/setup.sh
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
VOLUME ["\${SOURCES}", "\${OUTPUT}"]
CMD ["build"]
EOF
}
function map-all() {
while IFS=' ' read -r -a input; do
$1 "${input[0]}" "${input[1]}"
done < ./defaults
}
function docker-image-name() {
DISTRO=${1}
VERSION=${2}
echo -n "${DOCKER_REGISTRY_USER}/debbuilder:${DISTRO/\//-}-${VERSION}"
}
function docker-image-dist-tag() {
DISTRO=${1}
VERSION=${2}
# Prefer generated mapping if available
if declare -F codename_to_numeric_tag >/dev/null 2>&1; then
local dist_tag
dist_tag="$(codename_to_numeric_tag "${DISTRO}" "${VERSION}")"
echo -n "${DOCKER_REGISTRY_USER}/debbuilder:${dist_tag}"
return
fi
# Create dist tags using version numbers (similar to RPM's %{?dist} system)
# This matches patterns like ubuntu.24.04 seen in Plesk repositories
case "${DISTRO}" in
ubuntu)
case "${VERSION}" in
focal) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:ubuntu20.04" ;;
jammy) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:ubuntu22.04" ;;
noble) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:ubuntu24.04" ;;
kinetic) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:ubuntu22.10" ;;
*) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:ubuntu${VERSION}" ;;
esac
;;
debian)
case "${VERSION}" in
bookworm) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:debian12" ;;
trixie) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:debian13" ;;
sid) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:debian-sid" ;;
*) echo -n "${DOCKER_REGISTRY_USER}/debbuilder:debian${VERSION}" ;;
esac
;;
*)
echo -n "${DOCKER_REGISTRY_USER}/debbuilder:${DISTRO}${VERSION}"
;;
esac
}
function build() {
DISTRO=${1}
VERSION=${2}
MAIN_TAG="$(docker-image-name "${DISTRO}" "${VERSION}")"
DIST_TAG="$(docker-image-dist-tag "${DISTRO}" "${VERSION}")"
# Ensure buildx is set up and ready for multi-architecture builds
docker buildx create --use --name multiarch-builder --driver docker-container || true
echo "Building multi-architecture image for ${DISTRO}-${VERSION}"
echo "Tags: ${MAIN_TAG}, ${DIST_TAG}"
echo "Platforms: linux/amd64, linux/arm64"
cd "${DISTRO}/${VERSION}" && docker buildx build \
--platform linux/amd64,linux/arm64 \
--push \
-t "${MAIN_TAG}" \
-t "${DIST_TAG}" \
.
cd -
}
function push() {
echo "Nothing to do, pushed in the build step"
}
function test() {
# Test build for both architectures
DISTRO=${1}
VERSION=${2}
MAIN_TAG="$(docker-image-name "${DISTRO}" "${VERSION}")"
echo "Testing x86_64 build for ${DISTRO}-${VERSION}"
docker run --rm --platform linux/amd64 \
-v "$(pwd)"/tests:/sources \
-v "$(pwd)"/output:/output \
"${MAIN_TAG}" build
echo "Testing aarch64 build for ${DISTRO}-${VERSION}"
docker run --rm --platform linux/arm64 \
-v "$(pwd)"/tests:/sources \
-v "$(pwd)"/output:/output \
"${MAIN_TAG}" build
echo "Done testing both architectures for ${DISTRO}-${VERSION}"
}
case "$1" in
generate|build|push|test|docker-image-name|docker-image-dist-tag)
if [ "$2" == "all" ]; then
map-all "$1"
else
"$1" "$2" "$3"
fi ;;
esac