Skip to content

Commit

Permalink
added deploy workflow & dockerfile for both frontend and backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneet-NJ committed Jan 4, 2025
1 parent 6de82b4 commit 500b7d5
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 516 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build and Deploy to Docker Hub

on:
push:
branches:
- main

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4 # Updated to v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 # Added for better build performance

- name: Log in to Docker Hub
uses: docker/login-action@v3 # Updated to 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
with:
context: .
file: ./Dockerfile.backend
push: true
tags: puneetnj/course-app-be:latest
cache-from: type=registry,ref=puneetnj/course-app-be:latest
cache-to: type=inline
build-args: |
DATABASE_URL=${{ secrets.DATABASE_URL }}
USER_JWT_PASSWORD=${{ secrets.USER_JWT_PASSWORD }}
ADMIN_JWT_PASSWORD=${{ secrets.ADMIN_JWT_PASSWORD }}
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
cache-from: type=registry,ref=puneetnj/course-app-fe:latest
cache-to: type=inline

- 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
33 changes: 33 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:18-bullseye

WORKDIR /app/backend

# Define build arguments
ARG DATABASE_URL
ARG USER_JWT_PASSWORD
ARG ADMIN_JWT_PASSWORD
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG CDN_LINK

# Set them as environment variables
ENV DATABASE_URL=$DATABASE_URL
ENV USER_JWT_PASSWORD=$USER_JWT_PASSWORD
ENV ADMIN_JWT_PASSWORD=$ADMIN_JWT_PASSWORD
ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
ENV CDN_LINK=$CDN_LINK

COPY ./backend/package*.json ./

RUN npm install

COPY ./backend ./

RUN npx prisma generate

EXPOSE 4000

RUN npm run build

CMD ["npm", "run", "start"]
22 changes: 22 additions & 0 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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;"]
Loading

0 comments on commit 500b7d5

Please sign in to comment.