A Node.js project written using Express. EJS was used as the view engine.
You need to write the following commands on the terminal screen so that you can run the project locally.
1. git clone git@github.com:acemilyalcin/sample-node-project.git
2. cd sample-node-project
3. npm install
4. npm startThe application is running on localhost.
A Node.js project written using Express. EJS was used as the view engine.
This project includes a GitHub Actions workflow (ci.yml) to automate the build and deployment process. The workflow performs the following tasks:
- Checkout Code: Pulls the latest code from the repository.
- Set Up Docker: Configures Docker Buildx for building images.
- Push to DockerHub: Builds and pushes the Docker image to DockerHub.
- Push to AWS ECR: Builds and pushes the Docker image to AWS Elastic Container Registry (ECR).
-
Add the Workflow File
The workflow file is located at.github/workflows/ci.yml. Ensure it is added to your repository. -
Configure GitHub Secrets
Add the following secrets to your GitHub repository under Settings > Secrets and variables > Actions:DOCKERHUB_USERNAME: Your DockerHub username.DOCKERHUB_PASSWORD: Your DockerHub password or personal access token.AWS_ACCESS_KEY_ID: Your AWS access key ID.AWS_SECRET_ACCESS_KEY: Your AWS secret access key.AWS_REGION: The AWS region where your ECR repository is located (e.g.,us-east-1).AWS_ACCOUNT_ID: Your AWS account ID.
-
Create an ECR Repository
Ensure an ECR repository namedsample-node-projectexists in your AWS account. You can create it via the AWS Management Console or CLI. -
Trigger the Workflow
The workflow runs automatically on:- Pushes to the
mainbranch. - Pull requests targeting the
mainbranch.
You can also manually trigger the workflow from the Actions tab in your GitHub repository.
- Pushes to the
Follow these steps to run the project locally:
Run the following commands in your terminal:
# Clone the repository
git clone git@github.com:acemilyalcin/sample-node-project.git
# Navigate to the project directory
cd sample-node-project
# Install dependencies
npm install
# Start the application
npm startThe application will be running on http://localhost:3000.
To run the application using Docker:
-
Build the Docker image:
docker build -t sample-node-project . -
Run the Docker container:
docker run -p 3000:3000 sample-node-project
The application will be accessible at http://localhost:3000.
The CI/CD pipeline automatically builds and pushes the Docker image to:
- DockerHub:
${{ secrets.DOCKERHUB_USERNAME }}/sample-node-project:latest - AWS ECR:
<AWS_ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/sample-node-project:latest
Ensure your AWS ECR repository and DockerHub account are properly configured to receive the images.