This repository contains all of the templates, configuration, etc. for the UXF website to run on Craft CMS.
There is one custom plugin which makes working with the version tree easier. It adds the latestApproved
twig filter. Pass an array of versions for a single component and it will return the latest approved entry.
Use object['prop'] is defined
vs object.prop is defined
.
Use {{ siteUrl }}desired/path/
(note no slash immediately after the base url).
For entries just use {{ entry.url }}
which already contains the base.
-
Make any changes to the templates, etc. Commit to the git repo.
-
Run
git push live master
Any control panel settings will be stored in the database. We use the production server as the canonical source for DB settings. You can sync them back to a local dev environment by running the following command:
./scripts/pull_db.sh
The production server will also serve as the canonical source for assets, which can be pulled down to local by running:
./scripts/pull_assets.sh
Reference: https://nystudio107.com/blog/database-asset-syncing-between-environments-in-craft-cms
A free mailgun account is used to send account activation emails. It is connected through SMTP.
For now we are using Digital Ocean backups. In the future it would be worth setting up the Craft Scripts thing to automatically backup to S3 or something.
Reference: https://nystudio107.com/blog/mitigating-disaster-via-website-backups
Reference: https://github.com/nystudio107/craft-scripts
- Create a LAMP on 16.04 One-click app.
- Choose the desired size.
- Recommend configuring an SSH key.
- SSH into the droplet and install dependencies:
sudo apt-get update
sudo apt-get install php-mbstring php-mcrypt php-curl php-xml npm nodejs-legacy
sudo systemctl restart apache2
- Set the proper permissions:
chown -R www-data:www-data /var/www/
chmod -R 770 /var/www/
chmod -R 774 /var/www/html/
Reference: https://deploybot.com/guides/deploy-craft-cms-to-digitalocean
- Enable options:
a2enmod rewrite
a2enmod ssl
phpenmod mcrypt
service apache2 restart
- Change GROUP BY behavior in MySQL to account for breaking change in MySQL 5.7.5+ by editing
/etc/mysql/my.cnf
to include the following lines at the end of the file:
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
- Log into MySQL and create a database user. Note Digital Ocean stores the root MySQL password at
/root/.digitalocean_password
mysql -u root -p
Then run the following queries:
CREATE USER craftcms@localhost IDENTIFIED BY 'complex_password';
CREATE DATABASE craftcms;
GRANT ALL PRIVILEGES ON craftcms.* TO craftcms@localhost;
FLUSH PRIVILEGES;
exit
And restart MySQL:
service mysql restart
-
Recommend running
mysql_secure_installation
, at least with the options of removing the anonymous user, disallowing remote root access, and removing the test database. Don't forget to reload the privilege table as prompted to ensure changes take effect. -
Install SSL certificates by following these instructions: https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority
-
Create the bare git repo that we will push to when we want to deploy.
cd /var/
mkdir repo && cd repo
mkdir uxf-craft.git && cd uxf-craft.git
git init --bare
cd hooks/
touch post-receive
Edit the post-receive
file to contain:
#!/bin/sh
git --work-tree=/var/www/html/ --git-dir=/var/repo/uxf-craft.git/ checkout -f
npm install --prefix /var/www/html/
Then make it executable:
chmod +x post-receive
- Add the server repo as a remote to your local repo.
git remote add live ssh://root@<droplet_ip_address>/var/repo/uxf-craft.git/
To deploy the project run git push live master
- Add config files. Two config files are excluded from the git repo because they contain db passwords,
craft/config/db.php
andscripts/.env.sh
. Edit these to contain the correct information then:
scp craft/config/db.php root@<droplet_ip_address>:/var/www/html/craft/config/
scp scripts/.env.sh root@<droplet_ip_address>:/var/www/html/scripts/
- Set change the user on craft files to take advantage of previously set up permissions.
chown -R www-data:www-data /var/www/
-
Go to <droplet_ip_address>/admin and follow the prompts to complete the craft installation.
-
Go to the settings panel, click on plugins, and install the UXFToolsPlugin.
-
At this point you can follow the steps below to do a fresh import, or restore from a backup.
You may need to increase the file upload size limit in php. This is likely in the php.ini file, don't forget to restart apache after changing it.
-
Make sure to set up all of the fields, entries, assets, etc. in the Craft CMS. Especially make sure the asset fields point to the correct asset source if you have deleted/recreated them.
-
Edit line 55 and 56 of
exporter.js
to point to the correct section and type IDs for the top level components. (Read the IDs from the url when looking at them in the Craft settings area.) -
From the root of the github pages repo, run:
node --harmony ./exporter.js
to create the following files:
- components.json --- This file lists the top level components with appropriate slugs
- assets.json --- This file lists all of the images and videos for every component version, intended for a FeedMe plugin asset import
- sketch.json --- Lists all of the sketch files for each version, intended for FeedMe plugin import
Note you may need to run the command a few times to get it to complete without throwing an error as occasionally there is a race condition when checking file urls for 404s.
-
Import the top level components by pointing the SproutImport plugin at
components.json
. -
Import images and videos by running FeedMe on
assets.json
. This will likely take a while. -
Import sketch files by running FeedMe on
sketch.json
. -
Edit lines 9 and 33 of the
UXFTools_FolderIdsController.php
file in the custom UXFToolsPlugin to reflect the IDs of the two asset sources. -
In the custom UXFToolsPlugin, click the two buttons to write parent and folder IDs to the files
component_ids.json
,folder_ids.json
, andfolder_ids_sketch.json
. These files can be found at:
craft/storage/runtime/temp/UXFTools/
-
Copy those three files to the root of the github pages repo.
-
Create the
versions-X.json
files by running:
node --harmony ./exporter_versions.js
Note: ensure the sectionId and typeId are set correctly on lines 195 and 196.
-
In sequential order, import the versions files with the SproutImport plugin.
-
There may be a few errors about missing files and whatnot. I was generally able to go in and manually rename references to get this all to work. Check the sprout logs at craft/storage/runtime/logs/
-
Extra steps for custom color type:
- Change all the color version entries to colorsVersion entry type
- Use the third button in the UXF tools plugin to write the entry IDs for the colors entries.
- Run
node --harmony ./exporter_colors.js
in the jekyll repo to create thecolors.json file
- Use the Feed Me plugin to pull this file in and update the existing entries