From f3e095dafc6fbbf047bc127a6fe7a73f27078653 Mon Sep 17 00:00:00 2001 From: Liosha84 Date: Wed, 28 Oct 2026 23:27:29 +0100 Subject: [PATCH] Add Gitea Actions CI/CD for automated Docker builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add .gitea/workflows/docker.yml: builds and pushes Docker image on Git tags with semantic versioning (v0.1.0 → tags 0.1.0, 0.1, latest) - Add .dockerignore to optimize Docker build context - Document release process in docs/DEVELOPMENT.md - Update CHANGELOG.md with v0.1.0 release and Unreleased CI/CD entry Required Gitea secrets: REGISTRY_USERNAME, REGISTRY_PASSWORD Co-authored-by: Junie --- .dockerignore | 34 +++++++++++++++++++----- .gitea/workflows/docker.yml | 50 ++++++++++++++++++++++++++++++++++ CHANGELOG.md | 6 +++++ docs/DEVELOPMENT.md | 53 +++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 .gitea/workflows/docker.yml diff --git a/.dockerignore b/.dockerignore index e2b2d71..9c1c116 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,29 @@ - +# Docker build context exclusions .git +.github +.gitea +docs +*.md +!.markdownlint.yaml .idea -**/.idea -**/node_modules - -**/dist -**/.gradle -**/.angular +*.iml +node_modules +.gradle +build +dist +.DS_Store +*.log +*.tmp +*.swp +*~ +# Frontend build artifacts (built inside Docker) +frontend/dist +frontend/.angular +# Backend build artifacts (built inside Docker) +backend/build +backend/libs +# Test reports +backend/build/reports +# Secrets +.env +.env.* diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..a28a330 --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,50 @@ +name: Docker Build and Push + +on: + push: + tags: + - 'v*' + +env: + REGISTRY: gitea.jambotron.com + IMAGE_NAME: liosha84/htop-web + +jobs: + build-and-push: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Extract version from tag + id: version + run: | + # Remove 'v' prefix from tag (e.g., v0.1.0 → 0.1.0) + VERSION=$(echo "${{ gitea.ref }}" | sed 's|refs/tags/v||') + echo "version=${VERSION}" >> "${GITEA_OUTPUT}" + + # Extract major.minor for minor tag (e.g., 0.1.0 → 0.1) + MINOR=$(echo "${VERSION}" | sed 's/\.[0-9]*$//') + echo "minor=${MINOR}" >> "${GITEA_OUTPUT}" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.minor }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d2d2e3..ed888a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ This project has not yet established a versioned changelog. Add entries as relea ## Unreleased +- **CI/CD with Gitea Actions** — automated Docker image build and push on Git tags. Each release produces three tags: full version (`0.2.0`), minor version (`0.2`), and `latest`. Configure `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` secrets in Gitea repository settings. +- **Docker build optimization** — added `.dockerignore` to exclude unnecessary files from the build context, reducing build time and image size. +- **Release documentation** — added detailed release process guide in `docs/DEVELOPMENT.md` with Semantic Versioning workflow. + +## v0.1.0 + - **Multi-stage Docker build** — the Dockerfile now compiles both the Angular frontend and Spring Boot backend inside Docker using three stages (Node.js → Gradle → JRE). Build the entire application with a single `docker build` command — no local Java or Node.js required. - **Security hardening** — replaced full host root mount (`/:/host/root:ro`) with specific directory mounts (`/proc`, `/sys`, `/etc/hostname`, `/etc/os-release`, `/var`, `/home`, `/opt`, `/tmp`, `/srv`, `/usr`) to minimize the attack surface. - **Host metrics consistency** — `LinuxMemoryService` and `CpuDetailsService` now read host metrics from `/host/proc` instead of container metrics from OSHI. diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 04b2901..eaebcf2 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -91,6 +91,59 @@ docker run -d \ htop-web ``` +## Release process + +### Prerequisites + +- Gitea Actions runner must be configured and running. +- Repository secrets `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` must be set in **Settings → Secrets** of the Gitea repository. These credentials are used to authenticate with the Gitea Container Registry. + +### Creating a release + +1. **Update `CHANGELOG.md`** with changes for the new version. + +2. **Commit and push** your changes: + + ```bash + git add -A + git commit -m "Prepare release v0.2.0" + git push origin master + ``` + +3. **Create and push a Git tag** with Semantic Versioning: + + ```bash + git tag -a v0.2.0 -m "Release v0.2.0: new features and fixes" + git push origin v0.2.0 + ``` + +4. **Gitea Actions** will automatically: + - Build the Docker image using the multi-stage Dockerfile + - Tag it with the version (`0.2.0`), minor version (`0.2`), and `latest` + - Push all three tags to the Gitea Container Registry + +### Docker image tags + +Each release produces three Docker image tags: + +| Tag | Example | Description | +|-----|---------|-------------| +| Full version | `gitea.jambotron.com/liosha84/htop-web:0.2.0` | Exact version, use in production | +| Minor version | `gitea.jambotron.com/liosha84/htop-web:0.2` | Latest patch of 0.2.x | +| Latest | `gitea.jambotron.com/liosha84/htop-web:latest` | Most recent stable release | + +### Using a specific version in production + +In `docker-compose.yml`, always pin to a specific version: + +```yaml +services: + htop-web: + image: gitea.jambotron.com/liosha84/htop-web:0.2.0 +``` + +Avoid using `:latest` in production — it makes rollbacks impossible and breaks reproducibility. + ## Contribution guidelines - Keep changes focused and reviewable.