Deployment intro

Code deployment is a multi-step process to deliver code from your local computer to a web server in a reliable and automated fashion.

In regard of deployment, Git is not only used as a version control system, but also as a transport layer to copy over the latest code changes. A typical code deployment on fortrabbit consists of the following deployment pipeline:

# High level concept

1 Local   2 Git provider   3 fortrabbit       4 environment
┌─────┐   ┌────────────┐   ┌──────────────┐   ┌──────────────┐
│ Git ├───▶  Git repo  ├───▶  Deployment  ├───▶   web space  │
└─────┘   └────────────┘   └──────────────┘   └──────────────┘
raw
  1. You work on your local Git repo
  2. You push code changes to the git provider (GitHub), to trigger a deployment
  3. The deployment service is runs at fortrabbit
  4. The build is getting distributed into the web space of the environment

# Code moves up, content moves down

Development is usually happening in the local development environment. Code changes are pushed up.

  • Code tracked with git: templates,plugins, themes, CSS, JS …
  • Content not tracked: images, uploads, database …
  • Runtime data not tracked: logs, sessions, vendor folder, temporary files …

Content updates whoever are often created in the production environment directly, for instance when an editor is adding a new blog post. In many software systems, code and content are separated and do not interfere. A classical PHP project consists of these blocks:

In addition to git deployment, direct code access via SSH and SFTP is also available. This is useful to sync down contents.

# What the storage contains

The Git repo is not a one to one representation of the storage. After you Git push, first the Git repo will be updated, then changes will be synchronized (overwrite but not delete) to the storage. So the storage contains:

  1. The latest Git changes synced in
  2. Artifacts from build steps
  3. Changes done by direct code access
  4. Runtime data like uploads, assets, logs, template fragments …

# Git only syncs up

Git is a one way street here and the only way is up. You can not pull the changes, which are made via SSH or SFTP, from the storage back into your Git repo. So you can not upload something via SFTP and clone it down later via Git. While this might looks odd at first: this design keeps your Git repo clean of temporary, binary and other blob data. The diagram above visualizes this. Use Git only for code deployment, not to manage all of your Apps runtime data. Separate code - managed in Git - from content - managed via SSH/SFTP.

# Not all applications work well with Git

Git deployment is great when the skeleton has clean folder structure with exclude patterns and Composer support. Laravel and Symfony are poster-child-level for good Git support. WordPress and other CMS are not Git compatible, out-of-the-box. Craft works well with Git and Composer.

# Detailed run down


               ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐             ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐

               │                        Deploy service                   │    ─ ─ ─ ▶  │          Environment          │

┌───────────┐  │  ┌──────────────┬────────────┬────────────────────┐   ┌─┴─────────────┴─┐  ┌──────────────────────┐   │
│           │     │              │            │                    │   │                 │  │                      │
│ 1 Queue   │  │  │ 2 Allocation │ 3 Code     │ 4 Build            │   │ 5 Deploy        │  │ 6 Post deploy        │   │
│           │     │              │ sync       │                    │   │                 │  │                      │
│ Waiting   │  │  │ Preparing    │            │ Build commands     │   │ Syncing deploy  │  │ Executing post       │   │
│ for free  │     │ deployment   │ Pull code  │                    │   │ package into    │  │ deploy commands      │
│ slot      │  │  │ containers   │ from git   │ composer install   │   │ web storage     │  │                      │   │
│           │     │              │ repo into  │ pnpm run prod      │   │                 │  │ artisan migrate:all  │
│           │  │  │              │ deploy     │                    │   │ merge           │  │                      │   │
│           │     │              │ container  │                    │   │ …               │  │                      │
│           │  │  │              │            │                    │   │                 │  │                      │   │
│           │     │              │            │                    │   │                 │  │                      │
│           │  │  │              │            │                    │   │                 │  │                      │   │
│           │     │              │            │                    │   │                 │  │                      │
└───────────┘  │  └──────────────┴────────────┴────────────────────┘   └─┬─────────────┬─┘  └──────────────────────┘   │
               └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘             └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
                         ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐

                         │          GitHub           │

                         └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
raw

Found a tpyo?Edit