Skip to content

Commit c2ec1c2

Browse files
authored
Refactor architecture-specific installation logic
1 parent ad28338 commit c2ec1c2

File tree

1 file changed

+122
-96
lines changed

1 file changed

+122
-96
lines changed

base/ubi9/Dockerfile

Lines changed: 122 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -65,93 +65,111 @@ RUN \
6565

6666
# Download and install ripgrep depending on the architecture.
6767
# See release page for details https://github.com/BurntSushi/ripgrep/releases/tag/13.0.0
68-
RUN \
69-
if [ "$TARGETARCH" = "ppc64le" ]; then \
70-
echo "Skipping ripgrep installation for ppc64le as binary not available"; \
71-
else \
72-
TEMP_DIR="$(mktemp -d)" && cd "${TEMP_DIR}" && \
73-
RG_VERSION="13.0.0" && \
74-
if [ "$TARGETARCH" = "arm64" ]; then \
75-
RG_ARCH="arm-unknown-linux-gnueabihf"; \
76-
else \
77-
RG_ARCH="x86_64-unknown-linux-musl"; \
78-
fi && \
79-
RG_TGZ="ripgrep-${RG_VERSION}-${RG_ARCH}.tar.gz" && \
80-
RG_TGZ_URL="https://github.com/BurntSushi/ripgrep/releases/download/${RG_VERSION}/${RG_TGZ}" && \
81-
echo "Downloading ${RG_TGZ_URL}..." && \
82-
if curl -fsSL "${RG_TGZ_URL}" -o "${RG_TGZ}"; then \
83-
if file "${RG_TGZ}" | grep -q 'gzip compressed'; then \
84-
tar -zxv --no-same-owner -f "${RG_TGZ}" && \
85-
mv "ripgrep-${RG_VERSION}-${RG_ARCH}"/rg /usr/local/bin/ && \
86-
mv "ripgrep-${RG_VERSION}-${RG_ARCH}"/doc/rg.1 /usr/local/share/man/man1; \
87-
else \
88-
echo "Downloaded ripgrep archive invalid — skipping."; \
89-
fi; \
68+
RUN set -e; \
69+
case "$TARGETARCH" in \
70+
ppc64le) \
71+
echo "Skipping ripgrep installation for ppc64le as binary not available"; \
72+
exit 0 ;; \
73+
arm64) \
74+
RG_ARCH="arm-unknown-linux-gnueabihf" ;; \
75+
amd64) \
76+
RG_ARCH="x86_64-unknown-linux-musl" ;; \
77+
*) \
78+
echo "Unsupported architecture for ripgrep: $TARGETARCH"; \
79+
exit 0 ;; \
80+
esac; \
81+
TEMP_DIR="$(mktemp -d)"; \
82+
cd "${TEMP_DIR}"; \
83+
RG_VERSION="13.0.0"; \
84+
RG_TGZ="ripgrep-${RG_VERSION}-${RG_ARCH}.tar.gz"; \
85+
RG_TGZ_URL="https://github.com/BurntSushi/ripgrep/releases/download/${RG_VERSION}/${RG_TGZ}"; \
86+
echo "Downloading ${RG_TGZ_URL} ..."; \
87+
if curl -fsSL "${RG_TGZ_URL}" -o "${RG_TGZ}"; then \
88+
if file "${RG_TGZ}" | grep -q 'gzip compressed'; then \
89+
tar -zxf "${RG_TGZ}" --no-same-owner; \
90+
install -m 0755 "ripgrep-${RG_VERSION}-${RG_ARCH}/rg" /usr/local/bin/rg; \
91+
mkdir -p /usr/local/share/man/man1; \
92+
install -m 0644 "ripgrep-${RG_VERSION}-${RG_ARCH}/doc/rg.1" /usr/local/share/man/man1/; \
9093
else \
91-
echo "ripgrep binary not found for ${TARGETARCH}, skipping installation."; \
92-
fi && \
93-
cd - && rm -rf "${TEMP_DIR}"; \
94-
fi
94+
echo "Downloaded ripgrep archive invalid — skipping."; \
95+
fi; \
96+
else \
97+
echo "ripgrep binary not found for ${TARGETARCH}, skipping installation."; \
98+
fi; \
99+
cd - >/dev/null; \
100+
rm -rf "${TEMP_DIR}"
95101

96102
# Download and install bat depending on the architecture.
97103
# See release page for details https://github.com/sharkdp/bat/releases/tag/v0.18.3
98-
RUN \
99-
if [ "$TARGETARCH" = "ppc64le" ]; then \
100-
echo "Skipping bat installation for ppc64le as binary not available"; \
101-
else \
102-
TEMP_DIR="$(mktemp -d)" && cd "${TEMP_DIR}" && \
103-
BAT_VERSION="0.18.3" && \
104-
if [ "$TARGETARCH" = "arm64" ]; then \
105-
BAT_ARCH="aarch64-unknown-linux-gnu"; \
106-
else \
107-
BAT_ARCH="x86_64-unknown-linux-musl"; \
108-
fi && \
109-
BAT_TGZ="bat-v${BAT_VERSION}-${BAT_ARCH}.tar.gz" && \
110-
BAT_TGZ_URL="https://github.com/sharkdp/bat/releases/download/v${BAT_VERSION}/${BAT_TGZ}" && \
111-
echo "Downloading ${BAT_TGZ_URL}..." && \
112-
if curl -fsSL "${BAT_TGZ_URL}" -o "${BAT_TGZ}"; then \
113-
if file "${BAT_TGZ}" | grep -q 'gzip compressed'; then \
114-
tar -zxv --no-same-owner -f "${BAT_TGZ}" && \
115-
mv "bat-v${BAT_VERSION}-${BAT_ARCH}"/bat /usr/local/bin/ && \
116-
mv "bat-v${BAT_VERSION}-${BAT_ARCH}"/bat.1 /usr/local/share/man/man1; \
117-
else \
118-
echo "Downloaded bat archive invalid — skipping."; \
119-
fi; \
104+
RUN set -e; \
105+
case "$TARGETARCH" in \
106+
ppc64le) \
107+
echo "Skipping bat installation for ppc64le as binary not available"; \
108+
exit 0 ;; \
109+
arm64) \
110+
BAT_ARCH="aarch64-unknown-linux-gnu" ;; \
111+
amd64) \
112+
BAT_ARCH="x86_64-unknown-linux-musl" ;; \
113+
*) \
114+
echo "Unsupported architecture for bat: $TARGETARCH"; \
115+
exit 0 ;; \
116+
esac; \
117+
TEMP_DIR="$(mktemp -d)"; \
118+
cd "${TEMP_DIR}"; \
119+
BAT_VERSION="0.18.3"; \
120+
BAT_TGZ="bat-v${BAT_VERSION}-${BAT_ARCH}.tar.gz"; \
121+
BAT_TGZ_URL="https://github.com/sharkdp/bat/releases/download/v${BAT_VERSION}/${BAT_TGZ}"; \
122+
echo "Downloading ${BAT_TGZ_URL} ..."; \
123+
if curl -fsSL "${BAT_TGZ_URL}" -o "${BAT_TGZ}"; then \
124+
if file "${BAT_TGZ}" | grep -q 'gzip compressed'; then \
125+
tar -zxf "${BAT_TGZ}" --no-same-owner; \
126+
install -m 0755 "bat-v${BAT_VERSION}-${BAT_ARCH}/bat" /usr/local/bin/bat; \
127+
mkdir -p /usr/local/share/man/man1; \
128+
install -m 0644 "bat-v${BAT_VERSION}-${BAT_ARCH}/bat.1" /usr/local/share/man/man1/; \
120129
else \
121-
echo "bat binary not found for ${TARGETARCH}, skipping installation."; \
122-
fi && \
123-
cd - && rm -rf "${TEMP_DIR}"; \
124-
fi
130+
echo "Downloaded bat archive invalid — skipping."; \
131+
fi; \
132+
else \
133+
echo "bat binary not found for ${TARGETARCH}, skipping installation."; \
134+
fi; \
135+
cd - >/dev/null; \
136+
rm -rf "${TEMP_DIR}"
125137

126138
# Download and install fd depending on the architecture.
127139
# See release page for details https://github.com/sharkdp/fd/releases/tag/v8.7.0
128-
RUN \
129-
if [ "$TARGETARCH" = "ppc64le" ]; then \
130-
echo "Skipping fd installation for ppc64le as binary not available"; \
131-
else \
132-
TEMP_DIR="$(mktemp -d)" && cd "${TEMP_DIR}" && \
133-
FD_VERSION="8.7.0" && \
134-
if [ "$TARGETARCH" = "arm64" ]; then \
135-
FD_ARCH="aarch64-unknown-linux-gnu"; \
136-
else \
137-
FD_ARCH="x86_64-unknown-linux-musl"; \
138-
fi && \
139-
FD_TGZ="fd-v${FD_VERSION}-${FD_ARCH}.tar.gz" && \
140-
FD_TGZ_URL="https://github.com/sharkdp/fd/releases/download/v${FD_VERSION}/${FD_TGZ}" && \
141-
echo "Downloading ${FD_TGZ_URL}..." && \
142-
if curl -fsSL "${FD_TGZ_URL}" -o "${FD_TGZ}"; then \
143-
if file "${FD_TGZ}" | grep -q 'gzip compressed'; then \
144-
tar -xv --no-same-owner -f "${FD_TGZ}" && \
145-
mv "fd-v${FD_VERSION}-${FD_ARCH}"/fd /usr/local/bin/ && \
146-
mv "fd-v${FD_VERSION}-${FD_ARCH}"/fd.1 /usr/local/share/man/man1; \
147-
else \
148-
echo "Downloaded fd archive invalid — skipping."; \
149-
fi; \
140+
RUN set -e; \
141+
case "$TARGETARCH" in \
142+
ppc64le) \
143+
echo "Skipping fd installation for ppc64le as binary not available"; \
144+
exit 0 ;; \
145+
arm64) \
146+
FD_ARCH="aarch64-unknown-linux-gnu" ;; \
147+
amd64) \
148+
FD_ARCH="x86_64-unknown-linux-musl" ;; \
149+
*) \
150+
echo "Unsupported architecture for fd: $TARGETARCH"; \
151+
exit 0 ;; \
152+
esac; \
153+
TEMP_DIR="$(mktemp -d)"; \
154+
cd "${TEMP_DIR}"; \
155+
FD_VERSION="8.7.0"; \
156+
FD_TGZ="fd-v${FD_VERSION}-${FD_ARCH}.tar.gz"; \
157+
FD_TGZ_URL="https://github.com/sharkdp/fd/releases/download/v${FD_VERSION}/${FD_TGZ}"; \
158+
echo "Downloading ${FD_TGZ_URL} ..."; \
159+
if curl -fsSL "${FD_TGZ_URL}" -o "${FD_TGZ}"; then \
160+
if file "${FD_TGZ}" | grep -q 'gzip compressed'; then \
161+
tar -xf "${FD_TGZ}" --no-same-owner; \
162+
install -m 0755 "fd-v${FD_VERSION}-${FD_ARCH}/fd" /usr/local/bin/fd; \
163+
mkdir -p /usr/local/share/man/man1; \
164+
install -m 0644 "fd-v${FD_VERSION}-${FD_ARCH}/fd.1" /usr/local/share/man/man1/; \
150165
else \
151-
echo "fd binary not found for ${TARGETARCH}, skipping installation."; \
152-
fi && \
153-
cd - && rm -rf "${TEMP_DIR}"; \
154-
fi
166+
echo "Downloaded fd archive invalid — skipping."; \
167+
fi; \
168+
else \
169+
echo "fd binary not found for ${TARGETARCH}, skipping installation."; \
170+
fi; \
171+
cd - >/dev/null; \
172+
rm -rf "${TEMP_DIR}"
155173

156174
# Define user directory for binaries
157175
ENV PATH="/home/user/.local/bin:$PATH"
@@ -177,26 +195,34 @@ RUN mkdir -p /var/lib/shared/overlay-images /var/lib/shared/overlay-layers; \
177195
# See release page for details https://github.com/joyrex2001/kubedock/releases/tag/0.18.2
178196
ENV KUBEDOCK_VERSION=0.18.2
179197
ENV KUBECONFIG=/home/user/.kube/config
180-
RUN \
181-
if [ "$TARGETARCH" = "ppc64le" ]; then \
182-
echo "Skipping kubedock installation for ppc64le as binary not available"; \
183-
else \
184-
KUBEDOCK_ARCH="linux_${TARGETARCH}" && \
185-
KUBEDOCK_URL="https://github.com/joyrex2001/kubedock/releases/download/${KUBEDOCK_VERSION}/kubedock_${KUBEDOCK_VERSION}_${KUBEDOCK_ARCH}.tar.gz"; \
186-
echo "Downloading ${KUBEDOCK_URL}..."; \
187-
if curl -fsSL "${KUBEDOCK_URL}" -o /tmp/kubedock.tar.gz; then \
188-
if file /tmp/kubedock.tar.gz | grep -q 'gzip compressed'; then \
189-
tar -C /usr/local/bin -xz --no-same-owner -f /tmp/kubedock.tar.gz && \
190-
chmod +x /usr/local/bin/kubedock && \
191-
echo "Kubedock installed successfully."; \
192-
else \
193-
echo "Downloaded kubedock file invalid — skipping extraction."; \
194-
fi; \
198+
RUN set -e; \
199+
case "$TARGETARCH" in \
200+
ppc64le) \
201+
echo "Skipping kubedock installation for ppc64le as binary not available"; \
202+
exit 0 ;; \
203+
amd64) \
204+
KUBEDOCK_ARCH="linux_amd64" ;; \
205+
arm64) \
206+
KUBEDOCK_ARCH="linux_arm64" ;; \
207+
*) \
208+
echo "Unsupported architecture for kubedock: $TARGETARCH"; \
209+
exit 0 ;; \
210+
esac; \
211+
KUBEDOCK_TGZ="kubedock_${KUBEDOCK_VERSION}_${KUBEDOCK_ARCH}.tar.gz"; \
212+
KUBEDOCK_URL="https://github.com/joyrex2001/kubedock/releases/download/${KUBEDOCK_VERSION}/${KUBEDOCK_TGZ}"; \
213+
echo "Downloading ${KUBEDOCK_URL} ..."; \
214+
if curl -fsSL "${KUBEDOCK_URL}" -o /tmp/kubedock.tar.gz; then \
215+
if file /tmp/kubedock.tar.gz | grep -q 'gzip compressed'; then \
216+
tar -C /usr/local/bin -xzf /tmp/kubedock.tar.gz --no-same-owner; \
217+
chmod 0755 /usr/local/bin/kubedock; \
218+
echo "kubedock installed successfully."; \
195219
else \
196-
echo "Kubedock binary not found for ${TARGETARCH}, skipping installation."; \
220+
echo "Downloaded kubedock file invalid — skipping extraction."; \
197221
fi; \
198-
rm -f /tmp/kubedock.tar.gz; \
199-
fi
222+
else \
223+
echo "kubedock binary not found for ${TARGETARCH}, skipping installation."; \
224+
fi; \
225+
rm -f /tmp/kubedock.tar.gz
200226
COPY --chown=0:0 kubedock_setup.sh /usr/local/bin/kubedock_setup
201227

202228
# Configure Podman wrapper

0 commit comments

Comments
 (0)