Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
verma-kunal committed Jan 17, 2023
1 parent bb074f4 commit e2ed6bd
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM node:18-alpine

# Setting up the environment variables needed:
ENV DOMAIN="http://13.235.151.196:3000" \
ENV DOMAIN="http://localhost:3000" \
PORT=3000 \
STATIC_DIR="./client" \
PUBLISHABLE_KEY="pk_test_51L5AsSSCC8JVWfvgEtfJkzHMTh7Z5PLY5m1yhR379sJgwAVZEe13NaiG33wsHSyHnPJMjTNOosiPk6AeMI8q0ims0049IKffiu" \
Expand Down
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,72 @@
# AWS Deployment Automation
Deployment automation on AWS using Jenkins CI/CD
# Deploying a Node Js Application on AWS EC2

### Testing the project locally

1. Clone this project
```
git clone https://github.com/verma-kunal/AWS-Session.git
```
2. Setup the following environment variables - `(.env)` file
```
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY=""
SECRET_KEY=""
```
3. Initialise and start the project
```
npm install
npm run start
```

### Set up an AWS EC2 instance

1. Create an IAM user & login to your AWS Console
- Access Type - Password
- Permissions - Admin
2. Create an EC2 instance
- Select an OS image - Ubuntu
- Create a new key pair & download `.pem` file
- Instance type - t2.micro
3. Connecting to the instance using ssh
```
ssh -i instance.pem ubunutu@<IP_ADDRESS>
```

### Configuring Ubuntu on remote VM

1. Updating the outdated packages and dependencies
```
sudo apt update
```
3. Install Git - [Guide by DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-22-04)
4. Configure Node.js and `npm` - [Guide by DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-22-04)

### Deploying the project on AWS

1. Clone this project in the remote VM
```
git clone https://github.com/verma-kunal/AWS-Session.git
```
2. Setup the following environment variables - `(.env)` file
```
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY=""
SECRET_KEY=""
```
> For this project, we'll have to set up an [Elastic IP Address](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html) for our EC2 & that would be our `DOMAIN`
3. Initialise and start the project
```
npm install
npm run start
```

> NOTE - We will have to edit the **inbound rules** in the security group of our EC2, in order to allow traffic from our particular port
### Project is deployed on AWS 🎉
2 changes: 1 addition & 1 deletion client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var btnWorshop3 = document.getElementById("work-3");

// __________________________________________________________________

var URL = "http://13.235.151.196:3000";
var URL = "http://localhost:3000";

btnWorshop1.addEventListener("click", function (e) {
e.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions client/cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ <h1>Error ⚠️</h1>

<script>
var btn = document.getElementById("try-again-btn");

var domain = "http://localhost:3000";
btn.addEventListener("click", function (e) {
e.preventDefault();

location.href = "http://13.235.151.196:3000";
location.href = domain;
});
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="container">
<div class="header">
<div class="title">
<h1>Welcome to Kubesimplify Workshops - AWS Server! </h1>
<h1>Welcome to Kubesimplify Workshops! </h1>
</div>
<p>
Kubesimplify is on a mission to simplify the cloud-native for everyone. <br><br>
Expand Down
3 changes: 2 additions & 1 deletion client/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ <h1>Success 🎉</h1>
});

var btn = document.getElementById("home-btn");
var domain = "http://localhost:3000";
btn.addEventListener("click", function (e) {
e.preventDefault();

location.href = "http://13.235.151.196:3000";
location.href = domain;
});
</script>
</body>
Expand Down
6 changes: 0 additions & 6 deletions docker-compose.yml

This file was deleted.

5 changes: 3 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ app.get("/workshop3", (req, res) => {

// ____________________________________________________________________________________

const domainURL = process.env.DOMAIN;
app.post("/create-checkout-session/:pid", async (req, res) => {
const domainURL = process.env.DOMAIN;

const priceId = req.params.pid;

const session = await stripe.checkout.sessions.create({
Expand All @@ -78,5 +79,5 @@ app.post("/create-checkout-session/:pid", async (req, res) => {
// Server listening:
app.listen(port, () => {
console.log(`Server listening on port: ${port}`);
console.log('You may access you app at: http://13.235.151.196:3000/');
console.log(`You may access you app at: ${domainURL}`);
});

0 comments on commit e2ed6bd

Please sign in to comment.