Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structure changes for Multi-Stage Docker file - Work in progress #1726

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 140 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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}

Expand All @@ -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/
17 changes: 0 additions & 17 deletions Dockerfile.assets_builder

This file was deleted.

26 changes: 0 additions & 26 deletions Dockerfile.ci

This file was deleted.

17 changes: 0 additions & 17 deletions Dockerfile.composer

This file was deleted.

48 changes: 0 additions & 48 deletions Dockerfile.critical_css

This file was deleted.

13 changes: 0 additions & 13 deletions Dockerfile.npm

This file was deleted.

6 changes: 0 additions & 6 deletions Dockerfile.web

This file was deleted.

4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ elifePipeline {

dockerComposeSmokeTests(commit, [
'services': [
'app': './smoke_tests.sh',
'app_t': './smoke_tests.sh',
],
'blackbox': [
'./smoke_tests.sh localhost 8080',
Expand Down Expand Up @@ -53,7 +53,7 @@ elifePipeline {
def tagName = branchName.replaceAll("/", "_")
image.tag(tagName).push()
}

elifeMainlineOnly {
image.push()
}
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<details>
<summary>In order to sync vendor files with local</summary>
1. Add `./` between `-` and `vendor` in docker-compose.override.yml at lines 11 and 28
<br>
2. Erase `vendor` volume from docker-compose.override.yml
<br>
3. Run `composer install` to generate vendor files locally
</details>

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`
Expand Down
27 changes: 21 additions & 6 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '3.4'

services:
composer:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading