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.

443 lines
14 KiB

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="Mahmoud Zalt <mahmoud@zalt.me>"
  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. # Composer:
  93. ###########################################################################
  94. USER root
  95. # Add the composer.json
  96. COPY ./composer.json /home/laradock/.composer/composer.json
  97. # Add the auth.json for magento 2 credentials
  98. COPY ./auth.json /home/laradock/.composer/auth.json
  99. # Make sure that ~/.composer belongs to laradock
  100. RUN chown -R laradock:laradock /home/laradock/.composer
  101. USER laradock
  102. # Check if global install need to be ran
  103. ARG COMPOSER_GLOBAL_INSTALL=false
  104. ENV COMPOSER_GLOBAL_INSTALL ${COMPOSER_GLOBAL_INSTALL}
  105. RUN if [ ${COMPOSER_GLOBAL_INSTALL} = true ]; then \
  106. # run the install
  107. composer global install \
  108. ;fi
  109. # Check if auth file is disabled
  110. ARG COMPOSER_AUTH=false
  111. ENV COMPOSER_AUTH ${COMPOSER_AUTH}
  112. RUN if [ ${COMPOSER_AUTH} = false ]; then \
  113. # remove the file
  114. rm /home/laradock/.composer/auth.json \
  115. ;fi
  116. ARG COMPOSER_REPO_PACKAGIST
  117. ENV COMPOSER_REPO_PACKAGIST ${COMPOSER_REPO_PACKAGIST}
  118. RUN if [ ${COMPOSER_REPO_PACKAGIST} ]; then \
  119. composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST} \
  120. ;fi
  121. # Export composer vendor path
  122. RUN echo "" >> ~/.bashrc && \
  123. echo 'export PATH="~/.composer/vendor/bin:$PATH"' >> ~/.bashrc
  124. ###########################################################################
  125. # Non-root user : PHPUnit path
  126. ###########################################################################
  127. # add ./vendor/bin to non-root user's bashrc (needed for phpunit)
  128. USER laradock
  129. RUN echo "" >> ~/.bashrc && \
  130. echo 'export PATH="/var/www/vendor/bin:$PATH"' >> ~/.bashrc
  131. ###########################################################################
  132. # Crontab
  133. ###########################################################################
  134. USER root
  135. COPY ./crontab /etc/cron.d
  136. RUN chmod -R 644 /etc/cron.d
  137. ###########################################################################
  138. # WP CLI:
  139. ###########################################################################
  140. # The command line interface for WordPress
  141. USER root
  142. ARG INSTALL_WP_CLI=false
  143. RUN if [ ${INSTALL_WP_CLI} = true ]; then \
  144. curl -fsSL -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | bash && \
  145. chmod +x /usr/local/bin/wp \
  146. ;fi
  147. ###########################################################################
  148. # xDebug:
  149. ###########################################################################
  150. USER root
  151. ARG INSTALL_XDEBUG=false
  152. RUN if [ ${INSTALL_XDEBUG} = true ]; then \
  153. # Load the xdebug extension only with phpunit commands
  154. apt-get install -y php${PHP_VERSION}-xdebug && \
  155. sed -i 's/^;//g' /etc/php/${PHP_VERSION}/cli/conf.d/20-xdebug.ini && \
  156. echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/vendor/bin/phpunit'" >> ~/.bashrc \
  157. ;fi
  158. # ADD for REMOTE debugging
  159. COPY ./xdebug.ini /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini
  160. RUN sed -i "s/xdebug.remote_autostart=0/xdebug.remote_autostart=1/" /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini && \
  161. sed -i "s/xdebug.remote_enable=0/xdebug.remote_enable=1/" /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini && \
  162. sed -i "s/xdebug.cli_color=0/xdebug.cli_color=1/" /etc/php/${PHP_VERSION}/cli/conf.d/xdebug.ini
  163. ###########################################################################
  164. # Additional PHP-extensions:
  165. ###########################################################################
  166. RUN pecl install igbinary \
  167. && pecl install -a redis
  168. ###########################################################################
  169. # ssh:
  170. ###########################################################################
  171. ARG INSTALL_SSH=false
  172. ENV INSTALL_SSH ${INSTALL_SSH}
  173. ARG SSH_PASSPHRAZE=12345
  174. ENV SSH_PASSPHRAZE ${SSH_PASSPHRAZE}
  175. RUN ssh-keygen -f /tmp/id_rsa -N ${SSH_PASSPHRAZE}
  176. RUN if [ ${INSTALL_SSH} = true ]; then \
  177. rm -f /etc/service/sshd/down && \
  178. cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys \
  179. && cat /tmp/id_rsa.pub >> /root/.ssh/id_rsa.pub \
  180. && cat /tmp/id_rsa >> /root/.ssh/id_rsa \
  181. && rm -f /tmp/id_rsa* \
  182. && chmod 644 /root/.ssh/authorized_keys /root/.ssh/id_rsa.pub \
  183. && chmod 400 /root/.ssh/id_rsa \
  184. && cp -rf /root/.ssh /home/laradock \
  185. && chown -R laradock:laradock /home/laradock/.ssh \
  186. ;fi
  187. ###########################################################################
  188. # fswatch
  189. ###########################################################################
  190. ARG INSTALL_FSWATCH=false
  191. RUN if [ ${INSTALL_FSWATCH} = true ]; then \
  192. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 47FE03C1 \
  193. && add-apt-repository -y ppa:hadret/fswatch \
  194. || apt-get update -yqq \
  195. && apt-get -y install fswatch \
  196. ;fi
  197. ###########################################################################
  198. # Node / NVM:
  199. ###########################################################################
  200. # Check if NVM needs to be installed
  201. ARG INSTALL_NODE=false
  202. ENV INSTALL_NODE ${INSTALL_NODE}
  203. ARG NODE_VERSION=node
  204. ENV NODE_VERSION ${NODE_VERSION}
  205. ARG INSTALL_NPM_GULP=false
  206. ARG INSTALL_NPM_BOWER=false
  207. ARG INSTALL_NPM_VUE_CLI=false
  208. ARG INSTALL_NPM_ANGULAR_CLI=false
  209. ARG NPM_REGISTRY
  210. ENV NPM_REGISTRY ${NPM_REGISTRY}
  211. ENV NVM_DIR /home/laradock/.nvm
  212. RUN if [ ${INSTALL_NODE} = true ]; then \
  213. # Install nvm (A Node Version Manager)
  214. mkdir -p $NVM_DIR && \
  215. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash \
  216. && . $NVM_DIR/nvm.sh \
  217. && nvm install ${NODE_VERSION} \
  218. && nvm use ${NODE_VERSION} \
  219. && nvm alias ${NODE_VERSION} \
  220. && if [ ${NPM_REGISTRY} ]; then \
  221. npm config set registry ${NPM_REGISTRY} \
  222. ;fi \
  223. && if [ ${INSTALL_NPM_GULP} = true ]; then \
  224. npm install -g gulp \
  225. ;fi \
  226. && if [ ${INSTALL_NPM_BOWER} = true ]; then \
  227. npm install -g bower \
  228. ;fi \
  229. && if [ ${INSTALL_NPM_VUE_CLI} = true ]; then \
  230. npm install -g @vue/cli \
  231. ;fi \
  232. && if [ ${INSTALL_NPM_ANGULAR_CLI} = true ]; then \
  233. npm install -g @angular/cli \
  234. ;fi \
  235. && ln -s `npm bin --global` /home/laradock/.node-bin \
  236. ;fi
  237. # Wouldn't execute when added to the RUN statement in the above block
  238. # Source NVM when loading bash since ~/.profile isn't loaded on non-login shell
  239. RUN if [ ${INSTALL_NODE} = true ]; then \
  240. echo "" >> ~/.bashrc && \
  241. echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
  242. echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \
  243. ;fi
  244. # Add NVM binaries to root's .bashrc
  245. USER root
  246. RUN if [ ${INSTALL_NODE} = true ]; then \
  247. echo "" >> ~/.bashrc && \
  248. echo 'export NVM_DIR="/home/laradock/.nvm"' >> ~/.bashrc && \
  249. echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \
  250. ;fi
  251. # Add PATH for node
  252. ENV PATH $PATH:/home/laradock/.node-bin
  253. # Make it so the node modules can be executed with 'docker-compose exec'
  254. # We'll create symbolic links into '/usr/local/bin'.
  255. RUN if [ ${INSTALL_NODE} = true ]; then \
  256. find $NVM_DIR -type f -name node -exec ln -s {} /usr/local/bin/node \; && \
  257. NODE_MODS_DIR="$NVM_DIR/versions/node/$(node -v)/lib/node_modules" && \
  258. ln -s $NODE_MODS_DIR/bower/bin/bower /usr/local/bin/bower && \
  259. ln -s $NODE_MODS_DIR/gulp/bin/gulp.js /usr/local/bin/gulp && \
  260. ln -s $NODE_MODS_DIR/npm/bin/npm-cli.js /usr/local/bin/npm && \
  261. ln -s $NODE_MODS_DIR/npm/bin/npx-cli.js /usr/local/bin/npx && \
  262. ln -s $NODE_MODS_DIR/vue-cli/bin/vue /usr/local/bin/vue && \
  263. ln -s $NODE_MODS_DIR/vue-cli/bin/vue-init /usr/local/bin/vue-init && \
  264. ln -s $NODE_MODS_DIR/vue-cli/bin/vue-list /usr/local/bin/vue-list \
  265. ;fi
  266. RUN if [ ${NPM_REGISTRY} ]; then \
  267. . ~/.bashrc && npm config set registry ${NPM_REGISTRY} \
  268. ;fi
  269. ###########################################################################
  270. # YARN:
  271. ###########################################################################
  272. USER laradock
  273. ARG INSTALL_YARN=false
  274. ARG YARN_VERSION=latest
  275. ENV YARN_VERSION ${YARN_VERSION}
  276. RUN if [ ${INSTALL_YARN} = true ]; then \
  277. [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
  278. if [ ${YARN_VERSION} = "latest" ]; then \
  279. curl -o- -L https://yarnpkg.com/install.sh | bash; \
  280. else \
  281. curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version ${YARN_VERSION}; \
  282. fi && \
  283. echo "" >> ~/.bashrc && \
  284. echo 'export PATH="$HOME/.yarn/bin:$PATH"' >> ~/.bashrc \
  285. ;fi
  286. # Add YARN binaries to root's .bashrc
  287. USER root
  288. RUN if [ ${INSTALL_YARN} = true ]; then \
  289. echo "" >> ~/.bashrc && \
  290. echo 'export YARN_DIR="/home/laradock/.yarn"' >> ~/.bashrc && \
  291. echo 'export PATH="$YARN_DIR/bin:$PATH"' >> ~/.bashrc \
  292. ;fi
  293. # Add PATH for YARN
  294. ENV PATH $PATH:/home/laradock/.yarn/bin
  295. ###########################################################################
  296. # YARN:
  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. # MySQL Client:
  306. ###########################################################################
  307. USER root
  308. ARG INSTALL_MYSQL_CLIENT=false
  309. RUN if [ ${INSTALL_MYSQL_CLIENT} = true ]; then \
  310. apt-get update -yqq && \
  311. apt-get -y install mysql-client \
  312. ;fi
  313. ###########################################################################
  314. # ping:
  315. ###########################################################################
  316. USER root
  317. ARG INSTALL_PING=false
  318. RUN if [ ${INSTALL_PING} = true ]; then \
  319. apt-get update -yqq && \
  320. apt-get -y install inetutils-ping \
  321. ;fi
  322. ###########################################################################
  323. # PYTHON:
  324. ###########################################################################
  325. ARG INSTALL_PYTHON=false
  326. RUN if [ ${INSTALL_PYTHON} = true ]; then \
  327. apt-get -y install python python-pip python-dev build-essential \
  328. && python -m pip install --upgrade pip \
  329. && python -m pip install --upgrade virtualenv \
  330. ;fi
  331. ###########################################################################
  332. # Check PHP version:
  333. ###########################################################################
  334. RUN set -xe; php -v | head -n 1 | grep -q "PHP ${PHP_VERSION}."
  335. #
  336. #--------------------------------------------------------------------------
  337. # Final Touch
  338. #--------------------------------------------------------------------------
  339. #
  340. USER root
  341. # Clean up
  342. RUN apt-get clean && \
  343. rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
  344. rm /var/log/lastlog /var/log/faillog
  345. # Set default work directory
  346. WORKDIR /var/www