Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/practika.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build and Publish

on:
push:
branches: [ "practika-develop" ]

jobs:
build-server:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push Server
uses: docker/build-push-action@v4
with:
context: ./server
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/eduplatform-server:latest

build-web:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push Web
uses: docker/build-push-action@v4
with:
context: ./frontend
file: frontend/packages/web/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/eduplatform-web:latest

build-admin:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push Admin
uses: docker/build-push-action@v4
with:
context: ./frontend
file: frontend/packages/admin/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/eduplatform-admin:latest
61 changes: 61 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: '3.8'

services:
db:
image: postgres:15-alpine
container_name: edu_postgres
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword
POSTGRES_DB: mydb
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U myuser -d mydb"]
interval: 5s
timeout: 5s
retries: 5
restart: always

server:
build: ./server
container_name: edu_server
ports:
- "3000:3000"
environment:
DATABASE_URL: "postgresql://myuser:mypassword@db:5432/mydb?schema=public"
PORT: 3000
JWT_SECRET: "super-secret"
depends_on:
db:
condition: service_healthy
command: >
sh -c "npx prisma migrate deploy && node dist/main.js"
restart: always

web:
build:
context: ./frontend
dockerfile: packages/web/Dockerfile
container_name: edu_web
ports:
- "8080:80"
depends_on:
- server
restart: always

admin:
build:
context: ./frontend
dockerfile: packages/admin/Dockerfile
container_name: edu_admin
ports:
- "8081:80"
depends_on:
- server
restart: always

volumes:
postgres_data:
28 changes: 28 additions & 0 deletions frontend/packages/admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:20-alpine AS builder
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app

COPY package.json ./

RUN echo "packages:" > pnpm-workspace.yaml && \
echo " - 'packages/*'" >> pnpm-workspace.yaml

COPY package.json ./

RUN echo "packages:" > pnpm-workspace.yaml && \
echo " - 'packages/*'" >> pnpm-workspace.yaml

RUN echo "link-workspace-packages=true" > .npmrc && \
echo "prefer-workspace-packages=true" >> .npmrc && \
echo "shamefully-hoist=true" >> .npmrc

COPY packages ./packages

RUN pnpm install

RUN pnpm --filter admin build

FROM nginx:alpine
COPY --from=builder /app/packages/admin/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion frontend/packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint ."
},
Expand Down
25 changes: 25 additions & 0 deletions frontend/packages/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:20-alpine AS builder
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app

COPY package.json ./

RUN echo "packages:" > pnpm-workspace.yaml && \
echo " - 'packages/*'" >> pnpm-workspace.yaml

RUN echo "link-workspace-packages=true" > .npmrc && \
echo "prefer-workspace-packages=true" >> .npmrc && \
echo "shamefully-hoist=true" >> .npmrc

COPY packages ./packages

RUN ls -la packages/ui/package.json

RUN pnpm install

RUN pnpm --filter web build

FROM nginx:alpine
COPY --from=builder /app/packages/web/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion frontend/packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint ."
},
Expand Down
72 changes: 72 additions & 0 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 10 additions & 15 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
FROM node:20-alpine AS base

# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app

COPY package.json package-lock.json* ./
RUN npm ci

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Generate Prisma Client
RUN npx prisma generate

RUN npm run build

# Production image, copy all the files and run nest
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN apk add --no-cache libc6-compat openssl

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nestjs

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/package.json ./package.json
COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist
COPY --from=builder --chown=nestjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nestjs:nodejs /app/package.json ./package.json

RUN chown -R nestjs:nodejs /app

USER nestjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "dist/main.js"]




CMD ["node", "dist/main.js"]