gig changes

This commit is contained in:
Amit Kumar Nandi 2024-02-15 16:50:39 +05:30
parent 88ad86e26a
commit d9160d50b3
5 changed files with 161 additions and 48 deletions

View file

@ -1,5 +1,10 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
# Add the following lines to tag the image (replace 'your_username' and 'shortener-app' with your Docker Hub username and repository name)
ARG VERSION=latest
ARG IMAGE_NAME=bigwiz/shortener
ARG TAG=$VERSION
# Stage 1: Build the application # Stage 1: Build the application
FROM maven:3.9.6-eclipse-temurin-21 AS builder FROM maven:3.9.6-eclipse-temurin-21 AS builder
@ -19,8 +24,9 @@ ENV CATALINA_BASE /usr/local/tomcat
ENV CATALINA_HOME /usr/local/tomcat ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH ENV PATH $CATALINA_HOME/bin:$PATH
# Copy the WAR file from the builder stage # Copy the WAR file from the builder stage
COPY target/shortener.war $CATALINA_BASE/webapps/ COPY --from=builder /URLShortener/target/shortener.war $CATALINA_BASE/webapps/
# Add configuration for document base path # Add configuration for document base path
@ -44,4 +50,3 @@ RUN chmod +x /usr/local/tomcat/shortener.sh
# Start Tomcat and MariaDB using the startup script # Start Tomcat and MariaDB using the startup script
CMD ["sh", "/usr/local/tomcat/shortener.sh"] CMD ["sh", "/usr/local/tomcat/shortener.sh"]

132
README.md
View file

@ -1,9 +1,11 @@
## Enterprise-Grade URL Shortener and Bio Page Application ## ![](https://33333.cdn.cke-cs.com/kSW7V9NHUXugvhoQeFaf/images/849f04bc0b71c7572b553b2b283f7590067b036c87a71ba9.webp)**TUSC - The URL Shortener Company**
[![Build Status](https://travis-ci.org/yourusername/your-repo.svg?branch=main)](https://travis-ci.org/aamitn/URLShortener)[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)[![GitHub last commit](https://img.shields.io/github/last-commit/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/commits/main)[![GitHub issues](https://img.shields.io/github/issues/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/issues)[![GitHub pull requests](https://img.shields.io/github/issues-pr/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/pulls)[![GitHub contributors](https://img.shields.io/github/contributors/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/graphs/contributors) [![Build Status](https://travis-ci.org/yourusername/your-repo.svg?branch=main)](https://travis-ci.org/aamitn/URLShortener)[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)[![GitHub last commit](https://img.shields.io/github/last-commit/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/commits/main)[![GitHub issues](https://img.shields.io/github/issues/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/issues)[![GitHub pull requests](https://img.shields.io/github/issues-pr/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/pulls)[![GitHub contributors](https://img.shields.io/github/contributors/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/graphs/contributors)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/yourusername/your-repo.svg?style=social)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Faamitn%2FURLShortener&text=Check%20out%20this%20awesome%20URL%20Shortener%20and%20Bio%20Page%20Application&via=yourtwitterhandle) [![Twitter](https://img.shields.io/twitter/url/https/github.com/yourusername/your-repo.svg?style=social)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Faamitn%2FURLShortener&text=Check%20out%20this%20awesome%20URL%20Shortener%20and%20Bio%20Page%20Application&via=yourtwitterhandle)
A powerful and scalable URL shortener with integrated bio pages built using Spring Boot. An enterprise-grade, powerful and scalable URL shortener with integrated bio pages built using Spring Boot.
<table><tbody><tr><td>Maven Package</td><td><a href="https://onlinemarkdowneditor.dev/">Free Collaborative Markdown Editor - onlinemarkdowneditor.dev</a></td></tr><tr><td>Docker Image</td><td><a href="https://onlinemarkdowneditor.dev/">Free Collaborative Markdown Editor - onlinemarkdowneditor.dev</a></td></tr></tbody></table>
## Table of Contents ## Table of Contents
@ -23,14 +25,14 @@ This project is an enterprise-grade URL shortener and bio page application devel
## Features ## Features
* Shorten URLs and create custom short URLs * Shorten URLs and create custom short URLs.
* Integrated bio pages for users * Integrated bio pages for users.
* Analytics tracking for each shortened URL * Analytics tracking for each shortened URL.
* User management with registration, login, and profile updates * User management with registration, login, and profile updates.
* Subscription plans for premium features * Subscription plans for premium features.
* Rate limiting to prevent abuse * Rate limiting to prevent abuse.
* Forgot password and username recovery functionality * Forgot password and username recovery functionality.
* ... * OPEN API 3.0 Complaint REST API set, with extensive docs.
## Getting Started ## Getting Started
@ -43,94 +45,142 @@ Before you begin, ensure you have the following installed:
* MySQL * MySQL
* Your favorite IDE (IntelliJ, Eclipse, etc.) * Your favorite IDE (IntelliJ, Eclipse, etc.)
### Local Setup ### Local Setup
1. Clone the repository: 1. Clone the repository:
```plaintext ```plaintext
git clone https://github.com/aamitn/URLShortener.git git clone https://github.com/aamitn/URLShortener.git
``` ```
2. **Apply the Database Schema:** 2. **Apply the Database Schema:**
Execute the provided **db\_schema.sql** file to set up the necessary tables and schema for the application. This script will also create the required database. Execute the provided **db\_schema.sql** file to set up the necessary tables and schema for the application. This script will also create the required database.
```plaintext ```plaintext
mysql -u your_username -p < path/to/db_schema.sql mysql -u your_username -p < path/to/db_schema.sql
``` ```
3. Update the application.properties file: 3. Update the application.properties file:
 Update the application.properties file in the src/main/resources directory with your database configuration. Update the application.properties file in the src/main/resources directory with your database configuration.
4. Build and run the application: 4. Build and run the application:
```plaintext ```plaintext
cd URLShortener cd URLShortener
mvn spring-boot:run mvn spring-boot:run
``` ```
5. Access the application at http://localhost:8080 5. Access the application at http://localhost:8080
### Deployment ### Deployment
1. **Build a deployable WAR:** 1. **Build a deployable WAR:**
```plaintext ```plaintext
mvn clean install mvn clean install
``` ```
2. **Deploy the WAR:** 2. **Deploy the WAR:**
* **Option 1: Manual Deployment** * **Option 1: Manual Deployment**
Deploy the generated WAR file to your Tomcat server. Copy the WAR file to the `webapps` directory of your Tomcat installation. Deploy the generated WAR file to your Tomcat server. Copy the WAR file to the `webapps` directory of your Tomcat installation.
```plaintext ```plaintext
cp target/shorten.war /path/to/tomcat/webapps/ cp target/shorten.war /path/to/tomcat/webapps/
``` ```
* **Option 2: Web Interface Upload** * **Option 2: Web Interface Upload**
Alternatively, if your Tomcat server provides a web interface for WAR file deployment, follow these steps: Alternatively, if your Tomcat server provides a web interface for WAR file deployment, follow these steps:
* Access the Tomcat Manager web interface at `http://localhost:8080/manager/html` (replace with your Tomcat server address). * Access the Tomcat Manager web interface at `http://localhost:8080/manager/html` (replace with your Tomcat server address).
* Log in with your Tomcat manager credentials. * Log in with your Tomcat manager credentials.
* Navigate to the "WAR file to deploy" section. * Navigate to the "WAR file to deploy" section.
* Choose the `shorten.war` file using the file upload button. * Choose the `shorten.war` file using the file upload button.
* Click the "Deploy" button. * Click the "Deploy" button.
3. **Configure environment variables:** 3. **Configure environment variables:**
Set environment variables for cloud-specific settings. Set environment variables for cloud-specific settings.
4. **Adjust Tomcat Configuration (Important):** 4. **Adjust Tomcat Configuration (Important):**
To ensure proper functionality, it's important to run the application on the root of the servlet container. If you're using Tomcat, add the following line to your `server.xml` configuration file within the `<Host>` section: To ensure proper functionality, it's important to run the application on the root of the servlet container. If you're using Tomcat, add the following line to your `server.xml` configuration file within the `<Host>` section:
```xml ```xml
<Context path="" docBase="shorten" reloadable="true"></Context> <Context path="" docBase="shorten" reloadable="true"></Context>
``` ```
This ensures that the application runs on the root context path. Adjust the `docBase` attribute according to your deployment directory. This ensures that the application runs on the root context path. Adjust the `docBase` attribute according to your deployment directory.
5. **Start Tomcat:** 5. **Start Tomcat:**
Start your Tomcat server. Start your Tomcat server.
```plaintext ```plaintext
/path/to/tomcat/bin/startup.sh # for Linux /path/to/tomcat/bin/startup.sh # for Linux
/path/to/tomcat/bin/startup.bat # for Windows /path/to/tomcat/bin/startup.bat # for Windows
``` ```
Access the application at `http://localhost:8080/`. Access the application at `http://localhost:8080/`.
6. **Adjust Configuration (Optional):** If you need to customize the application configuration after deployment, you can find the **application.properties** file within the deployed WAR file. THe file can be accesses as : 6. **Adjust Configuration (Optional):** If you need to customize the application configuration after deployment, you can find the **application.properties** file within the deployed WAR file. THe file can be accesses as :
```plaintext ```plaintext
vi /path/to/tomcat/webapps/your-app/WEB-INF/classes/application.properties vi /path/to/tomcat/webapps/your-app/WEB-INF/classes/application.properties
``` ```
### Usage
### Cloud Native Deployment
To deploy the URL Shortener application on your cloud environment, follow the steps below:
**Prerequisites**
* [Docker](https://www.docker.com/get-started)
* [Docker Compose](https://docs.docker.com/compose/install/)
1. **Clone the Repository:**
```plaintext
git clone https://github.com/your-username/URLShortener.git
cd URLShortener
```
2. **Build and Run Your Own Image:**
```plaintext
docker build -t shortener:latest .
docker run -p 8080:8080 -p 3306:3306 shortener:latest
```
3. **Use Our Pre-built Image with Docker Compose:**
```plaintext
docker compose build
docker compose up
```
4. **Customizing Docker Compose Configuration:**
In the **docker-compose.yml** file, you can customize the build source for the Shortener service:
```plaintext
#Build from docker hub image .Comment/Uncomment Below
image: nmpl/shortener:latest
#Build from local Dockerfile.Comment/Uncomment Below
# build:
# context: .
# dockerfile: Dockerfilekerfile
```
Comment or uncomment the relevant lines based on whether you want to use the pre-built image from Docker Hub or build from the local Dockerfile.
### Usage Cases
1. Shorten URLs by visiting the URL Shortener page. 1. Shorten URLs by visiting the URL Shortener page.
2. Access analytics for each shortened URL. 2. Access analytics for each shortened URL.
@ -142,4 +192,4 @@ Contributions are welcome! Please follow the contribution guidelines.
### License ### License
This project is licensed under the MIT License - see the LICENSE.md file for details. This project is licensed under the MIT License - see the LICENSE.md file for details.

View file

@ -2,9 +2,36 @@ version: '3.8'
services: services:
shortener-app: shortener-app:
build: labels:
context: . - "TUSC The URL Shortener Company"
dockerfile: Dockerfile
#Build from docker hub image .Comment/Uncomment Below
image: nmpl/shortener:latest
#Build from local Dockerfile.Comment/Uncomment Below
# build:
# context: .
# dockerfile: Dockerfile
ports: ports:
- "8080:8080" - "8080:8080"
- "3306:3306" - "3306:3306"
volumes:
- shortener-db-data:/var/lib/mysql
- type: volume
source: shortener-db-data
target: /var/lib/mysql
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/monitoring" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
restart: unless-stopped
volumes:
shortener-db-data:
name: shortener-db-data

View file

@ -178,7 +178,7 @@
<packaging>${project.packaging}</packaging> <packaging>${project.packaging}</packaging>
<build> <build>
<finalName>${artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<pluginManagement> <pluginManagement>

View file

@ -0,0 +1,31 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 120 120">
<!-- Background Parallelogram Shape -->
<polygon points="0,0 0,0, 120,60,0,170" fill="#3498db" />
<!-- Wire -->
<line x1="20" y1="50" x2="90" y2="50" stroke="#fff" stroke-width="5" />
<!-- Plug -->
<rect x="50" y="40" width="20" height="20" fill="#e74c3c" />
<!-- T Letter -->
<text x="2%" y="70%" font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="25" fill="#fff" font-weight="bold">
<tspan font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="52" letter-spacing="2">T</tspan>
</text>
<!-- U Letter -->
<text x="20%" y="70%" font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="25" fill="#fff" font-weight="bold">
<tspan font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="40" letter-spacing="2">U</tspan>
</text>
<!-- S Letter -->
<text x="40%" y="70%" font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="25" fill="#fff" font-weight="bold">
<tspan font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="40" letter-spacing="2">S</tspan>
</text>
<!-- C Letter -->
<text x="58%" y="70%" font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="25" fill="#fff" font-weight="bold">
<tspan font-family="'Segoe UI', Tahoma, Geneva, Verdana, sans-serif" font-size="40" letter-spacing="2">C</tspan>
</text>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB