Files
website-template/README.md

112 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🚀 Showcase Website CI/CD Docker Template
This repository is a **production-ready template** for deploying a static website using:
- Plain **HTML / CSS / JavaScript**
- **Docker + Nginx**
- **Gitea Actions** for CI/CD
- Automated **build numbering**
- Safe **deployment with healthchecks & rollback**
It is designed to be **forked and reused** as a starting point for real-world deployments.
## 📦 Whats included
- ✅ Simple showcase website
- ✅ Configurable Nginx container
- ✅ Dockerfile ready for production
- ✅ CI pipeline (build + tag + push)
- ✅ CD pipeline (deploy + healthcheck)
- ✅ Automatic rollback on failed deployment
## 📁 Repository structure
```
.
├── .gitea/
│ └── workflows/
│ └── ci.yml
├── assets/
│ ├── scripts/
│ └── styles/
├── docker/
│ ├── default.conf.template
│ └── nginx.conf
├── Dockerfile
├── index.html
└── README.md
```
## 🐳 Docker image
### Image tags
Each build produces multiple tags:
| Tag | Description |
| ----------- | ----------- |
| `build-N` | Incremental build number with N as the build number (recommended for deployments) |
| `latest` | Pointer to most recent build |
## 🔁 CI/CD Pipeline Overview
### CI (Build)
Triggered on push to `main`:
1. Logs into the Docker registry
2. Build Docker image
3. Tag with: `build-N` & `latest`
4. Push image to registry
### CD (Deploy)
The deploy job:
1. Connects to the server via SSH
2. Logs into the Docker registry
3. Pulls the new `build-N` image
4. Starts the new `build-N` container on a test port `81`
5. Runs healthchecks
6. **If unhealthy**
1. Stops the new `build-N` container
2. Exits the CD process (keeping the old container running)
7. **If healthy → stop the new `build-N` container and stop here**
1. Stops the new `build-N` container
2. Stops the new old container
3. Starts the new `build-N` container on the correct port `80`
4. Remove the docker image of the old container
This guarantees:
- No broken deployments
- Clear CI failure signal
- Easy rollback
## ❤️ Healthcheck
The container exposes:
```
GET /health
```
Expected response:
```
200 OK
ok
```
Used by:
- Docker healthchecks
- Deployment validation
## 🔐 Required Gitea Secrets & Variables
The following secrets and variables **must be setup** inside the destination repository.
### Variables
| Variable | Description |
| ----------------------- | --------------------------------------------------- |
| `IMAGE_NAME` | Name of the docker image (built and deployed) |
| `REGISTRY_LOCATION` | Location of the image registery |
| `REGISTRY_ORGANIZATION` | Name of the organisation in the image registery |
| `PORT` | Port on which the site will be exposed on |
| `TEST_PORT` | Port on which the test container will be exposed on |
### Secrets
| Secrets | Description |
| ------------------ | --------------------------------------------------------------------- |
| `REGISTRY_USER` | User used in order to log into the image registery |
| `REGISTRY_TOKEN` | Token (or password) used in order to log into the image registery |
| `PROD_SERVER_HOST` | Location of the production server host (must be reachable from GITEA) |
| `DEPLOY_USER` | User used in order to ssh into the production server |
| `DEPLOY_SSH_KEY` | SSH private key used in order to ssh into the production server |