spc-alpine-docker 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env sh
  2. # This file is using docker to run commands
  3. # Detect docker can run
  4. if ! which docker >/dev/null; then
  5. echo "Docker is not installed, please install docker first !"
  6. exit 1
  7. fi
  8. DOCKER_EXECUTABLE="docker"
  9. # shellcheck disable=SC2046
  10. if [ $(id -u) -ne 0 ]; then
  11. if ! docker info > /dev/null 2>&1; then
  12. if [ "$SPC_USE_SUDO" != "yes" ]; then
  13. echo "Docker command requires sudo"
  14. # shellcheck disable=SC2039
  15. echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again'
  16. exit 1
  17. fi
  18. DOCKER_EXECUTABLE="sudo docker"
  19. fi
  20. fi
  21. # to check if qemu-docker run
  22. if [ "$SPC_USE_ARCH" = "" ]; then
  23. SPC_USE_ARCH=x86_64
  24. fi
  25. case $SPC_USE_ARCH in
  26. x86_64)
  27. ALPINE_FROM=alpine:edge
  28. ;;
  29. aarch64)
  30. ALPINE_FROM=multiarch/alpine:aarch64-edge
  31. # shellcheck disable=SC2039
  32. echo -e "\e[033m* Using different arch needs to setup qemu-static for docker !\e[0m"
  33. $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null
  34. ;;
  35. *)
  36. echo "Current arch is not supported to run in docker: $SPC_USE_ARCH"
  37. exit 1
  38. ;;
  39. esac
  40. if [ "$SPC_USE_MIRROR" = "yes" ]; then
  41. SPC_USE_MIRROR="RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories"
  42. else
  43. SPC_USE_MIRROR="RUN echo 'Using original repo'"
  44. fi
  45. # Detect docker env is setup
  46. if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH; then
  47. echo "Docker container does not exist. Building docker image ..."
  48. $DOCKER_EXECUTABLE build -t cwcc-spc-$SPC_USE_ARCH -f- . <<EOF
  49. FROM $ALPINE_FROM
  50. $SPC_USE_MIRROR
  51. RUN apk update; \
  52. apk add --no-cache \
  53. autoconf \
  54. automake \
  55. gettext \
  56. bash \
  57. binutils \
  58. bison \
  59. build-base \
  60. cmake \
  61. curl \
  62. file \
  63. flex \
  64. g++ \
  65. gcc \
  66. git \
  67. jq \
  68. libgcc \
  69. libtool \
  70. libstdc++ \
  71. linux-headers \
  72. m4 \
  73. make \
  74. php82 \
  75. php82-common \
  76. php82-pcntl \
  77. php82-phar \
  78. php82-posix \
  79. php82-sodium \
  80. php82-tokenizer \
  81. php82-dom \
  82. php82-xml \
  83. php82-xmlwriter \
  84. composer \
  85. pkgconfig \
  86. wget \
  87. xz
  88. WORKDIR /app
  89. ADD ./src /app/src
  90. COPY ./composer.* /app/
  91. ADD ./bin /app/bin
  92. RUN composer install --no-dev --classmap-authoritative
  93. EOF
  94. fi
  95. # Check if in ci (local terminal can execute with -it)
  96. if [ -t 0 ]; then
  97. INTERACT=-it
  98. else
  99. INTERACT=''
  100. fi
  101. # Run docker
  102. # shellcheck disable=SC2068
  103. $DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" -v "$(pwd)"/config:/app/config -v "$(pwd)"/src:/app/src -v "$(pwd)"/buildroot:/app/buildroot -v "$(pwd)"/source:/app/source -v "$(pwd)"/downloads:/app/downloads cwcc-spc-$SPC_USE_ARCH bin/spc $@