Skip to content

Commit 227cd2b

Browse files
aws ec2 deployment
1 parent 76ca8b2 commit 227cd2b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.github/workflows/cicd.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Deploy Node Application
2+
3+
on:
4+
push:
5+
branches:
6+
- mern-ec2-docker-ssl
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Source
13+
uses: actions/checkout@v4
14+
- name: Login to docker hub
15+
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
16+
- name: Build Docker Image
17+
run: docker build -t integrationninjas/nodejs-app .
18+
- name: Publish Image to docker hub
19+
run: docker push integrationninjas/nodejs-app:latest
20+
21+
deploy:
22+
needs: build
23+
runs-on: self-hosted
24+
steps:
25+
- name: Pull image from docker hub
26+
run: docker pull integrationninjas/nodejs-app:latest
27+
- name: Delete old container
28+
run: docker rm -f nodejs-app-container
29+
- name: Run Docker Container
30+
run: docker run -d -p 4000:4000 --name nodejs-app-container -e MONGO_PASSWORD='${{ secrets.MONGO_PASSWORD }}' integrationninjas/nodejs-app

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:alpine3.18
2+
WORKDIR /app
3+
COPY package.json ./
4+
RUN npm install
5+
COPY . .
6+
EXPOSE 4000
7+
CMD [ "npm", "run", "start" ]

0 commit comments

Comments
 (0)