Skip to content

Commit f1eab8d

Browse files
committed
add: ci/cd pipeline
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
1 parent b9dba56 commit f1eab8d

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

.github/workflows/ci-cd.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '14'
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Run build
25+
run: npm run build
26+
27+
- name: Docker login
28+
env:
29+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
30+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
31+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
32+
33+
- name: Build Docker image
34+
run: docker build -t sahilyeole/portfolio:latest .
35+
36+
- name: Push Docker image
37+
run: docker push sahilyeole/portfolio:latest
38+
39+
deploy:
40+
needs: build
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- name: Deploy to server via SSH
45+
uses: appleboy/ssh-action@master
46+
with:
47+
host: ${{ secrets.SSH_HOST }}
48+
username: ${{ secrets.SSH_USERNAME }}
49+
key: ${{ secrets.SSH_KEY }}
50+
script: |
51+
docker pull sahilyeole/portfolio:latest
52+
docker stop portfolio-container || true
53+
docker rm portfolio-container || true
54+
docker run -d --name portfolio-container -p 80:3000 sahilyeole/portfolio:latest
55+

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:14
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
7+
RUN npm install
8+
9+
COPY . .
10+
11+
RUN npm run build
12+
13+
EXPOSE 3000
14+
15+
CMD ["npm", "run", "dev"]
16+

0 commit comments

Comments
 (0)