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.

458 lines
14 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #
  2. #--------------------------------------------------------------------------
  3. # Image Setup
  4. #--------------------------------------------------------------------------
  5. #
  6. # To edit the 'workspace' base Image, visit its repository on Github
  7. # https://github.com/Laradock/workspace
  8. #
  9. # To change its version, see the available Tags on the Docker Hub:
  10. # https://hub.docker.com/r/laradock/workspace/tags/
  11. #
  12. # Note: Base Image name format {image-tag}-{php-version}
  13. #
  14. LABEL maintainer="Mahmoud Zalt <mahmoud@zalt.me>"
  15. # Set Environment Variables
  16. ENV DEBIAN_FRONTEND noninteractive
  17. # Start as root
  18. USER root
  19. ###########################################################################
  20. # Laradock non-root user:
  21. ###########################################################################
  22. # Add a non-root user to prevent files being created with root permissions on host machine.
  23. ARG PUID=1000
  24. ENV PUID ${PUID}
  25. ARG PGID=1000
  26. ENV PGID ${PGID}
  27. # always run apt update when start and after add new source list, then clean up at end.
  28. RUN set -xe; \
  29. apt-get update -yqq && \
  30. pecl channel-update pecl.php.net && \
  31. groupadd -g ${PGID} laradock && \
  32. useradd -u ${PUID} -g laradock -m laradock -G docker_env && \
  33. usermod -p "*" laradock -s /bin/bash && \
  34. apt-get install -yqq \
  35. apt-utils \
  36. #
  37. #--------------------------------------------------------------------------
  38. # Mandatory Software's Installation
  39. #--------------------------------------------------------------------------
  40. #
  41. # Mandatory Software's such as ("php-cli", "git", "vim", ....) are
  42. # installed on the base image 'laradock/workspace' image. If you want
  43. # to add more Software's or remove existing one, you need to edit the
  44. # base image (https://github.com/Laradock/workspace).
  45. #
  46. # next lines are here becase there is no auto build on dockerhub see https://github.com/laradock/laradock/pull/1903#issuecomment-463142846
  47. libzip-dev zip unzip \
  48. # Install the zip extension
  49. php${PHP_VERSION}-zip \
  50. # nasm
  51. nasm && \
  52. php -m | grep -q 'zip'
  53. #
  54. #--------------------------------------------------------------------------
  55. # Optional Software's Installation
  56. #--------------------------------------------------------------------------
  57. #
  58. # Optional Software's will only be installed if you set them to `true`
  59. # in the `docker-compose.yml` before the build.
  60. # Example:
  61. # - WORKSPACE_INSTALL_NODE=false
  62. # - ...
  63. #
  64. ###########################################################################
  65. # Set Timezone
  66. ###########################################################################
  67. ARG TZ=Europe/Moscow
  68. ENV TZ ${TZ}
  69. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  70. ###########################################################################
  71. # User Aliases
  72. ###########################################################################
  73. USER root
  74. COPY ./aliases.sh /root/aliases.sh
  75. COPY ./aliases.sh /home/laradock/aliases.sh
  76. RUN sed -i 's/\r//' /root/aliases.sh && \
  77. sed -i 's/\r//' /home/laradock/aliases.sh && \
  78. chown laradock:laradock /home/laradock/aliases.sh && \
  79. echo "" >> ~/.bashrc && \
  80. echo "# Load Custom Aliases" >> ~/.bashrc && \
  81. echo "source ~/aliases.sh" >> ~/.bashrc && \
  82. echo "" >> ~/.bashrc
  83. USER laradock
  84. RUN echo "" >> ~/.bashrc && \
  85. echo "# Load Custom Aliases" >> ~/.bashrc && \
  86. echo "source ~/aliases.sh" >> ~/.bashrc && \
  87. echo "" >> ~/.bashrc
  88. ###########################################################################
  89. # ssh:
  90. ###########################################################################
  91. USER root
  92. ARG INSTALL_SSH=false
  93. ENV INSTALL_SSH ${INSTALL_SSH}
  94. RUN if [ ${INSTALL_SSH} = true ]; then \
  95. rm -f /etc/service/sshd/down \
  96. ;fi
  97. USER laradock
  98. RUN if [ ${INSTALL_SSH} = true ]; then \
  99. mkdir -p ~/.ssh \
  100. && ln -s /run/secrets/user_ssh_key ~/.ssh/id_rsa \
  101. && ln -s /run/secrets/user_known_hosts ~/.ssh/known_hosts \
  102. ;fi
  103. ###########################################################################
  104. # MySQL Client:
  105. ###########################################################################
  106. USER root
  107. ARG INSTALL_MYSQL_CLIENT=false
  108. RUN if [ ${INSTALL_MYSQL_CLIENT} = true ]; then \
  109. apt-get update -yqq && \
  110. apt-get -y install mysql-client \
  111. ;fi
  112. ###########################################################################
  113. # PYTHON:
  114. ###########################################################################
  115. USER root
  116. ARG INSTALL_PYTHON=false
  117. RUN if [ ${INSTALL_PYTHON} = true ]; then \
  118. apt-get update && apt-get -y install python python-pip python-dev build-essential \
  119. && python -m pip install --upgrade "pip < 21.0" \
  120. && python -m pip install --upgrade virtualenv \
  121. ;fi
  122. ###########################################################################
  123. # fswatch
  124. ###########################################################################
  125. USER root
  126. ARG INSTALL_FSWATCH=false
  127. RUN if [ ${INSTALL_FSWATCH} = true ]; then \
  128. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 47FE03C1 \
  129. && add-apt-repository -y ppa:hadret/fswatch \
  130. || apt-get update -yqq \
  131. && apt-get -y install fswatch \
  132. ;fi
  133. ###########################################################################
  134. # ping:
  135. ###########################################################################
  136. USER root
  137. ARG INSTALL_PING=false
  138. RUN if [ ${INSTALL_PING} = true ]; then \
  139. apt-get update -yqq && \
  140. apt-get -y install inetutils-ping \
  141. ;fi
  142. ###########################################################################
  143. # Install S3 minio client:
  144. ###########################################################################
  145. USER root
  146. ARG INSTALL_S3_MINIO_CLIENT=false
  147. RUN if [ ${INSTALL_S3_MINIO_CLIENT} = true ]; then \
  148. curl https://dl.min.io/client/mc/release/linux-amd64/mc > /usr/local/sbin/mc \
  149. && chmod +x /usr/local/sbin/mc \
  150. ; fi
  151. ###########################################################################
  152. # Composer:
  153. ###########################################################################
  154. USER root
  155. # Add the composer.json
  156. COPY ./composer.json /home/laradock/.composer/composer.json
  157. # Make sure that ~/.composer belongs to laradock
  158. RUN chown -R laradock:laradock /home/laradock/.composer
  159. RUN ln -s /run/secrets/composer_auth /home/laradock/.composer/auth.json
  160. # Export composer vendor path
  161. RUN echo "" >> ~/.bashrc && \
  162. echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
  163. # Update composer
  164. ARG COMPOSER_VERSION=2
  165. ENV COMPOSER_VERSION ${COMPOSER_VERSION}
  166. RUN composer self-update --${COMPOSER_VERSION}
  167. USER laradock
  168. # Check if global install need to be ran
  169. ARG COMPOSER_GLOBAL_INSTALL=false
  170. ENV COMPOSER_GLOBAL_INSTALL ${COMPOSER_GLOBAL_INSTALL}
  171. RUN if [ ${COMPOSER_GLOBAL_INSTALL} = true ]; then \
  172. # run the install
  173. composer global install \
  174. ;fi
  175. ARG COMPOSER_REPO_PACKAGIST
  176. ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
  177. RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
  178. composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
  179. ;fi
  180. # Export composer vendor path
  181. RUN echo "" >> ~/.bashrc && \
  182. echo 'export PATH="~/.composer/vendor/bin:$PATH"' >> ~/.bashrc
  183. ###########################################################################
  184. # Non-root user : PHPUnit path
  185. ###########################################################################
  186. # add ./vendor/bin to non-root user's bashrc (needed for phpunit)
  187. USER laradock
  188. RUN echo "" >> ~/.bashrc && \
  189. echo 'export PATH="/var/www/vendor/bin:$PATH"' >> ~/.bashrc
  190. ###########################################################################
  191. # Check PHP version:
  192. ###########################################################################
  193. RUN set -xe; php -v | head -n 1 | grep -q "PHP ${PHP_VERSION}."
  194. ###########################################################################
  195. # xDebug:
  196. ###########################################################################
  197. USER root
  198. ARG INSTALL_XDEBUG=false
  199. RUN if [ ${INSTALL_XDEBUG} = true ]; then \
  200. # Load the xdebug extension only with phpunit commands
  201. apt-get install -y php${PHP_VERSION}-xdebug && \
  202. sed -i 's/^;//g' /etc/php/${PHP_VERSION}/cli/conf.d/20-xdebug.ini && \
  203. echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/vendor/bin/phpunit'" >> ~/.bashrc \
  204. ;fi
  205. # ADD for REMOTE debugging
  206. COPY ./xdebug.ini /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini
  207. RUN sed -i "s/xdebug.remote_autostart=0/xdebug.remote_autostart=1/" /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini && \
  208. sed -i "s/xdebug.remote_enable=0/xdebug.remote_enable=1/" /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini && \
  209. sed -i "s/xdebug.cli_color=0/xdebug.cli_color=1/" /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini
  210. ###########################################################################
  211. # WP CLI:
  212. ###########################################################################
  213. # The command line interface for WordPress
  214. USER root
  215. ARG INSTALL_WP_CLI=false
  216. RUN if [ ${INSTALL_WP_CLI} = true ]; then \
  217. curl -fsSL -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | bash && \
  218. chmod +x /usr/local/bin/wp \
  219. ;fi
  220. ###########################################################################
  221. # Node / NVM:
  222. ###########################################################################
  223. USER laradock
  224. # Check if NVM needs to be installed
  225. ARG INSTALL_NODE=false
  226. ENV INSTALL_NODE ${INSTALL_NODE}
  227. ARG NODE_VERSION=node
  228. ENV NODE_VERSION ${NODE_VERSION}
  229. ARG INSTALL_NPM_GULP=false
  230. ARG INSTALL_NPM_BOWER=false
  231. ARG INSTALL_NPM_VUE_CLI=false
  232. ARG INSTALL_NPM_ANGULAR_CLI=false
  233. ARG NPM_REGISTRY
  234. ENV NPM_REGISTRY ${NPM_REGISTRY}
  235. ENV NVM_DIR /home/laradock/.nvm
  236. RUN if [ ${INSTALL_NODE} = true ]; then \
  237. # Install nvm (A Node Version Manager)
  238. mkdir -p $NVM_DIR && \
  239. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash \
  240. && . $NVM_DIR/nvm.sh \
  241. && nvm install ${NODE_VERSION} \
  242. && nvm use ${NODE_VERSION} \
  243. && nvm alias ${NODE_VERSION} \
  244. && if [ ${NPM_REGISTRY} ]; then \
  245. npm config set registry ${NPM_REGISTRY} \
  246. ;fi \
  247. && if [ ${INSTALL_NPM_GULP} = true ]; then \
  248. npm install -g gulp \
  249. ;fi \
  250. && if [ ${INSTALL_NPM_BOWER} = true ]; then \
  251. npm install -g bower \
  252. ;fi \
  253. && if [ ${INSTALL_NPM_VUE_CLI} = true ]; then \
  254. npm install -g @vue/cli \
  255. ;fi \
  256. && if [ ${INSTALL_NPM_ANGULAR_CLI} = true ]; then \
  257. npm install -g @angular/cli \
  258. ;fi \
  259. && ln -s `npm bin --global` /home/laradock/.node-bin \
  260. ;fi
  261. # Wouldn't execute when added to the RUN statement in the above block
  262. # Source NVM when loading bash since ~/.profile isn't loaded on non-login shell
  263. RUN if [ ${INSTALL_NODE} = true ]; then \
  264. echo "" >> ~/.bashrc && \
  265. echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
  266. echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \
  267. ;fi
  268. # Add NVM binaries to root's .bashrc
  269. USER root
  270. RUN if [ ${INSTALL_NODE} = true ]; then \
  271. cp -R /home/laradock/.nvm /root/ && \
  272. chown -R root:root /root/.nvm && \
  273. echo "" >> ~/.bashrc && \
  274. echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
  275. echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \
  276. ;fi
  277. # Add PATH for node
  278. ENV PATH $PATH:/home/laradock/.node-bin
  279. # Make it so the node modules can be executed with 'docker-compose exec'
  280. # We'll create symbolic links into '/usr/local/bin'.
  281. RUN if [ ${INSTALL_NODE} = true ]; then \
  282. find $NVM_DIR -type f -name node -exec ln -s {} /usr/local/bin/node \; && \
  283. NODE_MODS_DIR="$NVM_DIR/versions/node/$(node -v)/lib/node_modules" && \
  284. ln -s $NODE_MODS_DIR/bower/bin/bower /usr/local/bin/bower && \
  285. ln -s $NODE_MODS_DIR/gulp/bin/gulp.js /usr/local/bin/gulp && \
  286. ln -s $NODE_MODS_DIR/npm/bin/npm-cli.js /usr/local/bin/npm && \
  287. ln -s $NODE_MODS_DIR/npm/bin/npx-cli.js /usr/local/bin/npx && \
  288. ln -s $NODE_MODS_DIR/vue-cli/bin/vue /usr/local/bin/vue && \
  289. ln -s $NODE_MODS_DIR/vue-cli/bin/vue-init /usr/local/bin/vue-init && \
  290. ln -s $NODE_MODS_DIR/vue-cli/bin/vue-list /usr/local/bin/vue-list \
  291. ;fi
  292. RUN if [ ${NPM_REGISTRY} ]; then \
  293. . ~/.bashrc && npm config set registry ${NPM_REGISTRY} \
  294. ;fi
  295. ###########################################################################
  296. # GULP:
  297. ###########################################################################
  298. ARG INSTALL_GULP=false
  299. ENV INSTALL_GULP ${INSTALL_GULP}
  300. USER root
  301. RUN if [ ${INSTALL_GULP} = true ]; then \
  302. npm i -g gulp gulp-cli \
  303. ;fi
  304. ###########################################################################
  305. # YARN:
  306. ###########################################################################
  307. USER laradock
  308. ARG INSTALL_YARN=false
  309. ENV INSTALL_YARN ${INSTALL_YARN}
  310. ARG YARN_VERSION=latest
  311. ENV YARN_VERSION ${YARN_VERSION}
  312. RUN if [ ${INSTALL_YARN} = true ]; then \
  313. [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
  314. if [ ${YARN_VERSION} = "latest" ]; then \
  315. curl -o- -L https://yarnpkg.com/install.sh | bash; \
  316. else \
  317. curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version ${YARN_VERSION}; \
  318. fi && \
  319. echo "" >> ~/.bashrc && \
  320. echo 'export PATH="$HOME/.yarn/bin:$PATH"' >> ~/.bashrc \
  321. ;fi
  322. # Add YARN binaries to root's .bashrc
  323. USER root
  324. RUN if [ ${INSTALL_YARN} = true ]; then \
  325. echo "" >> ~/.bashrc && \
  326. echo 'export YARN_DIR="/home/laradock/.yarn"' >> ~/.bashrc && \
  327. echo 'export PATH="$YARN_DIR/bin:$PATH"' >> ~/.bashrc \
  328. ;fi
  329. # Add PATH for YARN
  330. ENV PATH $PATH:/home/laradock/.yarn/bin
  331. ###########################################################################
  332. # S3 config helper
  333. ###########################################################################
  334. USER laradock
  335. COPY ./minio/auth.json /home/laradock/.mc/config.json
  336. ###########################################################################
  337. # Add known hosts
  338. ###########################################################################
  339. USER laradock
  340. RUN if [ ${INSTALL_SSH} = true ]; then \
  341. && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts \
  342. && ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts \
  343. && ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts \
  344. && ssh-keyscan -t rsa vcs.wpstudio.ru >> ~/.ssh/known_hosts \
  345. ;fi
  346. #
  347. #--------------------------------------------------------------------------
  348. # Final Touch
  349. #--------------------------------------------------------------------------
  350. #
  351. USER root
  352. # Clean up
  353. RUN apt-get clean && \
  354. rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
  355. rm /var/log/lastlog /var/log/faillog
  356. # Set default work directory
  357. WORKDIR /var/www