|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This file is using docker to run commands |
| 4 | +set -e |
| 5 | + |
| 6 | +# Detect docker can run |
| 7 | +if ! which docker >/dev/null; then |
| 8 | + echo "Docker is not installed, please install docker first !" |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | +DOCKER_EXECUTABLE="docker" |
| 12 | +# shellcheck disable=SC2046 |
| 13 | +if [ $(id -u) -ne 0 ]; then |
| 14 | + if ! docker info > /dev/null 2>&1; then |
| 15 | + if [ "$SPC_USE_SUDO" != "yes" ]; then |
| 16 | + echo "Docker command requires sudo" |
| 17 | + # shellcheck disable=SC2039 |
| 18 | + echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again' |
| 19 | + exit 1 |
| 20 | + fi |
| 21 | + DOCKER_EXECUTABLE="sudo docker" |
| 22 | + fi |
| 23 | +fi |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +# to check if qemu-docker run |
| 28 | +if [ "$SPC_USE_ARCH" = "" ]; then |
| 29 | + SPC_USE_ARCH=current |
| 30 | +fi |
| 31 | +case $SPC_USE_ARCH in |
| 32 | +current) |
| 33 | + BASE_ARCH=$(uname -m) |
| 34 | + if [ "$BASE_ARCH" = "arm64" ]; then |
| 35 | + BASE_ARCH=aarch64 |
| 36 | + GO_ARCH=arm64 |
| 37 | + else |
| 38 | + GO_ARCH=amd64 |
| 39 | + fi |
| 40 | + ;; |
| 41 | +aarch64) |
| 42 | + BASE_ARCH=aarch64 |
| 43 | + GO_ARCH=arm64 |
| 44 | + # shellcheck disable=SC2039 |
| 45 | + echo -e "\e[033m* Using different arch needs to setup qemu-static for docker !\e[0m" |
| 46 | + $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null |
| 47 | + ;; |
| 48 | +*) |
| 49 | + echo "Current arch is not supported to run in docker: $SPC_USE_ARCH" |
| 50 | + exit 1 |
| 51 | + ;; |
| 52 | +esac |
| 53 | + |
| 54 | +# Detect docker env is setup |
| 55 | +if ! $DOCKER_EXECUTABLE images | grep -q cwcc-frankenphp-gnu-$SPC_USE_ARCH; then |
| 56 | + echo "Docker container does not exist. Building docker image ..." |
| 57 | + $DOCKER_EXECUTABLE build -t cwcc-frankenphp-gnu-$SPC_USE_ARCH -f- . <<EOF |
| 58 | +FROM centos:7 |
| 59 | +RUN sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo && \ |
| 60 | + sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \ |
| 61 | + sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo |
| 62 | +RUN yum clean all && \ |
| 63 | + yum makecache && \ |
| 64 | + yum update -y |
| 65 | +
|
| 66 | +RUN yum install -y centos-release-scl |
| 67 | +
|
| 68 | +RUN if [ "$BASE_ARCH" = "aarch64" ]; then \ |
| 69 | + sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo ; \ |
| 70 | + sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl.repo ; \ |
| 71 | + else \ |
| 72 | + sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo ; \ |
| 73 | + fi |
| 74 | +RUN sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \ |
| 75 | + sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo |
| 76 | +
|
| 77 | +RUN yum update -y && \ |
| 78 | + yum install -y devtoolset-10-gcc-* |
| 79 | +RUN echo "source scl_source enable devtoolset-10" >> /etc/bashrc |
| 80 | +RUN source /etc/bashrc |
| 81 | +
|
| 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 && \ |
| 83 | + mkdir /cmake && \ |
| 84 | + tar -xzf cmake.tgz -C /cmake --strip-components 1 |
| 85 | +
|
| 86 | +WORKDIR /app |
| 87 | +ADD ./src /app/src |
| 88 | +COPY ./composer.* /app/ |
| 89 | +ADD ./bin/setup-runtime /app/bin/setup-runtime |
| 90 | +ADD ./bin/spc /app/bin/spc |
| 91 | +RUN /app/bin/setup-runtime |
| 92 | +RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative |
| 93 | +ENV PATH="/app/bin:/cmake/bin:/usr/local/go/bin:$PATH" |
| 94 | +ENV SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed" |
| 95 | +
|
| 96 | +ADD ./config/env.ini /app/config/env.ini |
| 97 | +RUN bin/spc doctor --auto-fix --debug |
| 98 | +
|
| 99 | +RUN curl -o make.tgz -fsSL https://ftp.gnu.org/gnu/make/make-4.4.tar.gz && \ |
| 100 | + tar -zxvf make.tgz && \ |
| 101 | + cd make-4.4 && \ |
| 102 | + ./configure && \ |
| 103 | + make && \ |
| 104 | + make install && \ |
| 105 | + ln -sf /usr/local/bin/make /usr/bin/make |
| 106 | +
|
| 107 | +RUN git clone https://github.com/static-php/gnu-frankenphp --depth=1 /frankenphp |
| 108 | +WORKDIR /frankenphp |
| 109 | +
|
| 110 | +RUN curl -o go.tgz -fsSL https://go.dev/dl/go1.24.1.linux-$GO_ARCH.tar.gz && \ |
| 111 | + rm -rf /usr/local/go && tar -C /usr/local -xzf go.tgz |
| 112 | +EOF |
| 113 | +fi |
| 114 | + |
| 115 | +# Check if in ci (local terminal can execute with -it) |
| 116 | +if [ -t 0 ]; then |
| 117 | + INTERACT=-it |
| 118 | +else |
| 119 | + INTERACT='' |
| 120 | +fi |
| 121 | + |
| 122 | +# Mounting volumes |
| 123 | +MOUNT_LIST="" |
| 124 | +# shellcheck disable=SC2089 |
| 125 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config" |
| 126 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src" |
| 127 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot" |
| 128 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source" |
| 129 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist" |
| 130 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads" |
| 131 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot" |
| 132 | +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/frankenphp/dist" |
| 133 | + |
| 134 | +# Apply env in temp env file |
| 135 | +echo 'SPC_SKIP_DOCTOR_CHECK_ITEMS=if musl-wrapper is installed,if musl-cross-make is installed' > /tmp/spc-gnu-docker.env |
| 136 | +echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' >> /tmp/spc-gnu-docker.env |
| 137 | +echo 'CXX=/opt/rh/devtoolset-10/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env |
| 138 | +echo 'AR=/opt/rh/devtoolset-10/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env |
| 139 | +echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env |
| 140 | +echo 'SPC_DEFAULT_C_FLAGS=-fPIE' >> /tmp/spc-gnu-docker.env |
| 141 | +echo 'SPC_NO_MUSL_PATH=yes' >> /tmp/spc-gnu-docker.env |
| 142 | +echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env |
| 143 | +echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env |
| 144 | + |
| 145 | +# Run docker |
| 146 | +# shellcheck disable=SC2068 |
| 147 | +# shellcheck disable=SC2086 |
| 148 | +# shellcheck disable=SC2090 |
| 149 | + |
| 150 | +$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-frankenphp-gnu-$SPC_USE_ARCH ./build-static.sh |
0 commit comments