Applications3 min readUpdated

Git deploys: connect GitHub, deploy on push and roll back

Connect a repository with one click or by hand, deploy a branch from the console or on every push, and roll back a release.

Connect an application to a Git repository and deploy a branch from the console. For Magento, Laravel and Node.js every deploy builds a complete new release and switches to it in one step, so visitors never see a half-built site.

Git deploys: repository address and branch.
Git deploys: repository address and branch.

Connect with GitHub (the quick way)

  1. Connect GitHub

    On the Git deploys tab press Connect GitHub and allow the ShopWhizzy app. You come back to the same page.

  2. Pick the repository and branch

    Choose one of your repositories, or New private repository to create an empty one on GitHub. If a repository is not listed, use the link under the form to give the ShopWhizzy app access to it on GitHub.

  3. Decide about deploys on pushDeploy on every push is off by default. Leave it off until the first deploy from the console has worked.
  4. Connect

    The console saves the repository and branch on the application, adds a read-only deploy key and the push webhook to the repository on GitHub. Nothing is deployed yet.

  5. Deploy

    Check the settings and press Deploy. The log shows each step.

For Magento the console also checks the repository before the first deploy: it must hold the full project, with composer.json, composer.lock and app/etc/config.php. A deploy replaces the code on the server with the repository, so a repository with only a theme or a module would leave the store without its code.

Connect any other Git host by hand

  1. Enter the repository

    The SSH address (for example git@gitlab.com:company/site.git) and the branch.

  2. Add the deploy key

    The console shows a public key made for this application. Add it to the repository as a read-only deploy key (GitHub: Settings, Deploy keys; GitLab: Settings, Repository, Deploy keys).

  3. Create the webhook (optional)

    Press Create webhook to get a URL and a secret, and add them to the repository (content type JSON, push events). The secret is shown once.

How deploys on push work

  1. You push to the repository. GitHub (or GitLab) calls the application's webhook URL with the details of the push.
  2. The platform checks the signature with the webhook's secret. A call without the right signature is refused.
  3. A push to another branch is ignored. Only the branch saved on the application counts.
  4. With Deploy on every push on, the deploy starts by itself, exactly as if you had pressed Deploy, and shows in the application's activity. With it off, the push is only noted ("push received, auto deploy off") and you deploy from the console when you are ready.

Many teams keep deploys on push on for a staging copy and off for the live store, so a push never reaches customers before someone has looked at it.

What a Magento deploy does

  1. Fetches the code into a new folder under releases/.
  2. Links the shared paths from shared/: app/etc/env.php, pub/media, var/log and the other folders that must survive deploys (see Where your files go).
  3. Runs composer install, setup:di:compile and a full setup:static-content:deploy.
  4. Runs setup:upgrade only when the database or configuration needs it (maintenance mode only for that step), after a database backup.
  5. Switches current to the new release, flushes the cache and reloads PHP.
  6. Keeps the last 5 releases.

The first Magento deploy needs shared/app/etc/env.php. On a store moved from another host, put its env.php there (with the new database details) before deploying.

Roll back

A rollback points current back to a previous release. It changes the code only, not the database.

Disconnect

Disconnect from GitHub removes the deploy key and the webhook from the repository. The code on the server stays as it is.

WordPress, WooCommerce, PrestaShop, Shopware and plain PHP applications deploy by updating the code in place, with optional composer install and an npm build. Files that are not in the repository, such as uploads and settings files, are left alone. See Where your files go for your platform.

Did this solve it? If not, tell us what you see and we look at your server.

Open a ticket

Still stuck? Ask a person.

Tickets go straight to the engineers who run ShopWhizzy servers. Tell us the store, what you see and when it started, and we take it from there.