Skip to content

Latest commit

 

History

History
99 lines (67 loc) · 4.76 KB

Development model for WordPress with Kinsta.md

File metadata and controls

99 lines (67 loc) · 4.76 KB

Development model for WordPress with Kinsta

Set up local environment

  1. Install DevKinsta

  2. Create a new project / Clone an existing project

Set up the repository in GitHub

  1. Create a new repository in the bcc-code organization
    Note 1: this will contain only the editable files (themes and plugins) from WordPress
    Note 2: remember to give access to BCC IT Publishing with Admin role and add it to the Publishing Team dashboard

  2. Go to the folder where your project is located (probably C:/Users/[YourUser]/DevKinsta/public/[ProjectName]) and add a .gitignore file starting from this template.
    Note: that is to exclude everything else from WordPress which won't be edited during development

  3. Open a cmd in the project folder and run the following commands which add the created repository as a remote:
    git init
    git add .
    git remote add production https://github.com/bcc-code/[project-name].git

  4. Go to the Kinsta SSH key settings and add the new repository to the list.

  5. Create a workflow in GitHub (which will deploy the code to the Kinsta server on every push) starting from this template.

    Replace:

  • REPLACE_THIS_WITH_KINSTA_PRODUCTION_PORT
  • REPLACE_THIS_WITH_KINSTA_STAGING_PORT
  • REPLACE_THIS_WITH_KINSTA_HOST
  • REPLACE_THIS_WITH_PROJECT_NAME_IN_KINSTA
  • REPLACE_THIS_WITH_PROJECT_ID_IN_KINSTA

    Note: the necessary info can be found in MyKinsta and choosing the corresponding project

Set up the connection from the Kinsta server to GitHub

Note: Further down will you find the placeholder variable names you have to replace

  1. Get the ssh keys from the Kinsta SSH item. Create a file on your local, name it kinsta, add the content of the same private key and save it in a safe place (best is the C:/Users/[YourUser]/.ssh folder) and give it permission access (e.g. chmod 400 kinsta).
    Open a cmd and type in ssh-add C:/Users/[YourUser]/.ssh/kinsta to add the secret key to your OS registry.

  2. SSH into the Kinsta Server (a good idea is to use Visual Code with the SSH Remote Server extension)
    Note: server details can be found in MyKinsta

  3. Run cd private, git init --bare {sitename}.git

  4. Run cd ../public, git init

  5. Access the private repo hooks folder and create a post-receive hook.
    cd ../private/{sitename}.git/hooks
    nano post-receive

  6. Add the following code inside the post-receive file, make the necessary changes, save and quit nano (CTRL+X -> Y -> Enter).

#!/bin/bash
TARGET="/www/{sitefolder_xxxxxxx}/public"
GIT_DIR="/www/{sitefolder_xxxxxxx}/private/{sitename}.git"
BRANCH="main"

while read oldrev newrev ref
do
        # only checking out the main (or whatever branch you would like to deploy)
        if [[ $ref = refs/heads/$BRANCH ]];
        then
                echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
                git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
        else
                echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
        fi
done


Replacements you have to make:

  • {sitename} is the project name in Kinsta (Username value in MyKinsta)
  • {sitefolder_xxxxxxx} is the project name concatenated with the project id in Kinsta (found under the Path field in MyKinsta)
  1. Assign execute permissions to post-receive file.
    chmod +x post-receive

  2. Do the same thing for the staging environment, or push Live into Staging in Kinsta.

Push to GitHub (will deploy to Kinsta)

When you now push to GitHub, the kinsta.yml workflow should be triggered.
If the commit is to develop it will deploy the changes to the staging environment, and if it is main it will deploy to the live env.

Kinsta accepts the push from the GitHub action because the BCC IT account in Kinsta has the kinsta public key added in Settings > SSH keys.

Deploy to Kinsta from DevKinsta

You may also deploy the entire application (database, WordPress files, etc.) to Kinsta. To do so, you will:

  1. Push to staging from DevKinsta. This will take a few minutes.

  2. Once that is done, you can deploy staging to production from MyKinsta.
    Note: One disadvantage when deploying from DevKinsta is that you have to remove the registration of the production server from the known hosts