spc-alpine-docker 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env sh
  2. # This file is using docker to run commands
  3. self_dir=$(cd "$(dirname "$0")";pwd)
  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. 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. echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again'
  15. exit 1
  16. fi
  17. DOCKER_EXECUTABLE="sudo docker"
  18. fi
  19. fi
  20. # to check if qemu-docker run
  21. if [ "$SPC_USE_ARCH" = "" ]; then
  22. SPC_USE_ARCH=x86_64
  23. fi
  24. case $SPC_USE_ARCH in
  25. x86_64)
  26. ALPINE_FROM=alpine:edge
  27. ;;
  28. aarch64)
  29. ALPINE_FROM=multiarch/alpine:aarch64-edge
  30. echo -e "\e[033m* Using different arch needs to setup qemu-static for docker !\e[0m"
  31. $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null
  32. ;;
  33. *)
  34. echo "Current arch is not supported to run in docker: $SPC_USE_ARCH"
  35. exit 1
  36. ;;
  37. esac
  38. if [ "$SPC_USE_MIRROR" = "yes" ]; then
  39. SPC_USE_MIRROR="RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories"
  40. else
  41. SPC_USE_MIRROR="RUN echo 'Using original repo'"
  42. fi
  43. # Detect docker env is setup
  44. if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH; then
  45. echo "Docker container does not exist. Building docker image ..."
  46. ALPINE_DOCKERFILE=$(cat << EOF
  47. FROM $ALPINE_FROM
  48. $SPC_USE_MIRROR
  49. RUN apk update
  50. RUN apk add bash file wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils bison flex pkgconfig automake curl
  51. RUN apk add build-base xz php81 php81-common php81-pcntl php81-tokenizer php81-phar php81-posix php81-xml composer
  52. RUN mkdir /app
  53. WORKDIR /app
  54. ADD ./src /app/src
  55. ADD ./composer.json /app/composer.json
  56. ADD ./bin /app/bin
  57. RUN composer update --no-dev
  58. EOF
  59. )
  60. echo "$ALPINE_DOCKERFILE" > $(pwd)/Dockerfile
  61. $DOCKER_EXECUTABLE build -t cwcc-spc-$SPC_USE_ARCH .
  62. rm $(pwd)/Dockerfile
  63. fi
  64. # Check if in ci (local terminal can execute with -it)
  65. if [ -t 0 ]; then
  66. INTERACT=-it
  67. else
  68. INTERACT=''
  69. fi
  70. # Run docker
  71. $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 $@