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.

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