From 03b41e9cfc1d465d520811db11197654a107c5a4 Mon Sep 17 00:00:00 2001 From: vaibhav7500 Date: Mon, 15 Apr 2024 22:55:07 +0530 Subject: [PATCH] Improvements --- Dockerfile | 38 +++++-- README.md | 32 ++---- backend/.dockerignore | 1 + backend/.env_sample | 10 +- backend/Dockerfile | 7 +- backend/app.js | 2 +- backend/package.json | 2 +- build.sh | 5 - deploy.sh | 27 ----- docker-compose.local.yaml | 8 ++ ...mpose.yaml => docker-compose.override.yaml | 16 ++- docker-compose.yaml | 12 ++ docker-compose.yml | 32 ------ frontend/.dockerignore | 1 + frontend/.env_sample | 20 +--- frontend/Dockerfile | 16 +-- install-build.sh | 6 - local.sh | 1 + package-lock.json | 105 ------------------ setup.sh | 2 + start.sh | 1 + 21 files changed, 100 insertions(+), 244 deletions(-) create mode 100644 backend/.dockerignore delete mode 100644 build.sh delete mode 100644 deploy.sh create mode 100644 docker-compose.local.yaml rename backend/docker-compose.yaml => docker-compose.override.yaml (53%) create mode 100644 docker-compose.yaml delete mode 100644 docker-compose.yml create mode 100644 frontend/.dockerignore delete mode 100644 install-build.sh create mode 100644 local.sh delete mode 100644 package-lock.json create mode 100644 setup.sh create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile index e24ca5b..baffa6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,31 @@ -FROM node:16 +FROM node:20-alpine as frontend-builder + +RUN apk app update && apk upgrade && \ + apk add --no-cache bash git openssh + WORKDIR /app -COPY . . -WORKDIR /app/backend -RUN npm ci -WORKDIR /app/frontend -RUN npm ci + +COPY ./frontend/ . + +RUN npm install --silent + +RUN npm install react-scripts@3.4.1 -g --silent + +RUN npm run build + + + +FROM node:20-alpine + +RUN apk update && apk upgrade && \ + apk add --no-cache bash git openssh WORKDIR /app -RUN sh ./build.sh -WORKDIR /app/backend -EXPOSE 8080 -CMD ["node", "app.js"] \ No newline at end of file + +COPY ./backend/ . +COPY --from=frontend-builder /app/build ./build + +RUN npm ci + +EXPOSE 4200 +CMD ["node", "app.js"] diff --git a/README.md b/README.md index 8fb5737..1f1c5f4 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,7 @@ ![Cover Page](./images/cover.png)

-# Demo - -URL: https://anime-web-app.herokuapp.com/ +# Test Account Email: test@test.com @@ -18,7 +16,17 @@ Password: Hello@123 # [Screenshots](#screenshots) -# Installation + +## Quick Demo + +Requirements: Docker & Docker Compose + +``` + +sh setup.sh && sh start.sh +``` + +# Development ## Requirements @@ -26,9 +34,6 @@ Password: Hello@123 * Node - Setup Node from [here](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) -* Self Signed SSL - [here](https://zeropointdevelopment.com/how-to-get-https-working-in-windows-10-localhost-dev-environment/) - -* Redis - [here](https://linuxize.com/post/how-to-install-and-configure-redis-on-ubuntu-18-04/) ## Backend: * Install packages required. @@ -37,19 +42,6 @@ Password: Hello@123 cd backend npm install ``` -* Check for MySQL - ``` - which mysqld - ``` - If it shows the path then continue otherwise install MySQL. -* Create a config folder and copy config files in that folder - -* Create a certificate folder and copy the self signed certificate over there. - -* Create Database - ``` - npm run db - ``` * Crate a .env file and copy the required content. * Start Server diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/backend/.env_sample b/backend/.env_sample index 311a312..6f407e2 100644 --- a/backend/.env_sample +++ b/backend/.env_sample @@ -1,10 +1,8 @@ -ENV=dev -CORS_ORIGIN=http://localhost:3000 +CORS_ORIGIN=http://0.0.0.0:3000 PORT=4200 -BASE_URL=http://localhost:4200 +BASE_URL=http://0.0.0.0:4200 UPLOAD_DIR="./public/videos" -HOST=localhost -NODE_ENV=dev +HOST=0.0.0.0 RAZORPAY_KEY_ID=optional RAZORPAY_KEY_SECRET=optional SENDGRID_KEY=optional @@ -12,6 +10,6 @@ SESSION_KEY=_abcd SESSION_SECRET=1234 DB_USER=root DB_PASS=pwd -DB_HOST=localhost +DB_HOST=db DB=animeApp DB_PORT=3306 diff --git a/backend/Dockerfile b/backend/Dockerfile index 0560248..12560a0 100755 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,4 +1,7 @@ -FROM node:16 +FROM node:20-alpine + +RUN apk update && apk upgrade && \ + apk add --no-cache bash git openssh WORKDIR /app @@ -6,7 +9,7 @@ COPY . . RUN npm ci -EXPOSE 8080 +EXPOSE 4200 CMD ["node", "app.js"] diff --git a/backend/app.js b/backend/app.js index 9c7dfbc..bd70d0e 100644 --- a/backend/app.js +++ b/backend/app.js @@ -44,7 +44,7 @@ if(process.env.NODE_ENV === "production"){ })) }else { global.redis = redis.createClient({ - host: 'localhost', + host: 'redis', port: 6379, }); global.redis.on('error', (err) => { diff --git a/backend/package.json b/backend/package.json index dcb34d9..6f55d1d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -50,6 +50,6 @@ "ws": "^7.5.9" }, "engines": { - "node": "14.x" + "node": "20.x" } } diff --git a/build.sh b/build.sh deleted file mode 100644 index 3e91115..0000000 --- a/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -cd frontend -rm -rf build || true -npm run build -rm -rf ../backend/build || true -cp -R build ../backend/ diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index e8381c2..0000000 --- a/deploy.sh +++ /dev/null @@ -1,27 +0,0 @@ -echo "Stopping Server" -forever stopall || true -echo "Setting Permissions" -git remote set-url origin git@github.com:VAIBHAV7500/anime_web_app.git -echo "Pulling repository" -git status -echo "Stashing Current Changes" -git stash -echo "Fetching Data" -git fetch -echo "Pulling Data" -git pull - -cd frontend -echo "Installing Frontend Packages" -npm install -cd ../backend -echo "Installing Backend Packages" -npm install -echo "Creating Tables & Mirgartions" -npm run db -echo "Building Frontend" -cd .. -sh build.sh -echo "Creating Server" -cd backend -forever start app.js diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml new file mode 100644 index 0000000..3d8b245 --- /dev/null +++ b/docker-compose.local.yaml @@ -0,0 +1,8 @@ +version: "3.7" +services: + app: + build: + context: . + dockerfile: Dockerfile + + diff --git a/backend/docker-compose.yaml b/docker-compose.override.yaml similarity index 53% rename from backend/docker-compose.yaml rename to docker-compose.override.yaml index 4968a4c..8d2f6ac 100644 --- a/backend/docker-compose.yaml +++ b/docker-compose.override.yaml @@ -4,7 +4,12 @@ services: image: mysql:8.0 volumes: - mysql_data:/var/lib/mysql - - ./animeApp.sql:/docker-entrypoint-initdb.d/dump.sql + - ./backend/animeApp.sql:/docker-entrypoint-initdb.d/dump.sql + healthcheck: + test: mysqladmin ping --user=$MYSQL_USER --password=$MYSQL_ROOT_PASSWORD + interval: 10s + timeout: 5s + retries: 100 environment: MYSQL_DATABASE: animeApp MYSQL_ROOT_PASSWORD: pwd @@ -23,6 +28,13 @@ services: PMA_PORT: 3306 ports: - "8080:80" + + app: + depends_on: + db: + condition: service_healthy + redis: + condition: service_started volumes: - mysql_data: {} + mysql_data: {} \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a01626d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +version: "3.7" +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "4200:4200" + environment: + NODE_ENV: production + ENV: production + diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index fb72428..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: "3" - -services: - server: - build: ./ - ports: - - "8080:8080" - depends_on: - - db - - redis - container_name: backend - - db: - container_name: mysql - image: mysql:8.0.11 - volumes: - - "db_data:/var/lib/mysql" - restart: always - ports: - - 3336:3306 - environment: - MYSQL_ROOT_PASSWORD: 'trailblazer' - MYSQL_DATABASE: 'animeApp' - - redis: - container_name: redis - image: redis:6.0 - ports: - - 6379:6379 - -volumes: - db_data: \ No newline at end of file diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/frontend/.env_sample b/frontend/.env_sample index 9ff4337..7602cf4 100644 --- a/frontend/.env_sample +++ b/frontend/.env_sample @@ -1,23 +1,9 @@ -REACT_APP_BASE_URL=http://192.168.2.7:4200/ +REACT_APP_BASE_URL=http://localhost:4200/ REACT_APP_API_KEY=Kp4mJvZ7XDluaVsDkKIchQVIuYWIJo3l -REACT_APP_SERVER_URL=http://192.168.2.7:4200/ -REACT_APP_WEBSOCKET_URL=ws://192.168.2.7:4200 +REACT_APP_SERVER_URL=http://localhost:4200/ +REACT_APP_WEBSOCKET_URL=ws://localhost:4200 REACT_PRIVATE_KEY=123 REACT_APP_TINY_API_KEY=l1ogtgyej2icbacskxgja5mh74iygkxad8bmprn8qz5k0s7k REACT_APP_HCAPTCHA_SITE_KEY=10000000-ffff-ffff-ffff-000000000001 PORT=3000 -PUBLIC_URL=https://dev.animei.tv/ INLINE_RUNTIME_CHUNK=false - - -REACT_APP_BASE_URL=http://animeistag.net/ -REACT_APP_API_KEY=Kp4mJvZ7XDluaVsDkKIchQVIuYWIJo3l -REACT_APP_SERVER_URL=http://animeistag.net/ -REACT_APP_WEBSOCKET_URL=ws://animeistag.net -REACT_PRIVATE_KEY=123 -REACT_APP_TINY_API_KEY=l1ogtgyej2icbacskxgja5mh74iygkxad8bmprn8qz5k0s7k -REACT_APP_HCAPTCHA_SITE_KEY=5f9da22f-a8bc-482b-9a0f-a29f06ef875c -PORT=3000 -PUBLIC_URL=http://animeistag.net/ -INLINE_RUNTIME_CHUNK=false - diff --git a/frontend/Dockerfile b/frontend/Dockerfile index c5cf5ce..11b00b3 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,13 +1,9 @@ -FROM node:16 +FROM node:20-alpine WORKDIR /app COPY . . -WORKDIR /app/backend -RUN npm install -WORKDIR /app/frontent -RUN npm install -WORKDIR /app -RUN sh ./build.sh -WORKDIR /app/backend -EXPOSE 8080 -CMD ["node", "app.js"] \ No newline at end of file +RUN npm install --silent +RUN npm install react-scripts@3.4.1 -g --silent + +EXPOSE 3000 +CMD ["npm", "start"] \ No newline at end of file diff --git a/install-build.sh b/install-build.sh deleted file mode 100644 index 1a4f7f1..0000000 --- a/install-build.sh +++ /dev/null @@ -1,6 +0,0 @@ -cd frontend -rm -rf build || true -npm ci -npm run build -rm -rf ../backend/build || true -cp -R build ../backend/ diff --git a/local.sh b/local.sh new file mode 100644 index 0000000..70f3daa --- /dev/null +++ b/local.sh @@ -0,0 +1 @@ +docker compose -f docker-compose.local.yaml -f docker-compose.override.yaml up -d \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index caeffc1..0000000 --- a/package-lock.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "@discordjs/collection": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz", - "integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==" - }, - "@discordjs/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, - "abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "requires": { - "event-target-shim": "^5.0.0" - } - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "requires": { - "delayed-stream": "~1.0.0" - } - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, - "discord.js": { - "version": "12.5.1", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz", - "integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==", - "requires": { - "@discordjs/collection": "^0.1.6", - "@discordjs/form-data": "^3.0.1", - "abort-controller": "^3.0.0", - "node-fetch": "^2.6.1", - "prism-media": "^1.2.2", - "setimmediate": "^1.0.5", - "tweetnacl": "^1.0.3", - "ws": "^7.3.1" - } - }, - "event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" - }, - "mime-db": { - "version": "1.45.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", - "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==" - }, - "mime-types": { - "version": "2.1.28", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", - "integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", - "requires": { - "mime-db": "1.45.0" - } - }, - "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" - }, - "prism-media": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.3.tgz", - "integrity": "sha512-fSrR66n0l6roW9Rx4rSLMyTPTjRTiXy5RVqDOurACQ6si1rKHHKDU5gwBJoCsIV0R3o9gi+K50akl/qyw1C74A==" - }, - "setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" - }, - "tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" - }, - "ws": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.2.tgz", - "integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==" - } - } -} diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..821380a --- /dev/null +++ b/setup.sh @@ -0,0 +1,2 @@ +cp frontend/.env_sample frontend/.env +cp backend/.env_sample backend/.env \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..4ceeefa --- /dev/null +++ b/start.sh @@ -0,0 +1 @@ +docker compose up --remove-orphans --force-recreate --build -d \ No newline at end of file