1
1
#! /usr/bin/env bash
2
2
3
+ set -e
4
+
5
+ # This file is using docker to run commands
6
+ SPC_DOCKER_VERSION=v4
7
+
3
8
# Detect docker can run
4
9
if ! which docker > /dev/null; then
5
10
echo " Docker is not installed, please install docker first !"
@@ -19,35 +24,47 @@ if [ $(id -u) -ne 0 ]; then
19
24
fi
20
25
fi
21
26
22
-
23
-
24
- # to check if qemu-docker run
25
- if [ " $SPC_USE_ARCH " = " " ]; then
26
- SPC_USE_ARCH=current
27
+ # Convert uname to gnu arch
28
+ CURRENT_ARCH=$( uname -m)
29
+ if [ " $CURRENT_ARCH " = " arm64" ]; then
30
+ CURRENT_ARCH=aarch64
27
31
fi
32
+ if [ -z " $SPC_USE_ARCH " ]; then
33
+ SPC_USE_ARCH=$CURRENT_ARCH
34
+ fi
35
+ # parse SPC_USE_ARCH
28
36
case $SPC_USE_ARCH in
29
- current)
30
- BASE_ARCH=$( uname -m)
31
- if [ " $BASE_ARCH " = " arm64" ]; then
32
- BASE_ARCH=aarch64
37
+ x86_64|amd64)
38
+ SPC_USE_ARCH=x86_64
39
+ SPC_USE_ARCH_DOCKER=amd64
40
+ if [ " $CURRENT_ARCH " != " x86_64" ]; then
41
+ PLATFORM_ARG=" --platform linux/amd64"
33
42
fi
34
43
;;
35
- aarch64)
36
- BASE_ARCH=aarch64
37
- # shellcheck disable=SC2039
38
- echo -e " \e[033m* Using different arch needs to setup qemu-static for docker !\e[0m"
39
- $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null
44
+ aarch64|arm64)
45
+ SPC_USE_ARCH=aarch64
46
+ SPC_USE_ARCH_DOCKER=arm64
47
+ if [ " $CURRENT_ARCH " != " aarch64" ]; then
48
+ PLATFORM_ARG=" --platform linux/arm64"
49
+ fi
40
50
;;
41
51
* )
42
52
echo " Current arch is not supported to run in docker: $SPC_USE_ARCH "
43
53
exit 1
44
54
;;
45
55
esac
56
+ # detect if we need to use qemu-static
57
+ if [ " $SPC_USE_ARCH " != " $CURRENT_ARCH " ]; then
58
+ if [ " $( uname -s) " = " Linux" ]; then
59
+ echo " * Using different arch needs to setup qemu-static for docker !"
60
+ $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static --reset -p yes > /dev/null
61
+ fi
62
+ fi
46
63
47
64
# Detect docker env is setup
48
- if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-gnu-$SPC_USE_ARCH ; then
65
+ if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-gnu-$SPC_USE_ARCH - $SPC_DOCKER_VERSION ; then
49
66
echo " Docker container does not exist. Building docker image ..."
50
- $DOCKER_EXECUTABLE build - t cwcc-spc-gnu-$SPC_USE_ARCH -f- . << EOF
67
+ $DOCKER_EXECUTABLE buildx build $PLATFORM_ARG --no-cache - t cwcc-spc-gnu-$SPC_USE_ARCH - $SPC_DOCKER_VERSION -f- . << EOF
51
68
FROM centos:7
52
69
RUN sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo && \
53
70
sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \
@@ -59,7 +76,7 @@ RUN yum clean all && \
59
76
60
77
RUN yum install -y centos-release-scl
61
78
62
- RUN if [ "$BASE_ARCH " = "aarch64" ]; then \
79
+ RUN if [ "$SPC_USE_ARCH " = "aarch64" ]; then \
63
80
sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo ; \
64
81
sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl.repo ; \
65
82
else \
@@ -74,12 +91,12 @@ RUN echo "source scl_source enable devtoolset-10" >> /etc/bashrc
74
91
RUN source /etc/bashrc
75
92
RUN yum install -y which
76
93
77
- RUN curl -fsSL -o patchelf.tgz https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-$BASE_ARCH .tar.gz && \
94
+ RUN curl -fsSL -o patchelf.tgz https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-$SPC_USE_ARCH .tar.gz && \
78
95
mkdir -p /patchelf && \
79
96
tar -xzf patchelf.tgz -C /patchelf --strip-components=1 && \
80
97
cp /patchelf/bin/patchelf /usr/bin/
81
98
82
- RUN curl -o cmake.tgz -fsSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$BASE_ARCH .tar.gz && \
99
+ RUN curl -o cmake.tgz -fsSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$SPC_USE_ARCH .tar.gz && \
83
100
mkdir /cmake && \
84
101
tar -xzf cmake.tgz -C /cmake --strip-components 1
85
102
@@ -173,7 +190,7 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
173
190
echo " * ./pkgroot: $( pwd) /pkgroot"
174
191
echo " *"
175
192
set -ex
176
- $DOCKER_EXECUTABLE run -- rm -it --privileged $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH
193
+ $DOCKER_EXECUTABLE run $PLATFORM_ARG --privileged -- rm -it $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH - $SPC_DOCKER_VERSION /bin/bash
177
194
else
178
- $DOCKER_EXECUTABLE run --rm $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@
195
+ $DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH - $SPC_DOCKER_VERSION bin/spc $@
179
196
fi
0 commit comments