From 9dd1aecd0fe0bae114c08196d220413e75f916f9 Mon Sep 17 00:00:00 2001 From: Sujal Goswami Date: Thu, 15 Aug 2024 21:58:58 +0530 Subject: [PATCH] write deployment github action --- .env.sample | 12 +++ .github/workflows/deploy.yml | 28 +++++- .github/workflows/test.yml | 8 +- README.md | 169 ++++++++++++++++++++++++++++++++++- 4 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..cdca570 --- /dev/null +++ b/.env.sample @@ -0,0 +1,12 @@ +PORT= +MONGODB_URI= +CORS_ORIGIN= +ACCESS_TOKEN_SECRET= +ACCESS_TOKEN_EXPIRY= +REFRESH_TOKEN_SECRET= +REFRESH_TOKEN_EXPIRY= + +CLOUDINARY_CLOUD_NAME= +CLOUDINARY_API_KEY= +CLOUDINARY_API_SECRET= + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4401ff6..5679633 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Build and Publish Docker Image +name: Deploy on: push: @@ -28,4 +28,28 @@ jobs: context: . file: ./Dockerfile push: true - tags: sujalgoswami/boredtube:latest \ No newline at end of file + tags: sujalgoswami/boredtube:latest + target: production + + - name: remote ssh into VPS and deploy + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + script: | + sudo docker pull sujalgoswami/boredtube:latest + sudo docker stop boredtube || true + sudo docker rm boredtube || true + sudo docker run --restart=always -d --name boredtube -p 8001:8000 \ + -e PORT=8000 \ + -e MONGODB_URI=${{ secrets.MONGODB_URI }} \ + -e CORS_ORIGIN=${{ secrets.CORS_ORIGIN }} \ + -e ACCESS_TOKEN_SECRET=${{ secrets.ACCESS_TOKEN_SECRET }} \ + -e ACCESS_TOKEN_EXPIRY=${{ secrets.ACCESS_TOKEN_EXPIRY }} \ + -e REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }} \ + -e REFRESH_TOKEN_EXPIRY=${{ secrets.REFRESH_TOKEN_EXPIRY }} \ + -e CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }} \ + -e CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }} \ + -e CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }} \ + sujalgoswami/boredtube:latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dfe386c..45b3e7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,9 +1,9 @@ -name: CI +name: Build and Test on: - # push: - # branches: - # - main + push: + branches: + - main pull_request: branches: - main diff --git a/README.md b/README.md index 4d66839..25941c9 100644 --- a/README.md +++ b/README.md @@ -1 +1,168 @@ -# BoredTube +# 🎬BoredTube +## Introduction + +>🎬 **BoredTube** is a video streaming service similar to YouTube, with built-in Twitter-like features. This project provides a complete video management system. It includes user management, video upload and editing, tweet management, subscription management, playlist management, and more. Built with Node.js, Express.js, and MongoDB, BoredTube is strong and can grow easily. It connects with Cloudinary for storing media and uses JWT for secure login. With detailed API documentation and a focus on user experience, BoredTube aims to offer a smooth and efficient video management system. + +## Important links +| Content | Link | +| ----------------- | -------------------------------------------------------------------------------- | +| API Documentation | [click here](https://documenter.getpostman.com/view/36524668/2sA3s7ioWe) | +| Model | [click here ](https://app.eraser.io/workspace/YtPqZ1VogxGy1jzIDkzj) | + +## Features + +### User Management: + +- Registration, login, logout, change password +- Profile management (avatar, cover image, other details) +- Watch history tracking and Clearing Watch History +- Liked videos tracking + +### Video Management: + +- Video upload +- Canceling Video upload with all resources cleaned up on backend. +- Visibility control (publish/un-publish) +- Video editing and deletion +- Video Search and pagination + +### Tweet Management: + +- Tweet creation and publishing +- Viewing user tweets +- Updating and deleting tweets +- Liking-disliking tweets + +### Subscription Management: + +- Subscribing to channels +- Viewing Channel subscriber +- Viewing Subscribed channel lists + +### Playlist Management: + +- Creating, updating, and deleting playlists +- Adding videos to playlists +- Removing videos from playlists and undoing them +- Viewing user playlists + +### Like Management: + +- Liking and Un-liking videos, comments, and tweets +- Viewing liked videos + +### Comment Management: + +- Adding, updating, and deleting comments on videos + +### Dashboard: + +- Viewing channel statistics (views, subscribers, videos, likes) +- Accessing uploaded videos and Controls +- Viewing Video statistics (PublishStatus, VideoName, DateUploaded, Views, TotalComments, LikeRatings) + +### Health Check: + +- Endpoint to verify the server's health + +## Technologies + +- Node.js +- Express.js +- MongoDB +- Mongoose +- JWT +- Cloudinary +- Jest & Supertest +- Docker +- Github actions + +## Installation and Setup + +### Prerequisites + +- Node.js (v20.x) +- Docker (optional, for containerized deployment) +- MongoDB (local or cloud instance) +- Cloudinary account (for media storage) + +### Environment Variables + +Create a `.env` file in the root directory of the project and populate it with the variables in `.env.sample` file. + +### Installation + +1) Clone the repository: + +``` + git clone https://github.com/sujal-goswami/BoredTube.git + cd boredtube +``` + +2) Install dependencies: + +``` + npm install +``` + +### Running the Application +### Development + +To run the application in development mode: +``` + npm run dev +``` + +### Production + +To run the application in production mode: +``` + npm run start +``` + +### Running Tests +To run the tests: + +``` + npm run test +``` + +### Docker Setup + +To build and run the application using Docker: + +1) Build the Docker image: + +``` + docker build --target development -t boredtube:latest . +``` + +2) Run the Docker container: + +``` +docker run -d --name boredtube -p 8000:8000 \ +-e PORT=8000 \ +-e MONGODB_URI=your_mongodb_uri \ +-e CORS_ORIGIN=your_cors_origin \ +-e ACCESS_TOKEN_SECRET=your_access_token_secret \ +-e ACCESS_TOKEN_EXPIRY=your_access_token_expiry \ +-e REFRESH_TOKEN_SECRET=your_refresh_token_secret \ +-e REFRESH_TOKEN_EXPIRY=your_refresh_token_expiry \ +-e CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name \ +-e CLOUDINARY_API_KEY=your_cloudinary_api_key \ +-e CLOUDINARY_API_SECRET=your_cloudinary_api_secret \ +boredtube:latest +``` + +### Continuous Integration and Deployment + +This project uses GitHub Actions for CI/CD. The workflows are defined in the `.github/workflows` directory. + +- Deploy Workflow +- Test Workflow + +## Contributing +Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request. Let's make 🎬BoredTube even better together! for more details refer [CONTRIBUTING.md]() . + +## License +🎬BoredTube is licensed under the [MIT License](). Feel free to modify, distribute, and use the code for personal or commercial projects. \ No newline at end of file