You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
9.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. # Set Environment Variables
  2. ENV DEBIAN_FRONTEND noninteractive
  3. # Start as root
  4. USER root
  5. ###########################################################################
  6. # Laradock non-root user:
  7. ###########################################################################
  8. # Add a non-root user to prevent files being created with root permissions on host machine.
  9. ARG PUID=1000
  10. ENV PUID ${PUID}
  11. ARG PGID=1000
  12. ENV PGID ${PGID}
  13. # always run apt update when start and after add new source list, then clean up at end.
  14. RUN set -xe; \
  15. apt-get update -yqq && \
  16. pecl channel-update pecl.php.net && \
  17. groupadd -g ${PGID} laradock && \
  18. useradd -u ${PUID} -g laradock -m laradock -G docker_env && \
  19. usermod -p "*" laradock -s /bin/bash && \
  20. apt-get install -yqq \
  21. apt-utils \
  22. #
  23. #--------------------------------------------------------------------------
  24. # Mandatory Software's Installation
  25. #--------------------------------------------------------------------------
  26. #
  27. # Mandatory Software's such as ("php-cli", "git", "vim", ....) are
  28. # installed on the base image 'laradock/workspace' image. If you want
  29. # to add more Software's or remove existing one, you need to edit the
  30. # base image (https://github.com/Laradock/workspace).
  31. #
  32. # next lines are here becase there is no auto build on dockerhub see https://github.com/laradock/laradock/pull/1903#issuecomment-463142846
  33. libzip-dev zip unzip \
  34. # Install the zip extension
  35. php${PHP_VERSION}-zip \
  36. # nasm
  37. nasm && \
  38. php -m | grep -q 'zip'
  39. #
  40. #--------------------------------------------------------------------------
  41. # Optional Software's Installation
  42. #--------------------------------------------------------------------------
  43. #
  44. # Optional Software's will only be installed if you set them to `true`
  45. # in the `docker-compose.yml` before the build.
  46. # Example:
  47. # - WORKSPACE_INSTALL_NODE=false
  48. # - ...
  49. #
  50. ###########################################################################
  51. # Set Timezone
  52. ###########################################################################
  53. ARG TZ=Europe/Moscow
  54. ENV TZ ${TZ}
  55. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  56. ###########################################################################
  57. # Root Aliases
  58. ###########################################################################
  59. USER root
  60. COPY ./aliases.sh /root/aliases.sh
  61. RUN sed -i 's/\r//' /root/aliases.sh && \
  62. echo "" >> ~/.bashrc && \
  63. echo "# Load Custom Aliases" >> ~/.bashrc && \
  64. echo "source ~/aliases.sh" >> ~/.bashrc && \
  65. echo "" >> ~/.bashrc \
  66. ###########################################################################
  67. # ssh:
  68. ###########################################################################
  69. USER root
  70. ARG INSTALL_SSH=false
  71. ENV INSTALL_SSH ${INSTALL_SSH}
  72. RUN if [ ${INSTALL_SSH} = true ]; then \
  73. rm -f /etc/service/sshd/down \
  74. ;fi
  75. USER laradock
  76. RUN if [ ${INSTALL_SSH} = true ]; then \
  77. mkdir -p ~/.ssh \
  78. && ln -s /run/secrets/user_ssh_key ~/.ssh/id_rsa \
  79. && ln -s /run/secrets/user_known_hosts ~/.ssh/known_hosts \
  80. ;fi
  81. ###########################################################################
  82. # MySQL Client:
  83. ###########################################################################
  84. USER root
  85. ARG INSTALL_MYSQL_CLIENT=false
  86. RUN if [ ${INSTALL_MYSQL_CLIENT} = true ]; then \
  87. apt-get update -yqq && \
  88. apt-get -y install mysql-client \
  89. ;fi
  90. ###########################################################################
  91. # fswatch
  92. ###########################################################################
  93. USER root
  94. ARG INSTALL_FSWATCH=false
  95. RUN if [ ${INSTALL_FSWATCH} = true ]; then \
  96. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 47FE03C1 \
  97. && add-apt-repository -y ppa:hadret/fswatch \
  98. || apt-get update -yqq \
  99. && apt-get -y install fswatch \
  100. ;fi
  101. ###########################################################################
  102. # ping:
  103. ###########################################################################
  104. USER root
  105. ARG INSTALL_PING=false
  106. RUN if [ ${INSTALL_PING} = true ]; then \
  107. apt-get update -yqq && \
  108. apt-get -y install inetutils-ping \
  109. ;fi
  110. ###########################################################################
  111. # Install S3 minio client:
  112. ###########################################################################
  113. USER root
  114. ARG INSTALL_S3_MINIO_CLIENT=false
  115. RUN if [ ${INSTALL_S3_MINIO_CLIENT} = true ]; then \
  116. curl https://dl.min.io/client/mc/release/linux-amd64/mc > /usr/local/sbin/mc \
  117. && chmod +x /usr/local/sbin/mc \
  118. ; fi
  119. ###########################################################################
  120. # xDebug:
  121. ###########################################################################
  122. RUN if [ $(php -r "echo PHP_MAJOR_VERSION;") = "5" ]; then \
  123. pecl install xdebug-2.5.5; \
  124. elif [ $(php -r "echo PHP_MAJOR_VERSION;") = "8" ]; then \
  125. if [ $(php -r "echo PHP_MINOR_VERSION;") = "1" ]; then \
  126. pecl install xdebug-3.1.6; \
  127. elif [ $(php -r "echo PHP_MINOR_VERSION;") = "2" ]; then \
  128. pecl install xdebug-3.3.1; \
  129. else \
  130. pecl install xdebug; \
  131. fi \
  132. else \
  133. pecl install xdebug-2.9.8; \
  134. fi && \
  135. echo ';zend_extension=xdebug.so' > /etc/php/${PHP_VERSION}/cli/conf.d/20-xdebug.ini && \
  136. echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/vendor/bin/phpunit'" >> ~/.bashrc
  137. ###########################################################################
  138. # BZ2:
  139. ###########################################################################
  140. ARG INSTALL_BZ2=false
  141. RUN if [ ${INSTALL_BZ2} = true ]; then \
  142. apt-get install -y php${PHP_VERSION}-bz2 \
  143. ;fi
  144. ###########################################################################
  145. # Non-root user : PHPUnit path
  146. ###########################################################################
  147. # add ./vendor/bin to non-root user's bashrc (needed for phpunit)
  148. USER laradock
  149. RUN echo "" >> ~/.bashrc && \
  150. echo 'export PATH="/var/www/vendor/bin:$PATH"' >> ~/.bashrc
  151. ###########################################################################
  152. # Check PHP version:
  153. ###########################################################################
  154. RUN set -xe; php -v | head -n 1 | grep -q "PHP ${PHP_VERSION}."
  155. ###########################################################################
  156. # WP CLI:
  157. ###########################################################################
  158. # The command line interface for WordPress
  159. USER root
  160. ARG INSTALL_WP_CLI=false
  161. RUN if [ ${INSTALL_WP_CLI} = true ]; then \
  162. curl -fsSL -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | bash && \
  163. chmod +x /usr/local/bin/wp \
  164. ;fi
  165. ###########################################################################
  166. # Node / NVM:
  167. ###########################################################################
  168. USER laradock
  169. ENV NVM_DIR /home/laradock/.nvm
  170. RUN mkdir -p $NVM_DIR && \
  171. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash \
  172. && . $NVM_DIR/nvm.sh
  173. # Wouldn't execute when added to the RUN statement in the above block
  174. # Source NVM when loading bash since ~/.profile isn't loaded on non-login shell
  175. RUN echo "" >> ~/.bashrc && \
  176. echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
  177. echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc
  178. # Add NVM binaries to root's .bashrc
  179. USER root
  180. RUN cp -R /home/laradock/.nvm /root/ && \
  181. chown -R root:root /root/.nvm && \
  182. echo "" >> ~/.bashrc && \
  183. echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
  184. echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc
  185. ###########################################################################
  186. # Tmux
  187. ###########################################################################
  188. USER root
  189. RUN apt-get update -yqq && apt-get install -y tmux
  190. COPY ./tmux.conf /etc/tmux.conf
  191. ###########################################################################
  192. # Remove DST_Root_CA3
  193. ###########################################################################
  194. USER root
  195. RUN sed -i 's/^mozilla\/DST_Root_CA_X3\.crt/!mozilla\/DST_Root_CA_X3.crt/g' /etc/ca-certificates.conf && update-ca-certificates
  196. ###########################################################################
  197. # Artisan bash autocompletion from symphony
  198. # @see https://wintercms.com/docs/v1.2/docs/console/introduction#autocompletion--suggested-input-values
  199. ###########################################################################
  200. RUN apt install bash-completion
  201. COPY /completion.sh /etc/bash_completion.d/artisan
  202. ###########################################################################
  203. # Tune opts:
  204. ###########################################################################
  205. ARG PHP_OPT_MAX_EXECUTION_TIME=600
  206. RUN sed -i "s/^max_execution_time = .*/max_execution_time = $PHP_OPT_MAX_EXECUTION_TIME/g" /etc/php/${PHP_VERSION}/cli/php.ini
  207. ARG PHP_OPT_MEMORY_LIMIT=256M
  208. RUN sed -i "s/^memory_limit = .*/memory_limit = $PHP_OPT_MEMORY_LIMIT/g" /etc/php/${PHP_VERSION}/cli/php.ini
  209. ARG PHP_OPT_POST_MAX_SIZE=48M
  210. RUN sed -i "s/^post_max_size = .*/post_max_size = $PHP_OPT_UPLOAD_MAX_FILESIZE/g" /etc/php/${PHP_VERSION}/cli/php.ini
  211. ARG PHP_OPT_UPLOAD_MAX_FILESIZE=16M
  212. RUN sed -i "s/^upload_max_filesize = .*/upload_max_filesize = $PHP_OPT_UPLOAD_MAX_FILESIZE/g" /etc/php/${PHP_VERSION}/cli/php.ini
  213. #
  214. #--------------------------------------------------------------------------
  215. # Final Touch
  216. #--------------------------------------------------------------------------
  217. #
  218. USER root
  219. # Clean up
  220. RUN apt-get clean && \
  221. rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
  222. rm /var/log/lastlog /var/log/faillog
  223. # Set default work directory
  224. WORKDIR /var/www