loading...

Setup 3-Stages DevEnv (local, staging, live) with just Git + Bash

loouislow profile image Loouis Low ・3 min read

I used to work in many random small startup companies. The truth is, some of the companies don't have the basic development environment that set up with local, staging, and live. The scariest thing ever was they did everything in one single environment. And many of them are pretty anti-pattern and very confident about what they are doing.

So, I wrote a bash script that manipulates on top of the Rsync and Git to create such low-cost solution and this is my Github repository page.

This script discards the complicated set up like the professional CI/CD for who would find this useful. It helps with creating a very practical sort-of-CI/CD-thing. You can modify and adding your innovation onto the script to fit in your style.

Concept

Local

  • At first, you have a git account set up with Github or BitBucket and created a new repository for a new project.
  • You are mostly doing software development on your local computer. The project files in this environment are called the local.
  • You pulled the new project repository from Github or BitBucket.
  • You make some new changes to the project files and pushed to Github or Bitbucket server.

Staging

  • Let say you set up a new server somewhere at Digital Ocean, for example.
  • With installed deployer may be located at dir /dev, for example.
  • Run the $ ./deployer --deploy to pulling the latest project repository from Github or BitBucket.
  • At /staging directory, you can run testing on the actual server environment, instead of doing it locally on your computer.

Live

  • Once you have satisfied and there are no errors in the /staging directory.
  • You can run $ deployer --deploy command to sync to /live directory.

Usage

Let's get started and clone the repository at Github with a Terminal,

$ git clone https://github.com/loouislow81/deployer.git
$ cd deployer

Run this command to get an overview of what this CLI is offered,

$ ./deployer --help

Step 1

Before anything else, you will need to edit the config.proto file to configure the identity of this script, which is only working for a specific payload (your project files),

# To identify specific payload is located
# To store payload history in-between `local` and `staging`
# PROJECT_NAME="defreeze"
PROJECT_NAME="defreeze"


# Set git repository URL (URL must end with `.git`)
# TO_LOCAL_DIR="https://github.com/loouislow81/defreeze.git"
TO_LOCAL_DIR="https://github.com/loouislow81/defreeze.git"


# Staging directory (full path required)
# e.g. `/to/your/staging/dir/`
# TO_STAGING_DIR="staging"
TO_STAGING_DIR="staging"


# Public or live directory (full path required)
# e.g. `/to/your/production/dir/`
# ~ recommended to use symlink re-routing to this directory
# TO_PRODUCTION_DIR="live"
TO_PRODUCTION_DIR="live"

Step 2

Then you are ready to start to load your payload into new a deployer environment,

$ ./deployer --deploy

What this command will do:

  • Check if prerequisites (Rsync, Git) are installed.
  • Create local .git just for deployers use to track changes and history.
  • Create a /staging directory.
  • Check or load the latest payload into /staging directory from PROJECT_NAME.
  • Create a /live directory.
  • Synchronize directory from /staging to /live with an exclusion, (see exclude-list.txt).
  • Output statistics.

Screenshots

Alt Text

Alt Text

Alt Text


Thank you for reading this article. Please heart or unicorn would encourage me to write more about this kind of article next time.

Posted on by:

loouislow profile

Loouis Low

@loouislow

UI Designer, Software Engineer. Interests include numerical linear algebra, software performance optimization with an Electronic Engineering background.

Discussion

pic
Editor guide