Core Server Setup¶
Provisioning recipe for a server that runs the Core (Laravel) dashboard: the stage box and the hand-managed production box. It is a record of how the boxes were built, not something a normal release touches. Releases reach production through the release workflow, which runs the update over SSM; see Deployments for the deploy mechanics and for what a rebuilt production box must restore from outside git.
Read before using
- The recipe predates the move from
dashtocorenaming and the retirement of theprodbranch. The stage box's checkout is/home/cookiehub/dash; production's is/home/cookiehub/core. Adjust paths to the box you are building. git switch stage # test, stage or prodapplies to a stage or test box. A production box is checked out at a release tag (git checkout vX.Y.Z); there is noprodbranch.- Package versions (Node, PHP) and build commands drift. Treat the deploy workflow's current build steps as authoritative over the ones below.
# Update to the latest version
apt-get update && apt-get upgrade
# Create a new cookiehub user that will own files
useradd -m -s /bin/bash cookiehub
# Copy SSH key to the cookiehub user
cp ~/.ssh /home/cookiehub/ -R
chown cookiehub.cookiehub /home/cookiehub/.ssh -R
# Install web server and related packages
apt-get install apache2 libapache2-mpm-itk php php-mbstring php-gd php-curl php-zip php-xml php-mysql certbot python3-certbot-apache
# Install git
apt-get install git
# Install build tools and package manageres
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt-get install nodejs composer
npm install --global yarn
# Clone dash
su cookiehub
cd
git clone https://github.com/cookiehub-com/dash.git
cd dash
git switch stage # test, stage or prod
# Compile and install dependecies
composer install
yarn install
cp _setup/env/stage .env # test, stage or prod
# Configure apache
cp /home/cookiehub/dash/_setup/apache/stage.conf /etc/apache2/sites-available/dash.conf # test, stage or prod
a2ensite dash
certbot --apache
# Run database migrations
php artisan migrate
# Install and configure supervisor (queue workers)
apt-get install supervisor
cp /home/cookiehub/core/_setup/supervisor/queue-wix.conf /etc/supervisor/conf.d/
supervisorctl reread
supervisorctl update
supervisorctl start queue-wix:*
# Configure cdn sync
#
# STILL REQUIRED. Most widget assets (c2/*.js, c2/css/*.css, client/*/*.json) are
# written straight to the CDN bucket by the app -- every AppHelper::writeFile under
# storage/cdn/ in Domain.php is paired with an S3BucketHelper::writeToS3 -- so for
# those the sync is redundant churn.
#
# But these writers have NO paired S3 write and reach the bucket ONLY via this cron:
# Tcf3Sync.php -> tcf/v3/*, c2/tcf/vendor-list-3.json
# Tcf2Sync.php -> tcf/v2/vendor-list.json, c2/tcf/vendor-list.json
# CookieDatabaseGenerate{Cookies,Vendors,Services}.php -> db/*.json
# Plus dist/* files placed on the box by hand.
#
# Proof: stage has no such cron, and s3://cookiehub-stage-cdn/ has no tcf/ or db/
# prefix at all. Dropping this cron on prod would freeze the TCF vendor lists and
# the cookie database served from the CDN.
#
# Removing it requires first giving those commands a paired writeToS3 (or moving
# the publish path to core-api). Tracked in IS-40.
sudo snap install aws-cli --classic
cd /home/cookiehub/core
aws configure
# Runs as the `cookiehub` user (crontab -e), NOT root, and hourly at :10 -- not the
# every-minute --size-only form this doc used to claim.
crontab -e
10 * * * * aws s3 sync ~/core/storage/cdn/ s3://cookiehub-cdn/ >> /tmp/s3-daily-sync.log