Whats App

Easy and Fast Deployment to VPS using Git

Yes Soft One Comment
Post Image

The Problem

You are developing Angular and you want to deploy continues patches to the server and bug fixes all over the stack. You want an easy way to deploy to the VPS server you have without any need to run throw the cycle over and over again of build/zip/upload/unzip/npm i (to update dependencies). Well, we have a simple solution for you.

Tools

You need: 

  • An SSH access to the server
  • composer/npm installed and functional

And that’s it, a cheap clean solution for you.

Demonstration’s Scenario

Continuous Deployment (is part of Continuous Integration, which involves Jenkins) of an Angular Project.

The Process usually goes as follows:

  1. You build a function/ component/ service
  2. ng build –prod
  3. Zip the dest folder
  4. Upload to the server via ftp
  5. Unzip the folder
  6. Product assessment.

The Trick

  1. Build a server repository using the command on the home directory
    ```bash
     git init --bare project.git
    ```
  2. Add a hook to update the site automatically
    ```bash
    #!/bin/bash
    unset GIT_INDEX_FILE
     #this will update the files of src folder basically pulling the repo again
    git --work-tree=/var/www/project --git-dir=/home/git/project.git checkout -f 
    cd /var/www/project #This is the location of the website folder
    npm i #could be composer install on PHP Platform
    ng build --prod # to build the project
    ```
  3. Add the repository as a remote on your project using the command
    ```shell
    git remote add deploy2server git@server.com:project.git
    ```

    Note: the git in git@server.com is a ssh user that requires ssh password to be able to push changes. It should be able to use npm in the deployment folders.
  4. Stage the changes using
    ```bash
    git add . 
    ```
  5. Commit the changes
    ```bash
    git commit -m "My Commit Message" -a
    ```
  6. Push the changes to the server
    ```bash
    git push --set-upstream deploy2server master
    ```
  7. VoilĂ , the site is always in sync with the master branch of your server repository

Categories : Blog, Git
Tags: There's No Tags For This Post

User Avatar
Yes Soft ( Yes Soft )

There Is No Biography


User Post Count: 22
User Profile Link: Yes Soft
« »

Comments Number :1 Comment


Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2020 Yes Soft - All right reserved.
Implemented By Yes Soft Team.