spc-gnu-docker 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. # This file is using docker to run commands
  3. set -e
  4. # Detect docker can run
  5. if ! which docker >/dev/null; then
  6. echo "Docker is not installed, please install docker first !"
  7. exit 1
  8. fi
  9. DOCKER_EXECUTABLE="docker"
  10. # shellcheck disable=SC2046
  11. if [ $(id -u) -ne 0 ]; then
  12. if ! docker info > /dev/null 2>&1; then
  13. if [ "$SPC_USE_SUDO" != "yes" ]; then
  14. echo "Docker command requires sudo"
  15. # shellcheck disable=SC2039
  16. echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again'
  17. exit 1
  18. fi
  19. DOCKER_EXECUTABLE="sudo docker"
  20. fi
  21. fi
  22. # to check if qemu-docker run
  23. if [ "$SPC_USE_ARCH" = "" ]; then
  24. SPC_USE_ARCH=current
  25. fi
  26. case $SPC_USE_ARCH in
  27. current)
  28. BASE_ARCH=$(uname -m)
  29. if [ "$BASE_ARCH" = "arm64" ]; then
  30. BASE_ARCH=aarch64
  31. fi
  32. ;;
  33. aarch64)
  34. BASE_ARCH=aarch64
  35. # shellcheck disable=SC2039
  36. echo -e "\e[033m* Using different arch needs to setup qemu-static for docker !\e[0m"
  37. $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null
  38. ;;
  39. *)
  40. echo "Current arch is not supported to run in docker: $SPC_USE_ARCH"
  41. exit 1
  42. ;;
  43. esac
  44. # Detect docker env is setup
  45. if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-gnu-$SPC_USE_ARCH; then
  46. echo "Docker container does not exist. Building docker image ..."
  47. $DOCKER_EXECUTABLE build -t cwcc-spc-gnu-$SPC_USE_ARCH -f- . <<EOF
  48. FROM centos:7
  49. RUN sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo && \
  50. sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \
  51. sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
  52. RUN yum clean all && \
  53. yum makecache && \
  54. yum update -y
  55. 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 && \
  56. mkdir /cmake && \
  57. tar -xzf cmake.tgz -C /cmake --strip-components 1
  58. WORKDIR /app
  59. ADD ./src /app/src
  60. COPY ./composer.* /app/
  61. ADD ./bin/setup-runtime /app/bin/setup-runtime
  62. ADD ./bin/spc /app/bin/spc
  63. RUN /app/bin/setup-runtime
  64. RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative
  65. ENV PATH="/app/bin:/cmake/bin:$PATH"
  66. ENV SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
  67. ADD ./config/env.ini /app/config/env.ini
  68. RUN bin/spc doctor --auto-fix --debug
  69. EOF
  70. fi
  71. # Check if in ci (local terminal can execute with -it)
  72. if [ -t 0 ]; then
  73. INTERACT=-it
  74. else
  75. INTERACT=''
  76. fi
  77. # Mounting volumes
  78. MOUNT_LIST=""
  79. # shellcheck disable=SC2089
  80. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config"
  81. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src"
  82. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot"
  83. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source"
  84. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
  85. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
  86. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
  87. # Run docker
  88. # shellcheck disable=SC2068
  89. # shellcheck disable=SC2086
  90. # shellcheck disable=SC2090
  91. $DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@