This is a Express Rest API. I'm trying here to run a CI/CD pipeline starting from building the docker image till deploying the container to AWS EC2 Ubuntu instance every time I push updates to the Main branch. Here are the steps:
Continuous Integration (CI) โ
Checkout code.
Login to dockerhub.
Build docker image that contains the Express Rest API and tag it with the commit sha.
Push the docker image to dockerhub.
Continuous Deployment (CD) ๐
Stop running docker containers.
Delete existing docker images.
Pull docker image that contains the Express Rest API.
Run docker container and expose port 3000.
Getting Started โถ๏ธ
Setup AWS EC2 Ubuntu Runner โ๏ธ
visit https://github.com/<username>/<repo-name>/settings/actions/runners
click "New self-hosted runner"
choose runner image & architecture from the options macOS, Linux and Windows.
follow the commands (with the normal user **"ubuntu"** and not the root user)
Setup AWS EC2 Ubuntu Runner Service โ๏ธ
# do the following (with the normal user **"ubuntu"** and not the root user) to enable the ec2 instance to listen to the jobs triggered by the workflow.# micro is a terminal-text-editor, to install it, run this command "sudo apt install micro"
sudo micro /etc/systemd/system/github-runner.service
# Content of the file
[Unit]
Description=GitHub Actions Self-hosted Runner
After=network.target
[Service]
WorkingDirectory=/home/ubuntu/actions-runner
ExecStart=/home/ubuntu/actions-runner/run.sh
Restart=always
Environment="RUNNER_ALLOW_RUNASROOT=1"# Add this line if required
[Install]
WantedBy=multi-user.target
# End of file's content# then run
sudo systemctl enable github-runner
sudo systemctl start github-runner
sudo systemctl status github-runner.service
Contribution ๐ค
If you're interested in contributing to this project, please follow these guidelines: