spc-alpine-docker 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 upgrade -a; \
  53. apk add --no-cache \
  54. autoconf \
  55. automake \
  56. gettext \
  57. bash \
  58. binutils \
  59. bison \
  60. build-base \
  61. cmake \
  62. curl \
  63. file \
  64. flex \
  65. g++ \
  66. gcc \
  67. git \
  68. jq \
  69. libgcc \
  70. libtool \
  71. libstdc++ \
  72. linux-headers \
  73. m4 \
  74. make \
  75. php82 \
  76. php82-common \
  77. php82-pcntl \
  78. php82-phar \
  79. php82-posix \
  80. php82-sodium \
  81. php82-tokenizer \
  82. php82-dom \
  83. php82-xml \
  84. php82-xmlwriter \
  85. composer \
  86. pkgconfig \
  87. wget \
  88. xz
  89. WORKDIR /app
  90. ADD ./src /app/src
  91. COPY ./composer.* /app/
  92. ADD ./bin /app/bin
  93. RUN composer install --no-dev --classmap-authoritative
  94. EOF
  95. fi
  96. # Check if in ci (local terminal can execute with -it)
  97. if [ -t 0 ]; then
  98. INTERACT=-it
  99. else
  100. INTERACT=''
  101. fi
  102. # Mounting volumes
  103. MOUNT_LIST=""
  104. # shellcheck disable=SC2089
  105. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config"
  106. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src"
  107. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot"
  108. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source"
  109. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
  110. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
  111. MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
  112. # Run docker
  113. # shellcheck disable=SC2068
  114. # shellcheck disable=SC2086
  115. # shellcheck disable=SC2090
  116. $DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH bin/spc $@