Domain, Hosting, Server Config, & Deployment - AmericanSolutions/company-www GitHub Wiki
Domain
Domain purchased through name.com under cory's acct.
SSL/HTTPS
letsencrypt certbot was used and a cron job is setup to run weekly. https://certbot.eff.org/#ubuntutyakkety-nginx
Hosting & Server
We're currently running on a digitalocean.com droplet with nginx & php configured.
A record is added in the DO networking config with the needed subdomain names as well.
Nginx
Nginx is configured w/ subdomains on the server in the config files located /etc/nginx/sites-enabled/ and serving TLD and sub domains from /var/www/public, /var/dev/public & /var/[subdomain name].
Note: since both www and dev directories in
/varthey must keep the structure to have or build to/publicin the repo project directory so they are served by nginx.
Deployment
This repository has a git webhook setup to hit git.americandevshop.com/git-receive-hook.php which will handle the "build/deploy" process in the file /var/git/git-receive-hook.php. This is triggered on branches master & develop.
Deployment Details & Flow
The git webhook sends a payload to the url above which is routed with our Nginx server to /var/git. The git-receive-hook.php pulls both master & develop branches in their respective directories (/var/www & /var/dev). The PHP script then creates a file in /var/git dir named update_needed. There is a crontab -e job set to run the shell script /var/git/cron_check_for_update.sh (as root) every minute. The shell script checks if the file update_needed exists, if it does, it then proceeds to run the npm script in the develop branch directory.
This entire flow was created because PHP scripts run as
www-datauser and in order to runnvm|npmscripts, we need to use the root user. The root user is needed because that's the user that installednvmand has permissions to run the deploy scripts.
Npm run deploy
The git hook on the server will run npm run deploy command on develop branch/directory. Any pre-processing, compiling, minifying, etc. can be done in that script.