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:
- You build a function/ component/ service
- ng build –prod
- Zip the dest folder
- Upload to the server via ftp
- Unzip the folder
- Product assessment.
The Trick
- Build a server repository using the command on the home directory
```bash
git init --bare project.git
``` - 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
``` - 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. - Stage the changes using
```bash
git add .
``` - Commit the changes
```bash
git commit -m "My Commit Message" -a
``` - Push the changes to the server
```bash
git push --set-upstream deploy2server master
``` - VoilĂ , the site is always in sync with the master branch of your server repository
https://waterfallmagazine.com
Thanks for your personal marvelous posting! I actually enjoyed reading it,
you might be a great author.I will be sure to bookmark your blog and
will come back later on. I want to encourage yourself to continue your great job,
have a nice evening!