Skip to content

Latest commit

 

History

History
120 lines (96 loc) · 5 KB

deploy-project.md

File metadata and controls

120 lines (96 loc) · 5 KB

How to deploy project

If configured correctly, you only need to git push origin master.

Jenkins in ci.nfqakademija.lt will run:

$WORKSPACE/.deploy/build.sh
echo "[app]
nfqakademija.lt ansible_host=deploy.nfqakademija.lt ansible_user=$JOB_NAME
" > $WORKSPACE/.deploy/ansible_hosts
$WORKSPACE/.deploy/deploy.sh

And your page will appear in http://PROJECT_NAME.projektai.nfqakademija.lt/, where PROJECT_NAME is usually the same as the name of github repository.

How deployment works

How deployment works

  1. You merge your changes to master branch and push it to GitHub (git push origin master)
  2. GitHub have WebHook configured for the project, so it informs ci.nfqakademija.lt, that new changes are pushed to repository (this is optional step just make deployment faster and easier)
  3. Jenkins checks if it have triggers enabled and branch is master – if all ok, Jenkins starts new job. Meaning, it executes build.sh, generates ansible_hosts file and executes deploy.sh. (you can trigger build manually by logging in to ci.nfqakademija.lt and pushing Build Now)
  4. Ansible (started by deploy.sh) use configuration in deploy_playbook.yaml. Usually it SSH to Web Server, copies build artifacts (E.g. project.tar.gz), change symbolic links to newest version (to make deployment atomic), warm-up cache.
  5. If there are no errors, you should see your new changes via http://PROJECT_NAME.projektai.nfqakademija.lt/, where PROJECT_NAME is your GitHub repository name.
  6. For more complex scenarios (E.g. custom .env configuration, setting up database tables), you can connect to WEB server using ssh PROJECT_NAME@deploy.nfqakademija.lt -p 2222, where PROJECT_NAME is your GitHub repository name.
  7. If there are any errors, you can login to ci.nfqakademija.lt and in Build History check Console Output. Last lines usually shows error message. Whole output is generated by build.sh and deploy.sh commands. (E.g. you can see + composer install --no-dev --no-scripts --no-interaction --optimize-autoloader command).

To get notifications about failed/successful builds, you can add Jenkins integration to Slack

How to configure passwords (e.g. Mailer)

  • Do not add passwords to .env file – because it will be pushed publickly to GitHub
  • During development put real values in .env.local – so they would be kept only in your machine
  • Use ssh PROJECT_NAME@deploy.nfqakademija.lt -p 2222 to connect to production server:
    • nano ~/shared/.env.local to update files manually on a server

For mail configuration. We recomend using Gmail:

  • .env would be used for documentation only. E.g.:
MAILER_URL=null://localhost
  • .env.local use real value specific to your machine or production server. E.g.:
MAILER_URL=gmail://username:password@localhost

How to update database on server

  1. SSH to deploy server:
ssh PROEJCT_NAME@deploy.nfqakademija.lt -p 2222

Where PROEJCT_NAME is your GitHub repository name

  1. Go to current deployed version
cd ~/current
  1. Use bin/console as you did locally (database credentials already in .env, which is linked to ~/shared/.env):
bin/console doctrine:migrations:migrate

Answer Yes (assuming you are the author and know, what migrations are to be applied)

How to debug errors

If you see white/blank page. It may be related to errors in your PHP application. To debug:

  1. SSH to deploy server:
ssh PROEJCT_NAME@deploy.nfqakademija.lt -p 2222

Where PROEJCT_NAME is your GitHub repository name

  1. Check PHP-FPM/nginix logs
tail -f /var/log/php7.3-fpm.log | grep "pool $USER"

You should see somehting like:

[27-Oct-2019 19:40:45] WARNING: [pool test20191027] child 9131 said into stderr: "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test20191027.test' doesn't exist" at ... Driver/AbstractMySQLDriver.php line 42"

If that does not help. You can temporary set APP_ENV=dev in ~/current/.env.local. But this is last option and is not good practice.

  1. Check Symfony logs
tail ~/current/var/log/prod.log

You could see something like:

[2019-04-24 15:22:56] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\TableNotFoundException: "...  doesn't exist at ... /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117)"} []
  1. Check, if all migrations are exectuted
~/current/bin/console doctrine:migrations:status

More inforamtion at doctrine docs