Automatic deployments help you keep your WordPress site's code inside GitLab, without the need to manually update any files on your server. If you need to make changes to any environment, all you'll need to do is push to whatever branch you've set up to deploy from.
In this article, we'll show you how to set up an automatic deployment webhook inside Atomic, then configure GitLab to notify that webhook each time a change is made.
Important: This is an alternate deployment method and is not recommended in most situations. Instead, we recommend using GitLab CI. For more information, see our article on deploying WordPress sites with GitLab CI.
Requirements
- A WordPress site created on your Pagely account.
- A git repository hosted at GitLab that contains your site's code.
Considerations
Before you start configuring your WordPress site's change to automatically deploy from GitLab, but sure to keep a few things in mind:
- You'll want to always make sure that your changes are pushed to GitLab and never directly to your live site. There's a saying that "if it isn't in version control, it doesn't exist", and that couldn't be any more accurate than when using automatic deployments. If something gets pushed by "cowboy coding" a change without going through version control, the next deployment could likely overwrite it.
- If a file exists within your deployment branch, it will be automatically deployed. This means that you should always exclude development files within your branch. Using a proper .gitignore file will allow you to easily exclude any extra development files.
- When initially setting up automatic deployments, make sure that your repository accurately reflects the site you're going to be deploying to. If not, the first automatic deployment can overwrite your site's files and cause data loss.
Step 1: Generate a Deployment Configuration in Atomic
First, you'll need to generate a webhook configuration that GitLab can use to communicate with your site.
- Start by logging into the Atomic control panel.
- On the left-side menu, select Apps.
- Next, find the app that you want to automatically deploy to, then select Go to app to the right.
(It's always a good idea to test deployments first with a development or staging environment. That way, if anything goes wrong, it won't impact your production site.) - From inside your WordPress app's details page, head over to the integration section by clicking on the Integrations icon.
- Select Create new Git Webhook Integration on the bottom right.
- You'll now be presented with a few disclaimers that you'll want to read over and acknowledge, as well as fields for your SSH Remote URL and Git Branch. Inside these fields, enter your SSH URL where your repository can be found, in addition to the branch that the automatic deployment will pull from.
- Finally, click on the Create Integration button to initialize the creation of your new git deployment.
After submitting your integration settings, the system will begin creating your webhook. Once finished, you'll be presented with the details for your webhook, which you'll use to configure the GitLab side of things in the next section.
Step 2: Configure Webhooks in GitLab
Now that you've created your deployment webhooks in Atomic, you'll need to configure GitLab to use those webhooks.
- Begin by logging into your GitLab account and accessing the project that you want to deploy from.
- Next, access your project's integration settings by hovering over Settings, then clicking on Integrations on the left side menu.
- The first field within your integration settings is the URL field. Within this field, enter your Webhook URL that was generated for your in Atomic.
- The next field is the Secret Token field. Inside this field, enter your Provider Secret from the webhook you generated inside Atomic.
- By default, the Push Events and Enable SSL Verification boxes will be enabled. Unless you have a specific reason to change these, just leave them as the default and click on the Add Webhook button.
- Now that your webhook has been configured, you'll need to set up a deploy key that your site will use to gain access to your GitLab repository. To get started, take a look back over to the Settings section of the left side menu, then click on Repository.
- Within your GitLab repository settings page, expand the Deploy Keys section. From here, paste your SSH Public Key that you received in Atomic into the Key field, then click on the Add Key button.
Congratulations! You've now fully configured an automatic deployment! Now that it's all set up, any changes that are made on your configured repository/branch will be automatically deployed to your site!