To allow us to continously deploy a application. In this example we will use the Angular application:
https://github.com/RyanKruger1/cx-forex/tree/master/forex-website
To create a pipeline we need to document the sequence of steps that we do to deploy it currently. Therefore lets lay out the various steps.
git clone
docker build .
docker tag
docker push
helm uninstall <#application-name>
helm install <#application-name>
Now that we outlined the various steps that we need we need to setup a runner.
These are normally dependend on the technology we are going to use. We have a choice of:
Each one of these have their own setup of runners. Since we already used github to host the .git. We will try and do it using github actions.
For using github you will need to setup a runner(This could be one of their servers or a self hosted runner). We choose self hosted since we don't want to keep reinstalling the technologies we need and it is safer.
Setting it up is straight forward since they provide all the commands that are required can be found on their wiki.
https://github.com/RyanKruger1/cx-forex/settings/actions/runners/new
After all their steps are followed. You can start a background service to have a runner run in the background:
ls # You should see a .svc.sh file
sudo ./svc.sh install
sudo ./svc.sh start
Then create a .gihub folder with all the bash commands. You will also need to configure the trigger and on which runners the action should run.
name: Run Bash Script
on:
push:
branches:
- master
jobs:
build:
runs-on: self-hosted # or "ubuntu-latest" if using GitHub-hosted runner
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Bash Commands
run: |
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
sudo chmod a+r /etc/rancher/k3s/k3s.yaml
IMAGE_TAG="main-${GITHUB_SHA::7}"
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
cd forex-website
docker rmi forex-website || true
docker build . -t forex-website -f DockerFile
docker tag forex-website registry.kroup.xyz/forex-website:$IMAGE_TAG
docker push registry.kroup.xyz/forex-website:$IMAGE_TAG
helm uninstall forex-website || true
helm install forex-website helm --set image.tag=$IMAGE_TAG