# πŸš€ 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. ## πŸ“¦ What’s 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/ β”œβ”€β”€ docker/ β”‚ β”œβ”€β”€ default.conf.template β”‚ └── nginx.conf β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ css/ β”‚ └── js/ β”œβ”€β”€ 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 | | `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 |