File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # .github/workflows/cicd.yml
2+
3+ name : Deploy Budget Tracker FE to EC2
4+
5+ on :
6+ push :
7+ branches :
8+ - main
9+
10+ jobs :
11+ build :
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : Checkout code
15+ uses : actions/checkout@v4
16+
17+ - name : Login to Docker Hub
18+ run : docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
19+
20+ - name : Build Docker Image
21+ run : |
22+ docker build \
23+ --build-arg VITE_EC2_BACKEND_URL=${{ secrets.VITE_EC2_BACKEND_URL }} \
24+ -t dilusharanasinghe/budget-tracker-fe:latest .
25+
26+ - name : Push Docker Image
27+ run : docker push dilusharanasinghe/budget-tracker-fe:latest
28+
29+ deploy :
30+ needs : build
31+ runs-on : [aws-EC2-budget-tracker-frontend]
32+ steps :
33+ - name : Pull Docker image
34+ run : docker pull dilusharanasinghe/budget-tracker-fe:latest
35+
36+ - name : Remove old container if exists
37+ run : docker rm -f budget-tracker-fe-container || true
38+
39+ - name : Run container on port 3000
40+ run : docker run -d -p 3000:80 --name budget-tracker-fe-container dilusharanasinghe/budget-tracker-fe:latest
Original file line number Diff line number Diff line change 1+ # Dockerfile
2+
3+ # Step 1: Build the React app
4+ FROM node:20 AS build
5+
6+ WORKDIR /app
7+
8+ # Copy project files
9+ COPY . .
10+
11+ # Pass environment variable at build time
12+ ARG VITE_EC2_BACKEND_URL
13+ ENV VITE_EC2_BACKEND_URL=$VITE_EC2_BACKEND_URL
14+
15+ # Install dependencies and build
16+ RUN npm install && npm run build
17+
18+ # Step 2: Serve with NGINX
19+ FROM nginx:alpine
20+
21+ # Copy build output to nginx html folder
22+ COPY --from=build /app/dist /usr/share/nginx/html
23+
24+ # Replace default nginx config
25+ COPY nginx.conf /etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change 1+ # nginx.conf
2+
3+ server {
4+ listen 80 ;
5+ server_name _;
6+
7+ root /usr/share/nginx/html;
8+ index index .html index .htm;
9+
10+ location / {
11+ try_files $uri $uri / /index .html;
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments