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.

433 lines
14 KiB

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