Hello everyone, today I want to share how I added my first CI/CD pipeline using YAML and Docker on AWS. First, I forked a React project on my GitHub because I didn’t want to waste time setting up React and adding a very simple app, so I decided to fork a project. Then I cloned that repository and added .dockerignore and Dockerfile files in my project’s root directory, and this is the code you can see in the screenshots:
After that, I created an EC2 instance to run my project and installed Docker. I added my Ubuntu user to Docker because Docker runs as root and the Ubuntu user doesn’t have access to that, so I added the user to the Docker group. Look at the screenshot I attached:
After that, I worked on the YAML for CI/CD. I created a .github folder in the root directory of my project, then created another folder called workflows, and in this folder I created a deploy.yml file. In this file, first I added the project name, after that I added on for when I push code to the main branch, then it triggers the action, and in the last I added my jobs. First, I used Ubuntu, then I checked out the code in that Ubuntu machine. After that, I copied this code to my EC2 machine, then SSH into my Ubuntu machine, then cd into my project, stop the running Docker container, build a new one, and run it. When I pushed the code, I saw my project was still not running, then I added an inbound rule in my EC2 machine because by default EC2 blocks other access points, so I added an inbound rule so everyone can access it.
Look at the YAML code screenshot and running project screenshot:




Top comments (0)