From d00ab3529da479e90ce76b87768f1a2c28f883d5 Mon Sep 17 00:00:00 2001 From: Puneet NJ Date: Fri, 17 Jan 2025 17:10:09 +0530 Subject: [PATCH] Checking deployment pipeline for frontend and backend --- .github/workflows/deploy.yml | 46 +++++++++++++++--------------------- Dockerfile.frontend | 22 ----------------- backend/src/index.ts | 2 +- frontend/src/utils/lib.ts | 2 +- nginx.conf | 16 ------------- 5 files changed, 21 insertions(+), 67 deletions(-) delete mode 100644 Dockerfile.frontend delete mode 100644 nginx.conf diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c584efe..c159d4a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,16 +13,16 @@ jobs: uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 # Added for better build performance + uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - uses: docker/login-action@v3 # Updated to v3 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and Push Backend Docker image - uses: docker/build-push-action@v5 # Updated to v5 + uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile.backend @@ -38,28 +38,14 @@ jobs: AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} CDN_LINK=${{ secrets.CDN_LINK }} - - - name: Build and Push Frontend Docker image - uses: docker/build-push-action@v5 # Updated to v5 - with: - context: . - file: ./Dockerfile.frontend - push: true - tags: puneetnj/course-app-fe:latest - platforms: linux/amd64,linux/arm64 - cache-from: type=registry,ref=puneetnj/course-app-fe:latest - cache-to: type=inline + CF_PUBLIC_KEY=${{ secrets.CF_PUBLIC_KEY }} + CF_PRIVATE_KEY=${{ secrets.CF_PRIVATE_KEY }} - name: Verify Backend Image run: | docker pull puneetnj/course-app-be:latest docker image inspect puneetnj/course-app-be:latest - - name: Verify Frontend Image - run: | - docker pull puneetnj/course-app-fe:latest - docker image inspect puneetnj/course-app-fe:latest - - name: Deploy to EC2 uses: appleboy/ssh-action@master with: @@ -72,6 +58,19 @@ jobs: sudo docker rm course-app-be || true sudo docker run -d --name course-app-be -p 4000:4000 puneetnj/course-app-be:latest + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Install Frontend Dependencies + working-directory: ./frontend # Adjust this path based on your project structure + run: npm install + + - name: Build Frontend + working-directory: ./frontend # Adjust this path based on your project structure + run: npm run build + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -79,14 +78,7 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_REGION }} - - name: Pull and Extract Frontend Assets - run: | - docker pull puneetnj/course-app-fe:latest - docker create --name temp_container puneetnj/course-app-fe:latest - docker cp temp_container:/usr/share/nginx/html/. ./dist - docker rm temp_container - - name: Deploy to S3 run: | - aws s3 sync dist s3://${{ secrets.S3_BUCKET }} --delete + aws s3 sync frontend/dist s3://${{ secrets.S3_BUCKET }} --delete aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" diff --git a/Dockerfile.frontend b/Dockerfile.frontend deleted file mode 100644 index 9044df7..0000000 --- a/Dockerfile.frontend +++ /dev/null @@ -1,22 +0,0 @@ -FROM node:18-alpine AS builder - -WORKDIR /app/frontend - -COPY ./frontend/package*.json ./ - -RUN npm install - -COPY ./frontend . - -RUN npm run build - -# Production runtime -FROM nginx:alpine AS production - -COPY --from=builder /app/frontend/dist /usr/share/nginx/html - -COPY nginx.conf /etc/nginx/conf.d/default.conf - -EXPOSE 5173 - -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/backend/src/index.ts b/backend/src/index.ts index 56bc6be..2b1d9d0 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -9,7 +9,7 @@ app.use(cookieParser()); app.use(express.json()); app.use( cors({ - origin: "http://localhost:5174", + origin: "https://course-app.puneetnj.fun", credentials: true, methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], allowedHeaders: ["Content-Type", "Authorization"], diff --git a/frontend/src/utils/lib.ts b/frontend/src/utils/lib.ts index e430bfd..fd6d87b 100644 --- a/frontend/src/utils/lib.ts +++ b/frontend/src/utils/lib.ts @@ -15,7 +15,7 @@ export const BLOCKCHAIN_COHORT_URL = export const COHORT2_URL = "https://appxcontent.kaxa.in/subject/2024-07-05-0.3715048534115637.jpeg"; -export const BACKEND_URL = "http://localhost:4000/api/v1"; +export const BACKEND_URL = "https://course-app-be.puneetnj.fun/api/v1"; export const ABOUT_CONTENT1 = "Welcome to 100xdevs."; diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index ccd7a26..0000000 --- a/nginx.conf +++ /dev/null @@ -1,16 +0,0 @@ -server { - listen 5173; - server_name localhost; - - location / { - root /usr/share/nginx/html; - index index.html; - try_files $uri $uri/ /index.html; - } - - location /assets { - root /usr/share/nginx/html; - expires 1y; - add_header Cache-Control "public, no-transform"; - } -} \ No newline at end of file