This repository is a guideline for creating repositories to use in projects and this is a guide on how to create it and use it. This quide explains step-by-step creating an GitHub account,creating an organization to group many projects together, downloading and installing the necessary software for each member and finally creating a CI/CD pipeline to use when creating a new piece of software and deploying it on a server.
Each member of the project must have a GitHub account you can create one here by entering your information and your preferences.The next step is to create an Organiztion in GitHub to organize your projects and you members in teams for easier control (this is for administrators).
To create an Organization you can Sign In on your GitHub account and then going into Settings -> Organizations -> New Organization. In the new page that opens you can choose your plan. The Free plan has almost all the functionality we will use in this case except you cannot use Code Owners (more on that later). Once you choose your plan then you have to choose a name for you Organization and who owns this Organization and then your Organization is Created. The person that created the organization is the Organization Owner. Generally inside a GitHub Organization everyone has one role from the following
After an Organization is created you can invite people ot your organization by going to your Organization Home Page -> People -> Invite member and searching by their GitHub username. Once you choose one you can send the invitation and an email will be sent to them.
Once you have invited everyone that you want to be part of you organization you can start creating Teams to divide people in groups depending on their role in a project. To create a team you can go to your Organization Home Page -> Teams -> New team and then choose the details for each Team. Once you create a Team you can go to your Teams page form your Organization Home Page and select the Team and Add a member you want to be part of the team.
After you have create all the teams you need and added all the members you can start Creating new repositories by going to your Organization Home Page -> Repositories -> New Repository and filling out the details for the new repository. When you create a new repository you can find it in the Repositories page and by selecting you can see all the information about it.
To select a team to work a repository you can go to the Teams Page and select a team. Then on the team's page you can go to Repositories and add a repository from those you have created. Additionally you can change the permissionsthat each team's members have on a repository by going to the team's Repository Pgae and choosing from the drop-down list one of the following:
GitHub has a feature called Projects which is a way to manage tasks and has a direct connection with the repositories Issues. You can create a new Project by going to the Organization Home Page -> Porjects -> New Project and selecting the view you want the project to have. After creating a Project you can go to the projects Page select a project and then go to the settings from the three-dot man on the top right where you can manage who has access to this project and who can view it.
Once you have a GitHub account the next step is preping your computer. You will need two applications Git and TortoiseGit.
You can download the correct version for your computer of Git from here and then run the installation Wizard you downloaded. Follow the steps in the Installation Wizard without changing anything (unless you know for sure what you are doing) and then press Install. You can use Git from the command line or by opening Git Bash but this is not necessary because everyone can use the application TortoiseGit that we will install below which is essentially a plugin for the Windows File Explorer.
The developers of the project can download Visual Studio Code which has a very good integration with Git and is very easy to use with many extensions. If you dont want to use Visual Studio Code and the IDE of your choice does not have an integration with Git you can download TortoiseGit by following the guide below. You can download the correct version for your computer of Visual Studio Code from here and then run the installation Wizard you downloaded. Follow the steps in the Installation Wizard without changing anything (unless you know for sure what you are doing) and then press Install.
If you don't want to use git or Visual Studio Code to make changes to the project, for example if you are not a developer, you can use TortoiseGit which is a plugin for Windows File Explorer and is really easy to install and use. You can download the correct version for your computer of TortoiseGit from here and then run the installation Wizard you downloaded. Follow the steps in the Installation Wizard without changing anything (unless you know for sure what you are doing) and then press Install. Once installed in File Explorer when you right click another optoin should appear called TortoiseGit and you can choose to clone a repository from GitHub by copying the URL of the repository and pasting in the dialog. Additionally you can check the box that says Branch and write the name of the branch that you want to download (in the Pipeline section of this guide you can see what branches are and how you can use them). Once you do that all the files from that branch will be downloaded and will appear in the folder.
The pipeline is the procedure we follow to create new projects and change existing ones. The pipeline we use is made of four steps : Build -> Test -> Package -> Deploy.
This is the step that we create new software, we make changes to old, we write the documentation and we generally work on our project. The building step in our pipeline is also managed with GitHub where we can make changes in a controlled enviroment without risking the functionality of older versions. In Github and other Version Control Systems we can separate our work in Branches. Each branch is a version of our project and we can work on one Branch without affecting the others. In our case and in most cases there is a main branch where we have the latest stable version of our project. The main branch is the one we see when we open our GitHub repository and we don't make any changes to it directly. When someone wants to make a change in our project (or many changes) the correct way is to create a new branch make changes there and when we are done we can create a pull request to merge the branch we have created with the main branch.
To make a change in th Project everyone has to follow these steps :
The next step in the pipeline is testing and this primarly involves the developers. When the code changes we have to amke sure it works like it is supposed to before we continue to package and deploy it. For that reason every developer should create tests (unit, performance, etc) while writing the code and when it is finished the tests are run automatically with GitHub Actions and if something fails it can't be merged to main. It is very important to create tests that cover every aspect of the software to find as many bugs as we can.
The packaging step is reffered to making our source code an executable (compile,containerize,...).This step is automatically triggered when a change is push to the main branch. The packaging can be done in multiple ways which are briefly explained below:
The deployment step is the final step of the pipeline and there are numerous ways to implement. The easiest way is to deploy our application in AWS using a serverless architecture which means that our organizations doesn't need to maintain a server on-premises or worry about scaling. The most popular way of deployment is on a server on-premises which gives us total control of our architecture but also total responsibility of maintaining and updating the server which can result in unexpected costs. Deploying an application is easy when packaging is done correctly. For example if we have a docker image the only thing we need is to install the Docker Engine in our server and then create a new container from our image. Similarly if we have an executable file we just have to run it.
TO implement our application using a microservices application is a very popular option nowadays and comes with many benefits. When we use a microservices architecture everu component is independent from the others and changes can be made to one without affecting the others. When we use a microservices architecture is very common to use Docker for our deployment where each component is represented by a docker image. To deploy and manage the containers that run our images most of the times Kubernetes is used which is a managing software that can be used to manage a cluster of nodes where each node runs pods (like containers) and everything seems to be a unique server when in reality there are many servers working closely with eachother. At least one node in every cluster is a Master Node which is used to manage the whole cluster and is the command center for the whole cluster. Kubernetes need at least two nodes (servers/VMs/computers) to be set up, a Master Node and a Worker node. Also there are tools like Minikube that create a virtual cluster with little hardware requirements so that developers and DevOps engineers can test their deployments before the deploy it on an actual cluster.
This repository is a sample case for all af the above. The steps we took are as follow:
To implement the above pipeline we use the following code. We use three actions:
name: Deploy Main Branch
on:
push:
branches: main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 20
- name: Install Dependencies
run: npm ci
- name: Build Application
run: npm run build
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 20
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test
name: Build and Test
on:
push:
branches-ignore:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 20.x
- name: Install packages and build
run: |
npm ci
npm run build --if-present
- name: Test the build
run: npm test
#!/bin/bash
git clone https://github.com/Uni-Systems-SMSA/DevOps_Sample_Case.git
cd /root/DevOps_Sample_Case git checkout main git pull
docker build -t 172.30.1.224:5050/devops-sample:$1 -t 172.30.1.224:5050/devops-sample:latest .
docker push 172.30.1.224:5050/devops-sample --all-tags
4. The script for deploying our new versions every time we want :
```shell
kill $(lsof -t -i:3001)
kubectl set image deployments/frontend-deployment frontend=172.30.1.224:5050/devops-sample:$1
sleep 10
kubectl port-forward --address=0.0.0.0 services/frontend-load 3001:3001 &
kubectl port-forward --address=0.0.0.0 services/keycloak-service 8080 &