Skip to content

Commit

Permalink
Deploy print and rabbitmq
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobeltrame committed Nov 8, 2020
1 parent 2d01b56 commit 75b43ab
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 12 deletions.
57 changes: 48 additions & 9 deletions .deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,64 @@ COMMIT_ID=$(git rev-parse --short "$TRAVIS_COMMIT")
# Inject environment secrets into backend config files
EDIT_SCRIPT=".deployment/edit_array_file.php"
DB_CONFIG_FILE=".deployment/dist/doctrine.local.prod.php"
DB_CONFIG_PARAMS_PATH="doctrine.connection.orm_default.params"
cp backend/config/autoload/doctrine.docker.dist $DB_CONFIG_FILE
php $EDIT_SCRIPT $DB_CONFIG_FILE "${DB_CONFIG_PARAMS_PATH}.host" "${DB_HOST:-db}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "${DB_CONFIG_PARAMS_PATH}.port" "${DB_PORT:-3306}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "${DB_CONFIG_PARAMS_PATH}.user" "${DB_USER:-ecamp3}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "${DB_CONFIG_PARAMS_PATH}.password" "${DB_PASS:-ecamp3}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "${DB_CONFIG_PARAMS_PATH}.dbname" "${DB_NAME:-ecamp3dev}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "doctrine.connection.orm_default.params.host" "${DB_HOST:-db}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "doctrine.connection.orm_default.params.port" "${DB_PORT:-3306}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "doctrine.connection.orm_default.params.user" "${DB_USER:-ecamp3}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "doctrine.connection.orm_default.params.password" "${DB_PASS:-ecamp3}"
php $EDIT_SCRIPT $DB_CONFIG_FILE "doctrine.connection.orm_default.params.dbname" "${DB_NAME:-ecamp3dev}"
cp backend/config/autoload/mail.local.docker.dist .deployment/dist/mail.local.prod.php
cp backend/config/autoload/sessions.local.docker.dist .deployment/dist/sessions.local.prod.php
php $EDIT_SCRIPT .deployment/dist/sessions.local.prod.php "session_config.cookie_domain" "${SESSION_COOKIE_DOMAIN}"
cp backend/config/autoload/zfr_cors.global.php .deployment/dist/zfr_cors.global.php
php $EDIT_SCRIPT .deployment/dist/zfr_cors.global.php "zfr_cors.allowed_origins.0" "${FRONTEND_URL:-*}"
php $EDIT_SCRIPT .deployment/dist/zfr_cors.global.php "zfr_cors.allowed_origins.1" "${PRINT_SERVER_URL:-*}"
cp backend/config/sentry.config.php.dist .deployment/dist/sentry.config.php
php $EDIT_SCRIPT .deployment/dist/sentry.config.php "dsn" "${SENTRY_DSN}"
cp backend/config/autoload/amq.local.dev.dist .deployment/dist/amq.local.prod.php
php $EDIT_SCRIPT .deployment/dist/amq.local.prod.php "amqp.connection.host" "${RABBITMQ_HOST:-rabbitmq}"
php $EDIT_SCRIPT .deployment/dist/amq.local.prod.php "amqp.connection.port" "${RABBITMQ_PORT:-5672}"
php $EDIT_SCRIPT .deployment/dist/amq.local.prod.php "amqp.connection.vhost" "${RABBITMQ_VHOST:-/}"
php $EDIT_SCRIPT .deployment/dist/amq.local.prod.php "amqp.connection.user" "${RABBITMQ_USER:-guest}"
php $EDIT_SCRIPT .deployment/dist/amq.local.prod.php "amqp.connection.pass" "${RABBITMQ_PASS:-guest}"

# Inject environment secrets into frontend config files
cp frontend/public/environment.dist .deployment/dist/environment.js
sed -ri "s~API_ROOT_URL: '.*'~API_ROOT_URL: '${BACKEND_URL}'~" .deployment/dist/environment.js
# Inject environment variables into frontend config file
cp frontend/public/environment.dist .deployment/dist/frontend-environment.js
sed -ri "s~API_ROOT_URL: '.*'~API_ROOT_URL: '${BACKEND_URL}'~" .deployment/dist/frontend-environment.js
sed -ri "s~PRINT_SERVER: '.*'~PRINT_SERVER: '${PRINT_SERVER_URL}'~" .deployment/dist/frontend-environment.js
sed -ri "s~PRINT_FILE_SERVER: '.*'~PRINT_FILE_SERVER: '${PRINT_FILE_SERVER_URL}'~" .deployment/dist/frontend-environment.js
sed -ri "s~VERSION: '.*'~VERSION: '${COMMIT_ID}'~" .deployment/dist/frontend-environment.js
sed -ri "s~VERSION_LINK_TEMPLATE: '.*'~VERSION_LINK_TEMPLATE: '${VERSION_LINK_TEMPLATE:-https://github.com/ecamp/ecamp3/commits/\{version\}}'~" .deployment/dist/frontend-environment.js

# Inject environment variables into print env file
cp print/print.env .deployment/dist/print.env
sed -ri "s~INTERNAL_API_ROOT_URL=.*~API_ROOT_URL=${INTERNAL_BACKEND_URL:-http://backend/api}~" .deployment/dist/print.env
sed -ri "s~API_ROOT_URL=.*~API_ROOT_URL=${BACKEND_URL:-http://localhost:3001/api}~" .deployment/dist/print.env

# Inject environment secrets into print-worker-puppeteer config file
cp workers/print-puppeteer/environment.js .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~PRINT_SERVER: .*$~PRINT_SERVER: '${PRINT_SERVER_URL:-print}',~" .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~SESSION_COOKIE_DOMAIN: .*$~SESSION_COOKIE_DOMAIN: '${SESSION_COOKIE_DOMAIN:-backend}',~" .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~AMQP_HOST: .*$~AMQP_HOST: '${RABBITMQ_HOST:-rabbitmq}',~" .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~AMQP_PORT: .*$~AMQP_PORT: '${RABBITMQ_PORT:-5672}',~" .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~AMQP_VHOST: .*$~AMQP_VHOST: '${RABBITMQ_VHOST:-/}',~" .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~AMQP_USER: .*$~AMQP_USER: '${RABBITMQ_USER:-guest}',~" .deployment/dist/worker-print-puppeteer-environment.js
sed -ri "s~AMQP_PASS: .*$~AMQP_PASS: '${RABBITMQ_PASS:-guest}',~" .deployment/dist/worker-print-puppeteer-environment.js

# Inject environment secrets into print-worker-weasy config file
cp workers/print-weasy/environment.py .deployment/dist/worker-print-weasy-environment.py
sed -ri "s~PRINT_SERVER = .*$~PRINT_SERVER = '${PRINT_SERVER_URL}'~" .deployment/dist/worker-print-weasy-environment.py
sed -ri "s~AMQP_HOST = .*$~AMQP_HOST = '${RABBITMQ_HOST:-rabbitmq}'~" .deployment/dist/worker-print-weasy-environment.py
sed -ri "s~AMQP_PORT = .*$~AMQP_PORT = '${RABBITMQ_PORT:-5672}'~" .deployment/dist/worker-print-weasy-environment.py
sed -ri "s~AMQP_VHOST = .*$~AMQP_VHOST = '${RABBITMQ_VHOST:-/}'~" .deployment/dist/worker-print-weasy-environment.py
sed -ri "s~AMQP_USER = .*$~AMQP_USER = '${RABBITMQ_USER:-guest}'~" .deployment/dist/worker-print-weasy-environment.py
sed -ri "s~AMQP_PASS = .*$~AMQP_PASS = '${RABBITMQ_PASS:-guest}'~" .deployment/dist/worker-print-weasy-environment.py

# Inject environment secrets into rabbitmq env file
cp .deployment/rabbitmq.env .deployment/dist/rabbitmq.env
sed -ri "s~RABBITMQ_DEFAULT_USER=.*~RABBITMQ_DEFAULT_USER=${RABBITMQ_USER:-guest}~" .deployment/dist/rabbitmq.env
sed -ri "s~RABBITMQ_DEFAULT_PASS=.*~RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASS:-guest}~" .deployment/dist/rabbitmq.env

echo "Deploying the project to the server..."

# Add the host fingerprint to the known hosts
Expand Down
42 changes: 41 additions & 1 deletion .deployment/dist/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,61 @@ services:
- '80:80'
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- print-output:/static-files
depends_on:
- backend
- frontend
- print
- worker-print-puppeteer
- worker-print-weasy

frontend:
image: ecamp/ecamp3-frontend:latest
container_name: 'ecamp3-frontend'
volumes:
- ./environment.js:/app/environment.js
- ./frontend-environment.js:/app/environment.js

backend:
image: ecamp/ecamp3-backend:latest
container_name: 'ecamp3-backend'
volumes:
- ./doctrine.local.prod.php:/app/config/autoload/doctrine.local.prod.php
- ./mail.local.prod.php:/app/config/autoload/mail.local.prod.php
- ./sessions.local.prod.php:/app/config/autoload/sessions.local.prod.php
- ./zfr_cors.global.php:/app/config/autoload/zfr_cors.global.php
- ./sentry.config.php:/app/config/sentry.config.php
depends_on:
- rabbitmq

print:
image: ecamp/ecamp3-print:latest
container_name: 'ecamp3-print'
env_file:
- ./print.env

rabbitmq:
image: rabbitmq:3.8-management
container_name: 'ecamp3-rabbitmq'
env_file:
- ./rabbitmq.env

worker-print-puppeteer:
image: ecamp/ecamp3-worker-print-puppeteer
container_name: 'ecamp3-worker-print-puppeteer'
volumes:
- ./worker-print-puppeteer-environment.js:/app/environment.js
- print-output:/app/data
depends_on:
- rabbitmq

worker-print-weasy:
image: ecamp/ecamp3-worker-print-weasy
container_name: 'ecamp3-worker-print-weasy'
volumes:
- ./worker-print-weasy-environment.py:/app/environment.py
- print-output:/app/data
depends_on:
- rabbitmq

volumes:
print-output:
25 changes: 23 additions & 2 deletions .deployment/dist/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
events {

}

http {

server {
listen 80;
server_name dev.ecamp3.ch;
Expand All @@ -22,6 +20,29 @@ http {
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name print-dev.ecamp3.ch;
location / {
proxy_pass http://print:80;
proxy_redirect off;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name files-dev.ecamp3.ch;
default_type application/octet-stream;
location / {
root /static-files;
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Methods' 'GET' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
}
}
server {
listen 80 default_server;
server_name _;
Expand Down
2 changes: 2 additions & 0 deletions .deployment/rabbitmq.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest

0 comments on commit 75b43ab

Please sign in to comment.