-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added deploy workflow & dockerfile for both frontend and backend
- Loading branch information
Showing
8 changed files
with
146 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
Oops, something went wrong.