-
Notifications
You must be signed in to change notification settings - Fork 84
Dev CI CD
Here are the steps that need to be carried out during local development and testing of the dev CI/CD:
First, we need to clone our project repository in a directory/path accessible by everyone on the server for this server its /var/www/aihomework/dev
Next:
cd /var/www/
sudo mkdir aihomework
cd /var/www/aihomework
sudo git clone <project-url> dev
cd /var/www/aihomework/dev
Navigate to the project repository and install the necessary dependencies.
cd /var/www/aihomework/dev
sudo npm install -g yarn pnpm
yarn -v
sudo yarn install
sudo yarn start # (execution only needed for testing on dev)
sudo yarn build
On successful installation of the above commands, your application should be up and running and exposed to the default port 8080 using the server's IP address. (e.g., http://ipaddress:8080).
Moving on, we will proceed to write the dev.yml CI/CD workflow, and also create our aihomeworkprod.service file, startappprod.sh file which will be created under the server-script
directory in our hng_boilerplate_expressjs root directory.
aihomeworkprod.service
Copy code
[Unit]
Description=AIHomework-Prod
After=network.target
[Service]
WorkingDirectory=/var/www/aihomework/prod
ExecStart=/bin/bash /var/www/aihomework/prod/server-script/startappprod.sh
#Restart=on-failure
#RestartSec=20s
StartLimitInterval=0
[Install]
WantedBy=multi-user.target
#!/bin/bash
cd /var/www/aihomework/prod/
/usr/bin/yarn prod
Create and Configure GitHub Actions Workflow for dev.yml
on Push to Dev Branch
The below dev.yml
CI/CD workflow should be written on the dev branch and configured to trigger on push to the dev branch.
dev.yml
name: Build, Test, and Deploy for Dev Branch
on:
push:
branches:
- dev
jobs:
build:
runs-on: self-hosted
defaults:
run:
working-directory: /var/www/aihomework/dev
steps:
- name: Pull from github
id: pull
run: |
git pull origin dev
- name: Install dependencies
run: yarn install
- name: Run Test
run: yarn test --passWithNoTests
- name: Build the dist
run: yarn build
- name: Setup service file
run: sudo cp server-script/aihomeworkdev.service /etc/systemd/system
- name: Start the app
run: |
sudo systemctl daemon-reload
sudo systemctl restart aihomeworkdev
Effective collaboration requires adherence to the following best practices:
Synchronize code merges by ensuring the next team member to push a new code change is working with the most recent codebase. Always perform a git pull to update your local repository with remote changes before pushing any local commits.
During the course of this project, we encountered several challenges:
Frequent new commit merges from the backend team necessitated ongoing updates to the package.json file to ensure successful execution of our CI/CD workflows for both development and production on GitHub Actions.
Following the outlined installation steps and procedures has facilitated the smooth and efficient deployment of this project, ensuring a robust CI/CD workflow.