Skip to content

Commit

Permalink
Publish print service images to Docker Hub
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobeltrame committed Nov 11, 2020
1 parent 8f7744e commit 8bff473
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 77 deletions.
18 changes: 18 additions & 0 deletions .docker-hub/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@ services:
context: ..
dockerfile: .docker-hub/backend/Dockerfile
image: ecamp/ecamp3-backend:latest

print:
build:
context: ..
dockerfile: .docker-hub/print/Dockerfile
image: ecamp/ecamp3-print:latest

worker-print-puppeteer:
build:
context: ..
dockerfile: .docker-hub/worker-print-puppeteer/Dockerfile
image: ecamp/ecamp3-worker-print-puppeteer:latest

worker-print-weasy:
build:
context: ..
dockerfile: .docker-hub/worker-print-weasy/Dockerfile
image: ecamp/ecamp3-worker-print-weasy:latest
8 changes: 8 additions & 0 deletions .docker-hub/print/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:12.18
WORKDIR /app
COPY print/package*.json ./
RUN npm install
COPY print .
RUN npm run build
EXPOSE 80
CMD npm run start
2 changes: 1 addition & 1 deletion .docker-hub/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -e

echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
docker-compose -f .docker-hub/docker-compose.yml build
docker-compose -f .docker-hub/docker-compose.yml push backend frontend
docker-compose -f .docker-hub/docker-compose.yml push backend frontend print worker-print-puppeteer worker-print-weasy
6 changes: 6 additions & 0 deletions .docker-hub/worker-print-puppeteer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM buildkite/puppeteer
WORKDIR /app
COPY workers/print-puppeteer/package*.json ./
RUN npm install
COPY workers/print-puppeteer .
CMD npm run print
21 changes: 21 additions & 0 deletions .docker-hub/worker-print-weasy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.8

# install all the dependencies except libcairo2 from jessie, then install libcairo2 from stretch
RUN apt-get -y update \
&& apt-get install -y \
fonts-font-awesome \
libffi-dev \
libgdk-pixbuf2.0-0 \
libpango1.0-0 \
python-dev \
python-lxml \
shared-mime-info \
libcairo2

WORKDIR /app

RUN pip install WeasyPrint pika requests

COPY workers/print-weasy .

CMD python -u print.py
7 changes: 7 additions & 0 deletions backend/config/autoload/sessions.local.docker.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'session_config' => [
'cookie_domain' => '',
],
];
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
image: node:12.18
container_name: 'ecamp3-print'
ports:
- '3003:3000'
- '3003:80'
volumes:
- ./print:/app:delegated
- npm-cache:/root/.npm
Expand All @@ -40,6 +40,8 @@ services:
command: ./docker-setup.sh
environment:
- HOST=0.0.0.0
env_file:
- ./print/print.env

composer:
image: composer:2
Expand Down Expand Up @@ -77,7 +79,7 @@ services:
- '3004:15672'

worker-print-puppeteer:
image: buildkite/puppeteer
build: ./workers/print-puppeteer
container_name: 'ecamp3-worker-print-puppeteer'
volumes:
- ./workers/print-puppeteer:/app:delegated
Expand Down
2 changes: 1 addition & 1 deletion print/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# install dependencies
$ npm install

# serve with hot reload at localhost:3000
# serve with hot reload at localhost
$ npm run dev

# build for production and launch server
Expand Down
16 changes: 16 additions & 0 deletions print/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default {
** See https://nuxtjs.org/api/configuration-target
*/
target: 'server',
server: {
port: 80,
host: '0.0.0.0',
},
/*
** Headers of the page
** See https://nuxtjs.org/api/configuration-head
Expand Down Expand Up @@ -82,4 +86,16 @@ export default {
** See https://nuxtjs.org/api/configuration-build/
*/
build: {},

publicRuntimeConfig: {
axios: {
browserBaseURL: process.env.API_ROOT_URL || 'http://localhost:3001/api',
},
},

privateRuntimeConfig: {
axios: {
baseURL: process.env.INTERNAL_API_ROOT_URL || 'http://backend/api',
},
},
}
91 changes: 46 additions & 45 deletions print/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion print/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "jest"
},
"dependencies": {
"@nuxtjs/axios": "^5.11.0",
"@nuxtjs/axios": "^5.12.2",
"nuxt": "^2.13.0",
"pagedjs": "^0.1.42"
},
Expand Down
2 changes: 2 additions & 0 deletions print/print.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INTERNAL_API_ROOT_URL=http://backend/api
API_ROOT_URL=http://localhost:3001/api
6 changes: 6 additions & 0 deletions workers/print-puppeteer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM buildkite/puppeteer
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD npm run print
9 changes: 9 additions & 0 deletions workers/print-puppeteer/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
PRINT_SERVER: process.env.PRINT_SERVER || "http://print",
SESSION_COOKIE_DOMAIN: process.env.SESSION_COOKIE_DOMAIN || "backend",
AMQP_HOST: process.env.AMQP_HOST || 'rabbitmq',
AMQP_PORT: process.env.AMQP_PORT || '5672',
AMQP_VHOST: process.env.AMQP_VHOST || '/',
AMQP_USER: process.env.AMQP_USER || 'guest',
AMQP_PASS: process.env.AMQP_PASS || 'guest',
};
23 changes: 4 additions & 19 deletions workers/print-puppeteer/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const puppeteer = require('puppeteer');
const amqp = require('amqplib/callback_api');

const PRINT_SERVER = process.env.PRINT_SERVER || "http://print:3000";

const AMQP_HOST = process.env.AMQP_HOST || 'rabbitmq';
const AMQP_PORT = process.env.AMQP_PORT || '5672';
const AMQP_VHOST= process.env.AMQP_VHOST || '/';
const AMQP_USER = process.env.AMQP_USER || 'guest';
const AMQP_PASS = process.env.AMQP_PASS || 'guest';

const { PRINT_SERVER, SESSION_COOKIE_DOMAIN, AMQP_HOST, AMQP_PORT, AMQP_VHOST, AMQP_USER, AMQP_PASS } = require('./environment.js');

async function startBrowser() {
const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});
Expand All @@ -25,17 +18,9 @@ async function html2pdf(url, filename, sessionId) {

const cookies = [
{
"domain": "print",
"hostOnly": true,
"httpOnly": false,
"domain": SESSION_COOKIE_DOMAIN,
"name": "PHPSESSID",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": true,
"storeId": "1",
"value": sessionId,
"id": 1
}
]

Expand All @@ -44,7 +29,7 @@ async function html2pdf(url, filename, sessionId) {
await page.goto(url);

await page.waitFor(500);
await page.waitForSelector(".pagedjs_pages", {timeout:2000});
await page.waitForSelector(".pagedjs_pages", {timeout:10000});

await page.pdf({path: `data/${filename}-puppeteer.pdf`});
}
Expand All @@ -60,7 +45,7 @@ function start() {
throw error1;
}

var queue = 'printer-puppeteer';
const queue = 'printer-puppeteer';

channel.assertQueue(queue, {
durable: true
Expand Down
1 change: 1 addition & 0 deletions workers/print-weasy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
8 changes: 8 additions & 0 deletions workers/print-weasy/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

PRINT_SERVER = os.getenv('PRINT_SERVER', 'http://print/')
AMQP_HOST = os.getenv('AMQP_HOST', 'rabbitmq')
AMQP_PORT = os.getenv('AMQP_PORT', '5672')
AMQP_VHOST = os.getenv('AMQP_VHOST', '/')
AMQP_USER = os.getenv('AMQP_USER', 'guest')
AMQP_PASS = os.getenv('AMQP_PASS', 'guest')
9 changes: 1 addition & 8 deletions workers/print-weasy/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
import pika
import json
import requests
import os

PRINT_SERVER = os.getenv('PRINT_SERVER', 'http://print:3000/')

AMQP_HOST = os.getenv('AMQP_HOST', 'rabbitmq')
AMQP_PORT = os.getenv('AMQP_PORT', '5672')
AMQP_VHOST = os.getenv('AMQP_VHOST', '/')
AMQP_USER = os.getenv('AMQP_USER', 'guest')
AMQP_PASS = os.getenv('AMQP_PASS', 'guest')
from environment import *

# create custom URL fetcher to include cookie
def url_fetcher_factory(sessionId):
Expand Down

0 comments on commit 8bff473

Please sign in to comment.