# JHP WEB

JHP_WEB is a web application for managing projects, properties, and related business operations.

## Tech Stack

* Docker
* React / Next.js
* Nginx

## Deployment

The application is deployed using Docker images hosted on Docker Hub.

### Docker Image

```text
jhpdev/jhp_projects
```

### Build

```bash
docker build -t jhpdev/jhp_projects:jhp_web_1.0.0 .
```

### Push

```bash
docker push jhpdev/jhp_projects:jhp_web_1.0.0
```

### Production Deployment

SSH into the production server:

```bash
ssh user@SERVER_IP
```

Pull the new image:

```bash
docker compose pull web
```

Stop the existing container:

```bash
docker stop web
```

Remove the existing container:

```bash
docker rm web
```

Start the new container:

```bash
docker compose up -d web
```

## Verify Deployment

Check running containers:

```bash
docker ps
```

Check application logs:

```bash
docker compose logs -f web
```

Check the last 100 log entries:

```bash
docker compose logs --tail 100 web
```

## Versioning

Use a new version tag for every deployment.

```text
jhp_web_1.0.0
jhp_web_1.0.1
jhp_web_1.0.2
jhp_web_1.1.0
```

Example:

```bash
docker build -t jhpdev/jhp_projects:jhp_web_1.0.1 .
docker push jhpdev/jhp_projects:jhp_web_1.0.1
```

Then on the production server:
Update the image tags on the .env file to point to the new image version to deploy.

```bash
docker compose pull web

docker stop web
docker rm web

docker compose up -d web

```

## Deployment Flow

```text
Local Machine
     │
     ▼
Docker Build
     │
     ▼
Docker Image
     │
     ▼
Docker Push
     │
     ▼
Docker Hub
     │
     ▼
Production Server
     │
     ▼
Docker Pull
     │
     ▼
Stop Old Container
     │
     ▼
Start New Container
     │
     ▼
Live Application
```

## Quick Deployment

### Local Machine

```bash
docker build -t jhpdev/jhp_projects:jhp_web_1.0.0 .
docker push jhpdev/jhp_projects:jhp_web_1.0.0
```

### Production Server

```bash
docker compose pull web

docker stop web
docker rm web

docker compose up -d web
```

### Verify

```bash
docker ps
docker compose logs -f web
```

## Deployment Checklist

* [ ] Test changes locally
* [ ] Assign a new version number
* [ ] Build Docker image
* [ ] Push image to Docker Hub
* [ ] Pull image on production server
* [ ] Stop existing container
* [ ] Remove existing container
* [ ] Start new container
* [ ] Check container status
* [ ] Check application logs
* [ ] Verify application is accessible
* [ ] Keep previous image available for rollback

## Important Notes

* Use a new image tag for every deployment.
* Do not overwrite existing version tags.
* Keep previous working images available for rollback.
* Do not commit `.env` files or production secrets to the repository.
* Verify the application logs after every deployment.

Available next action: Create a downloadable DOCX file here in this chat containing the editable prose above
