diff --git a/Dockerfile b/Dockerfile index 7a0ed1be8..eca882967 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,62 @@ -ARG image_tag=latest +ARG node_version +ARG composer_dev_arg ARG php_version -FROM elifesciences/journal_assets_builder:${image_tag} AS assets -FROM elifesciences/journal_composer:${image_tag} AS composer -FROM elifesciences/php_7.1_fpm:${php_version} +ARG image_tag=latest + +# NPM + +FROM node:${node_version} as npm + +RUN apt-get update && apt-get install --no-install-recommends -y \ + nasm \ + libvips-dev \ + && rm -rf /var/lib/apt/lists/* + +COPY npm-shrinkwrap.json \ + package.json \ + ./ + +RUN npm install + +# Composer + +FROM composer:1.6.4 as composer + +RUN apk add --no-cache \ + patch + +COPY composer.json \ + composer.lock \ + ./ + +RUN composer --no-interaction install ${composer_dev_arg} --ignore-platform-reqs --no-autoloader --no-suggest --prefer-dist + +COPY test/ test/ +COPY src/ src/ + +RUN composer --no-interaction dump-autoload ${composer_dev_arg} --classmap-authoritative + +# Assets-builder + +FROM npm AS assets + +RUN apt-get update && apt-get install --no-install-recommends -y \ + libvips \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=npm /node_modules/ node_modules/ + +COPY assets/images/ assets/images/ +COPY gulpfile.js ./ +COPY --from=composer /app/vendor/elife/patterns/resources/assets/ vendor/elife/patterns/resources/assets/ + +RUN node_modules/.bin/gulp assets + +# Dockerfile + +FROM elifesciences/php_7.1_fpm:${php_version} as app -ENV PROJECT_FOLDER=/srv/journal +ENV PROJECT_FOLDER=/srv/journal/ ENV PHP_ENTRYPOINT=web/app.php WORKDIR ${PROJECT_FOLDER} @@ -29,3 +81,86 @@ COPY --chown=elife:elife src/ src/ USER www-data HEALTHCHECK --interval=5s CMD HTTP_HOST=localhost assert_fpm /ping 'pong' + +FROM app as app_tests +COPY --chown=elife:elife test/ test/ + +# Critical_css + +FROM pinterb/jq:0.0.16 as jq +FROM npm as critical_css + +# From list at https://developers.google.com/web/tools/puppeteer/troubleshooting#chrome_headless_doesnt_launch +RUN apt-get update && apt-get install --no-install-recommends -y \ + fonts-liberation \ + gconf-service \ + libappindicator1 \ + libasound2 \ + libatk1.0-0 \ + libcups2 \ + libdbus-1-3 \ + libgconf-2-4 \ + libgtk-3-0 \ + libnspr4 \ + libnss3 \ + libvips \ + libx11-xcb1 \ + libxcomposite1 \ + libxcursor1 \ + libxdamage1 \ + libxfixes3 \ + libxi6 \ + libxrandr2 \ + libxss1 \ + libxtst6 \ + locales \ + lsb-release \ + unzip \ + xdg-utils \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=jq /usr/local/bin/jq /usr/bin/jq + +RUN mkdir -p build/critical-css + +COPY --from=npm /node_modules/ node_modules/ + +COPY check_critical_css.sh \ + critical-css.json \ + gulpfile.js \ + ./ + +CMD node_modules/.bin/gulp critical-css:generate && ./check_critical_css.sh + +# CI + +FROM app as ci + +USER root +RUN mkdir -p build/ci var/fixtures && \ + chown --recursive www-data:www-data build/ci var/fixtures + +COPY --from=jq /usr/local/bin/jq /usr/bin/jq + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +COPY --chown=elife:elife \ + behat.yml.dist \ + phpunit.xml.dist \ + phpcs.xml.dist \ + ./ +COPY --chown=elife:elife .ci/ .ci/ +COPY --chown=elife:elife assets/tests/ assets/tests/ +COPY --chown=elife:elife composer.json composer.lock ./ +COPY --from=composer --chown=elife:elife /app/vendor/ vendor/ +COPY --chown=elife:elife features/ features/ +COPY --chown=elife:elife test/ test/ + +USER www-data + +# Web + +FROM nginx:1.13.12-alpine as web + +COPY .docker/nginx-default.conf /etc/nginx/conf.d/default.conf +COPY --from=app /srv/journal/web/ /srv/journal/web/ diff --git a/Dockerfile.assets_builder b/Dockerfile.assets_builder deleted file mode 100644 index a03e7fff3..000000000 --- a/Dockerfile.assets_builder +++ /dev/null @@ -1,17 +0,0 @@ -ARG image_tag=latest -ARG node_version -FROM elifesciences/journal_composer:${image_tag} AS composer -FROM elifesciences/journal_npm:${image_tag} as npm -FROM node:${node_version} - -RUN apt-get update && apt-get install --no-install-recommends -y \ - libvips \ - && rm -rf /var/lib/apt/lists/* - -COPY --from=npm /node_modules/ node_modules/ - -COPY assets/images/ assets/images/ -COPY gulpfile.js ./ -COPY --from=composer /app/vendor/elife/patterns/resources/assets/ vendor/elife/patterns/resources/assets/ - -RUN node_modules/.bin/gulp assets diff --git a/Dockerfile.ci b/Dockerfile.ci deleted file mode 100644 index 8bd2b29c5..000000000 --- a/Dockerfile.ci +++ /dev/null @@ -1,26 +0,0 @@ -ARG image_tag=latest -FROM pinterb/jq:0.0.16 AS jq -FROM elifesciences/journal_composer_dev:${image_tag} AS composer -FROM elifesciences/journal:${image_tag} - -USER root -RUN mkdir -p build/ci var/fixtures && \ - chown --recursive www-data:www-data build/ci var/fixtures - -COPY --from=jq /usr/local/bin/jq /usr/bin/jq - -COPY --from=composer /usr/bin/composer /usr/bin/composer - -COPY --chown=elife:elife \ - behat.yml.dist \ - phpunit.xml.dist \ - phpcs.xml.dist \ - ./ -COPY --chown=elife:elife .ci/ .ci/ -COPY --chown=elife:elife assets/tests/ assets/tests/ -COPY --chown=elife:elife composer.json composer.lock ./ -COPY --from=composer --chown=elife:elife /app/vendor/ vendor/ -COPY --chown=elife:elife features/ features/ -COPY --chown=elife:elife test/ test/ - -USER www-data diff --git a/Dockerfile.composer b/Dockerfile.composer deleted file mode 100644 index f54e3a3fd..000000000 --- a/Dockerfile.composer +++ /dev/null @@ -1,17 +0,0 @@ -FROM composer:1.6.4 - -ARG composer_dev_arg - -RUN apk add --no-cache \ - patch - -COPY composer.json \ - composer.lock \ - ./ - -RUN composer --no-interaction install ${composer_dev_arg} --ignore-platform-reqs --no-autoloader --no-suggest --prefer-dist - -COPY test/ test/ -COPY src/ src/ - -RUN composer --no-interaction dump-autoload ${composer_dev_arg} --classmap-authoritative diff --git a/Dockerfile.critical_css b/Dockerfile.critical_css deleted file mode 100644 index bf070d450..000000000 --- a/Dockerfile.critical_css +++ /dev/null @@ -1,48 +0,0 @@ -ARG image_tag=latest -ARG node_version -FROM pinterb/jq:0.0.16 AS jq -FROM elifesciences/journal_npm:${image_tag} as npm - -FROM node:${node_version} - -# From list at https://developers.google.com/web/tools/puppeteer/troubleshooting#chrome_headless_doesnt_launch -RUN apt-get update && apt-get install --no-install-recommends -y \ - fonts-liberation \ - gconf-service \ - libappindicator1 \ - libasound2 \ - libatk1.0-0 \ - libcups2 \ - libdbus-1-3 \ - libgconf-2-4 \ - libgtk-3-0 \ - libnspr4 \ - libnss3 \ - libvips \ - libx11-xcb1 \ - libxcomposite1 \ - libxcursor1 \ - libxdamage1 \ - libxfixes3 \ - libxi6 \ - libxrandr2 \ - libxss1 \ - libxtst6 \ - locales \ - lsb-release \ - unzip \ - xdg-utils \ - && rm -rf /var/lib/apt/lists/* - -COPY --from=jq /usr/local/bin/jq /usr/bin/jq - -RUN mkdir -p build/critical-css - -COPY --from=npm /node_modules/ node_modules/ - -COPY check_critical_css.sh \ - critical-css.json \ - gulpfile.js \ - ./ - -CMD node_modules/.bin/gulp critical-css:generate && ./check_critical_css.sh diff --git a/Dockerfile.npm b/Dockerfile.npm deleted file mode 100644 index ac63629e4..000000000 --- a/Dockerfile.npm +++ /dev/null @@ -1,13 +0,0 @@ -ARG node_version -FROM node:${node_version} as npm - -RUN apt-get update && apt-get install --no-install-recommends -y \ - nasm \ - libvips-dev \ - && rm -rf /var/lib/apt/lists/* - -COPY npm-shrinkwrap.json \ - package.json \ - ./ - -RUN npm install diff --git a/Dockerfile.web b/Dockerfile.web deleted file mode 100644 index fe9fcc1f0..000000000 --- a/Dockerfile.web +++ /dev/null @@ -1,6 +0,0 @@ -ARG image_tag=latest -FROM elifesciences/journal:${image_tag} AS app -FROM nginx:1.13.12-alpine - -COPY .docker/nginx-default.conf /etc/nginx/conf.d/default.conf -COPY --from=app /srv/journal/web/ /srv/journal/web/ diff --git a/Jenkinsfile b/Jenkinsfile index f5ac8f6ee..3ce0866a2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,7 +22,7 @@ elifePipeline { dockerComposeSmokeTests(commit, [ 'services': [ - 'app': './smoke_tests.sh', + 'app_t': './smoke_tests.sh', ], 'blackbox': [ './smoke_tests.sh localhost 8080', @@ -53,7 +53,7 @@ elifePipeline { def tagName = branchName.replaceAll("/", "_") image.tag(tagName).push() } - + elifeMainlineOnly { image.push() } diff --git a/README.md b/README.md index 9764d8cab..6f7929856 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,17 @@ When using Windows to bypass the main errors we recommend to follow the next : Docker Installation - Running the site locally ---------------------------------------------- -1. Run `composer install` to generate vendor files locally -2. Run `docker-compose up --build` -3. Open `http://localhost:8080` in your browser. +
+In order to sync vendor files with local + 1. Add `./` between `-` and `vendor` in docker-compose.override.yml at lines 11 and 28 +
+ 2. Erase `vendor` volume from docker-compose.override.yml +
+ 3. Run `composer install` to generate vendor files locally +
+ +1. Run `docker-compose up --build` +2. Open `http://localhost:8080` in your browser. To start/restart the containers use these commands: `docker-compose down --volumes --remove-orphans && docker-compose up --build` diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 5bb6a9765..52bf8bd43 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -1,4 +1,4 @@ -version: '3' +version: '3.4' services: composer: @@ -8,10 +8,11 @@ services: composer-dev: build: context: . - dockerfile: Dockerfile.composer + dockerfile: Dockerfile + target: composer args: composer_dev_arg: - image: elifesciences/journal_composer_dev:${IMAGE_TAG} + node_version: ${NODE_VERSION} command: /bin/bash selenium: image: selenium/standalone-chrome${SELENIUM_IMAGE_SUFFIX}:2.53.1 @@ -23,10 +24,11 @@ services: ci: build: context: . - dockerfile: Dockerfile.ci + dockerfile: Dockerfile + target: ci args: - image_tag: ${IMAGE_TAG} - image: elifesciences/journal_ci:${IMAGE_TAG} + node_version: ${NODE_VERSION} + php_version: ${PHP_VERSION} volumes: - ./.docker/php.ini:/usr/local/etc/php/conf.d/x-dev.ini - ./.docker/parameters.yml:/srv/journal/app/config/parameters.yml @@ -36,12 +38,25 @@ services: depends_on: - composer-dev - app + - app_t - selenium app: volumes: - fixtures:/srv/journal/var/fixtures environment: - APP_ENV=ci + app_t: + build: + context: . + dockerfile: Dockerfile + target: app_tests + args: + node_version: ${NODE_VERSION} + php_version: ${PHP_VERSION} + volumes: + - fixtures:/srv/journal/var/fixtures + environment: + - APP_ENV=ci web: volumes: - ./assets/tests:/srv/journal/web/tests diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 25071e972..3e2db9973 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,36 +1,31 @@ -version: '3' +version: '3.4' services: - composer: + assets: build: args: composer_dev_arg: volumes: - ./composer.json:/app/composer.json - ./composer.lock:/app/composer.lock - - ./vendor:/app/vendor - npm: - volumes: + - vendor:/app/vendor - ./npm-shrinkwrap.json:/npm-shrinkwrap.json - ./package.json:/package.json - - node_modules:/node_modules - assets_builder: - volumes: - ./assets/images:/assets/images - assets:/web - build:/build - node_modules:/node_modules - ./gulpfile.js:/gulpfile.js + - critical_css:/build/critical-css app: environment: - APP_ENV=${APP_ENV} volumes: - - ./:/srv/journal - ./.docker/php.ini:/usr/local/etc/php/conf.d/x-dev.ini - /srv/journal/var - build:/srv/journal/build - critical_css:/srv/journal/build/critical-css - - ./vendor:/srv/journal/vendor + - vendor:/srv/journal/vendor web: volumes: - assets:/srv/journal/web @@ -44,3 +39,4 @@ volumes: build: critical_css: node_modules: + vendor: diff --git a/docker-compose.yml b/docker-compose.yml index 8a064f06f..5b397703f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,58 +1,51 @@ -version: '3' +version: '3.4' services: composer: build: context: . - dockerfile: Dockerfile.composer + dockerfile: Dockerfile + target: composer args: + node_version: ${NODE_VERSION} composer_dev_arg: ${COMPOSER_DEV_ARG} - image: elifesciences/journal_composer:${IMAGE_TAG} command: /bin/bash - npm: + assets: build: context: . - dockerfile: Dockerfile.npm + dockerfile: Dockerfile + target: assets args: + composer_dev_arg: ${COMPOSER_DEV_ARG} node_version: ${NODE_VERSION} - image: elifesciences/journal_npm:${IMAGE_TAG} + command: /bin/bash redis: image: redis:6.2-alpine - assets_builder: - build: - context: . - dockerfile: Dockerfile.assets_builder - args: - image_tag: ${IMAGE_TAG} - node_version: ${NODE_VERSION} - image: elifesciences/journal_assets_builder:${IMAGE_TAG} - depends_on: - - composer - - npm app: build: context: . + dockerfile: Dockerfile + target: app args: - image_tag: ${IMAGE_TAG} + node_version: ${NODE_VERSION} php_version: ${PHP_VERSION} environment: - SYMFONY__API_URL=${API_URL} - SYMFONY__API_URL_PUBLIC=${API_URL_PUBLIC} - SYMFONY__API_KEY=${API_KEY} - image: elifesciences/journal:${IMAGE_TAG} volumes: - ./.docker/parameters.yml:/srv/journal/app/config/parameters.yml depends_on: - - assets_builder - - composer + - assets - redis web: build: context: . - dockerfile: Dockerfile.web + dockerfile: Dockerfile + target: web args: - image_tag: ${IMAGE_TAG} - image: elifesciences/journal_web:${IMAGE_TAG} + node_version: ${NODE_VERSION} + php_version: ${PHP_VERSION} ports: - '${JOURNAL_PORT}:80' depends_on: @@ -64,14 +57,14 @@ services: critical_css: build: context: . - dockerfile: Dockerfile.critical_css + dockerfile: Dockerfile + target: critical_css args: - image_tag: ${IMAGE_TAG} node_version: ${NODE_VERSION} + php_version: ${PHP_VERSION} environment: - CRITICAL_CSS_BASE_URL=http://web:8080 - image: elifesciences/journal_critical_css:${IMAGE_TAG} depends_on: - - npm + - assets - web - api_dummy