Container Based Wordpress ========================= [![Build Status](http://gitea.yvvas.com:8000/api/badges/craft-in-america/vue-wp/status.svg)](http://gitea.yvvas.com:8000/craft-in-america/vue-wp) Docker + Wordpress for SPEED Vue.js for sanity :tools: Requirements -------------------- ### Node.js 14+ * OSX: `brew install node` using [Homebrew](http://brew.sh/) * Linux: `apt install nodejs` ([see Ubuntu/Debian specific instructions](https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions)) or `pacman -S nodejs` (Arch Linux) * Windows: [Install](https://nodejs.org/en/download/) ### Docker & docker-compose * OSX: TBD * Linux: TBD * Windows: TBD :gear: Installation ------------------- 1. Clone repo: `git clone ssh://git@gitea.yvvas.com:4022/craft-in-america/vue-wp.git` 2. Get into the directory with `cd vue-wp` 3. Copy the `sample.env` file to `.env` and substitute the variables with your own 4. Spin up the database and Wordpress containers with `docker-compose up -d` 5. Use a web-browser to navigate to `http://localhost:8080` and complete the Wordpress installer 6. After Wordpress installation is complete, with your terminal navigate to the theme directory `cd vue-theme` 7. Install the theme dependencies: `npm install` ### Post-Installation Configuration The initial Wordpress installation does *not* include any content or user data beyond the default, so we'll need to adjust some settings before we can use our custom theme. 1. The vue-theme is NOT enabled. Please enable it in the wp-admin page under `Appearance > Themes` 2. The custom plugins must be enabled for our theme to work. Please activate them in the wp-admin page under `Plugins`. You should activate `craft-endpoints`, `craft-post-types`, and `posts-to-posts` 3. Wordpress' `API` is NOT turned on by default, so the vue-theme won't have anything to display. You will need to start the `API` with the instructions below. ### Activate Wordpress API 1. Navigate to Settings > [Permalinks](http://localhost:8080/wp-admin/options-permalink.php) 2. Click the 'Custom Structure' radio button 3. Type in `/%postname%/` in the text field 4. Click 'Save Changes' 5. Verify the API by [visiting the API endpoint](http://localhost:8080/wp-json/wp/v2/) :construction_site: Development ------------------------------- After the `API` is active double check your settings in the `.env` file like so.. ``` DB_PASSWORD= WORDPRESS_DB_USER= WORDPRESS_DB_PASSWORD= DB_NAME= IS_DEV=true ``` Make sure `IS_DEV` is set to `true`. This is important. Currently the API uses `localhost`. This should be changed in production. Set your directory owner to `www-data` with `docker exec -it craft-vue chown -R www-data:www-data ./wp-content` so your Wordpress container can write files Lastly, run `npm run dev` to start the development server. If successful, it will tell you that it is running on `http://localhost:8081` :electric_plug: Deployment -------------------------- Setup a staging server and initialize a bare git repo in the `/opt` directory ``` git init --bare /opt/staging/craft-vue.git ``` Copy over the `post-receive` script from `./deployment` to `/opt/staging/craft-vue.git/hooks` and make it executable with the command `chmod ug+x /opt/staging/craft-vue.git/hooks/post-receive` On your development machine, add the staging server as a remote... ``` git remote add staging @:/opt/staging/craft-vue.git ``` When you are ready to get your app to the new server, run `git push && git push staging` and things will get pulled and built on the staging server. Sweet! :robot: CI/CD ------------- Included is a drone config, and some recommended steps to build. * You MUST activate the pipeline * Add the `id_rsa` of the drone host to appropriate key in the pipeline secrets under the name `push_deploy_key` You also need to setup a `post-receive` hook on the host server. * On your *development* machine, add the target host as a remote `git remote add staging master` * Login to the *remote* machine and setup a bare git repo on `git init --bare ` * Copy the `post-receive` hook file into the `` directory :question_mark: Misc -------------------- ### Backup commands #### Uploads Directories 1. Download to development machine: `rsync -av @:/opt/vue-wp/uploads/ ` 2. Upload from development machine: `rsync -azP /uploads/* @:/opt/staging/vue-wp.git/uploads/` #### mysql Dump 1. On the production machine: ``` docker-compose exec -T craft-db mysqldump -u root -p current_cia | gzip > /home//backups/"`date +"%Y-%m-%d"`"-craftdb-backup.sql.gz ``` 2. On your development machine: `rsync -av @:/home//-craftdb-backup.sql.gz ` ```mysql update wp_posts set guid = replace(guid, 'http://old', 'http://143.110.234.41:8080/'); ```