From 37a667daff614813ea7be4e6099899f7ed7f183d Mon Sep 17 00:00:00 2001 From: Kyle Affolder Date: Mon, 10 Feb 2025 11:21:22 -0500 Subject: [PATCH] fix(docker): dynamic README generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ๐Ÿ”„ Automate README Generation via Mustache Templating - Use Mustache to dynamically generate `README.md` from `README.template.md`. - Populate README with environment variables (e.g., `KENER_BUILD_FULL_VERSION`). - Prevent direct edits to `README.md` by enforcing updates via the template. - Enhance GitHub Actions workflow to auto-generate and commit the README. - Add GitHub Action workflow (`protect-readme.yml`) to prevent others from direct updates to `README.md` via PR. --- .github/workflows/protect-readme.yml | 21 ++ .../{publishImage.yml => publish-images.yml} | 72 +++--- README.template.md | 217 ++++++++++++++++++ package.json | 2 + scripts/generate-readme.js | 31 +++ 5 files changed, 306 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/protect-readme.yml rename .github/workflows/{publishImage.yml => publish-images.yml} (68%) create mode 100644 README.template.md create mode 100644 scripts/generate-readme.js diff --git a/.github/workflows/protect-readme.yml b/.github/workflows/protect-readme.yml new file mode 100644 index 0000000..9963dc7 --- /dev/null +++ b/.github/workflows/protect-readme.yml @@ -0,0 +1,21 @@ +name: Prevent Direct README Changes + +on: + pull_request: + paths: + - "README.md" + +jobs: + check-readme: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.4.2 + + - name: Detect direct README changes + run: | + if git diff --name-only origin/main | grep -q "README.md"; then + echo "โŒ Direct modifications to README.md are not allowed!" + echo "Please update README.md.template instead." + exit 1 + fi diff --git a/.github/workflows/publishImage.yml b/.github/workflows/publish-images.yml similarity index 68% rename from .github/workflows/publishImage.yml rename to .github/workflows/publish-images.yml index a82a71d..1633cce 100644 --- a/.github/workflows/publishImage.yml +++ b/.github/workflows/publish-images.yml @@ -122,46 +122,44 @@ jobs: run: | echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} - # FIXME: Currently with this setup, job will only update versioning listed under README Docker section the FIRST time, but then once those inline placeholders are updated, future job runs will fail. Need to revisit with a more robust approach. Commenting out (for now) - # update_readme: - # needs: build_and_push_to_registries # Runs only after build_and_push_to_registries completes successfully - # name: Update README with release versions - # runs-on: ubuntu-latest + generate_readme: + needs: build_and_push_to_registries # Runs only after build_and_push_to_registries completes successfully + name: Generate README from template + runs-on: ubuntu-latest - # steps: - # - name: Checkout Repository - # uses: actions/checkout@v4.4.2 + steps: + - name: Checkout Repository + uses: actions/checkout@v4.4.2 - # - name: Extract Release Versions - # id: meta - # uses: docker/metadata-action@v5.6.1 - # with: - # images: rajnandan1/kener - # tags: | - # type=semver,pattern={{version}} - # type=semver,pattern={{major}}.{{minor}} - # type=semver,pattern={{major}} + - name: Extract Release Versions + id: meta + uses: docker/metadata-action@v5.6.1 + with: + images: rajnandan1/kener + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} - # - name: Set Environment Variables - # run: | - # echo "KENER_SEMVER_VERSION=${{ steps.meta.outputs.version }}" >> $GITHUB_ENV - # echo "KENER_MAJOR_MINOR_VERSION=${{ steps.meta.outputs.major }}.${{ steps.meta.outputs.minor }}" >> $GITHUB_ENV - # echo "KENER_MAJOR_VERSION=${{ steps.meta.outputs.major }}" >> $GITHUB_ENV + - name: Setup Node.js + uses: actions/setup-node@v4.2.0 + with: + node-version: "20" - # - name: Safetly Update README.md - # run: | - # KENER_SEMVER_VERSION_ESCAPED=$(printf '%s\n' "${{ env.KENER_SEMVER_VERSION }}" | sed 's/[&/\]/\\&/g') - # KENER_MAJOR_MINOR_VERSION_ESCAPED=$(printf '%s\n' "${{ env.KENER_MAJOR_MINOR_VERSION }}" | sed 's/[&/\]/\\&/g') - # KENER_MAJOR_VERSION_ESCAPED=$(printf '%s\n' "${{ env.KENER_MAJOR_VERSION }}" | sed 's/[&/\]/\\&/g') + - name: Install Dependencies + run: npm install mustache dotenv - # sed -i "s/KENER_SEMVER_VERSION_PLACEHOLDER/${KENER_SEMVER_VERSION_ESCAPED}/g" README.md - # sed -i "s/KENER_MAJOR_MINOR_VERSION_PLACEHOLDER/${KENER_MAJOR_MINOR_VERSION_ESCAPED}/g" README.md - # sed -i "s/KENER_MAJOR_VERSION_PLACEHOLDER/${KENER_MAJOR_VERSION_ESCAPED}/g" README.md + - name: Generate README.md + env: + KENER_BUILD_FULL_VERSION: ${{ steps.meta.outputs.tags[0] }} # e.g., 1.2.3 + KENER_BUILD_MAJOR_MINOR_VERSION: ${{ steps.meta.outputs.tags[1] }} # e.g., 1.2 + KENER_BUILD_MAJOR_VERSION: ${{ steps.meta.outputs.tags[2] }} # e.g., 1 + run: node scripts/generate-readme.js - # - name: Commit and Push Changes - # run: | - # git config --global user.name 'github-actions' - # git config --global user.email 'github-actions@github.com' - # git add README.md - # git commit -m "Update README with latest versions: ${{ env.KENER_SEMVER_VERSION }}" || exit 0 - # git push + - name: Commit and Push Changes + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add README.md + git commit -m "Auto-generate README.md with release versions" || echo "No changes to commit" + git push diff --git a/README.template.md b/README.template.md new file mode 100644 index 0000000..0737e18 --- /dev/null +++ b/README.template.md @@ -0,0 +1,217 @@ +# Kener - Stunning Status Pages + +

+ kener example illustration +

+ +

+ GitHub Repo stars + Awesome status page + Awesome self hosted +

+ +

+ Docker Kener + Docker Image Size + Docker Image Size +

+ +

+ GitHub Workflow Status + + GitHub issues +

+ +

+ + Kener on Product Hunt + +

+ +

+ + + ๐Ÿ”” + + + + ๐Ÿš€ + + + + ๐Ÿšง + +

+ +| [๐ŸŒ Live Server](https://kener.ing) | [๐ŸŽ‰ Quick Start](https://kener.ing/docs/quick-start) | [๐Ÿ—„ Documentation](https://kener.ing/docs/home) | +| ----------------------------------- | ---------------------------------------------------- | ----------------------------------------------- | + +## What is Kener? + +**Kener** is a sleek and lightweight status page system built with **SvelteKit** and **NodeJS**. Itโ€™s not here to replace heavyweights like Datadog or Atlassian but rather to offer a simple, modern, and hassle-free way to set up a great-looking status page with minimal effort. + +Designed with **ease of use** and **customization in mind**, Kener provides all the essential features youโ€™d expect from a status pageโ€”without unnecessary complexity. + +### Why Kener? + +โœ…  Minimal overhead – Set up quickly with a clean, modern UI
+โœ…  Customizable – Easily tailor it to match your brand
+โœ…  Open-source & free – Because great tools should be accessible to everyone + +### What's in a Name? + +โ€œKenerโ€ is inspired by the Assamese word _โ€œKeneโ€_, meaning _โ€œhowโ€™s it going?โ€_. The _โ€˜.ingโ€™_ was added because, wellโ€ฆ that domain was available. ๐Ÿ˜„ + +## Installation + +### Manual + +```shell +# Clone the repository +git clone https://github.com/rajnandan1/kener.git +cd kener +npm install +cp .env.example .env +npm run dev +``` + +### Docker + +Official Docker images for **Kener** are available on [Docker Hub](https://hub.docker.com/r/rajnandan1/kener). Multiple versions are maintained to support different use cases. + +![Docker Image Version (latest semver)](https://img.shields.io/docker/v/rajnandan1/kener?sort=semver&label=Latest%20Stable%20Release) + +#### Available Tags + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Image TagDescription
Debian 12 (Bookwork Slim) w/ Node.js v23.7.0  (default)
latestLatest stable release (aka {{kener_full_version}})
{{kener_full_version}}Specific release version
{{kener_major_minor_version}}Major-minor version tag pointing to the latest patch ({{kener_full_version}}) release within that minor version ({{kener_major_minor_version}}.x)
{{kener_major_version}}Major version tag pointing to the latest stable ({{kener_full_version}}) release within that major version ({{kener_major_version}}.x.x)
Alpine Linux 3.21 w/ Node.js v23.7.0  (smallest image size)
alpineLatest stable release (aka {{kener_full_version}})
{{kener_full_version}}-alpineSpecific release version
{{kener_major_minor_version}}-alpineMajor-minor version tag pointing to the latest patch ({{kener_full_version}}) release within that minor version ({{kener_major_minor_version}}.x)
{{kener_major_version}}-alpineMajor version tag pointing to the latest stable ({{kener_full_version}}) release within that major version ({{kener_major_version}}.x.x)
+ +#### Usage + +Pull the latest stable version: + +```sh +docker pull rajnandan1/kener:latest +``` + +Or use the smaller, Alpine-based variant: + +```sh +docker pull rajnandan1/kener:alpine +``` + +For a production setup, refer to the sample [docker-compose.yml](https://github.com/rajnandan1/kener/blob/main/docker-compose.yml). +This keeps things clean, structured, and easy to read while preserving all the details. + +### One Click + +[![Deploy on Railway](https://railway.com/button.svg)](https://railway.com/template/spSvic?referralCode=1Pn7vs) + +## Features + +Here are some of the features that you get out of the box. Please read the documentation to know how to use them. + +### ๐Ÿ“Š  Monitoring and Tracking + +- Advanced **application performance monitoring** tools +- **Real-time network monitoring** capabilities +- Supports **polling HTTP endpoints** or **pushing data** via REST APIs +- **Timezone auto-adjustment** for visitors +- Organize monitors into **custom sections** +- **Cron-based scheduling** (minimum: **every minute**) +- **Create complex API polls** (chaining, secrets, etc.) +- Set a **default status** for monitors +- Supports **base path hosting in Kubernetes (k8s)** +- **Pre-built Docker images** for easy deployment + +### ๐ŸŽจ  Customization and Branding + +- Fully **customizable status page** +- **Badge generation** for status and uptime tracking +- Support for **custom domains** +- Embed monitors as **iframes or widgets** +- **Light & Dark Mode** +- **Internationalization (i18n) support** +- **Sleek, beautifully crafted UI** + +### ๐Ÿšจ  Incident Management + +- **Incident tracking & communication** tools +- **Comprehensive APIs** for incident management + +### ๐Ÿง‘โ€๐Ÿ’ป  User Experience and Design + +- **Accessible & user-friendly interface** +- **Quick & easy installation** +- **Responsive design** for all devices +- **Auto SEO & Social Media ready** +- **Server-Side Rendering (SSR) for better performance** + +
+ Visitor Stats +
+ +## Technologies Used + +- [SvelteKit](https://kit.svelte.dev/) +- [shadcn-svelte](https://www.shadcn-svelte.com/) + +## Support Me + +If youโ€™re enjoying Kener and want to support its development, consider sponsoring me on GitHub or treating me to a coffee. Your support helps keep the project growing! ๐Ÿš€ + +[Sponsor Me Using Github](https://github.com/sponsors/rajnandan1) + +โ˜•  [Buy Me a Coffee](https://www.buymeacoffee.com/rajnandan1) + +![image](https://badges.pufler.dev/visits/rajnandan1/kener) + +## Contributing + +If you want to contribute to Kener, please read the [Contribution Guide](https://github.com/rajnandan1/kener/blob/main/.github/CONTRIBUTING.md). + +## Star History + +[![Star History Chart](https://api.star-history.com/svg?repos=rajnandan1/kener&type=Date)](https://star-history.com/#rajnandan1/kener&Date) diff --git a/package.json b/package.json index 17c3eda..b2fcd10 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "devschedule": "node src/lib/server/startup.js", "schedule": "node src/lib/server/startup.js", "development": "vite dev", + "generate-readme": "node scripts/generate-readme.js", "dev": "npm-run-all --parallel devschedule development", "prettify": "prettier --write .", "start": "node main.js" @@ -51,6 +52,7 @@ "concurrently": "^8.2.2", "cross-env": "^7.0.3", "date-picker-svelte": "^2.15.1", + "mustache": "^4.2.0", "postcss": "^8.4.24", "postcss-load-config": "^4.0.1", "prettier": "^3.2.5", diff --git a/scripts/generate-readme.js b/scripts/generate-readme.js new file mode 100644 index 0000000..af1c1be --- /dev/null +++ b/scripts/generate-readme.js @@ -0,0 +1,31 @@ +import fs from "fs"; +import Mustache from "mustache"; +import dotenv from "dotenv"; +import { fileURLToPath } from "url"; +import path from "path"; + +// Load environment variables from .env file +dotenv.config(); + +// Resolve paths correctly in ES modules +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Load the template +const templatePath = path.resolve(__dirname, "../README.template.md"); +const template = fs.readFileSync(templatePath, "utf-8"); + +// Load environment variables and provide default values +const data = { + kener_full_version: process.env.KENER_BUILD_FULL_VERSION || "N/A", + kener_major_minor_version: process.env.KENER_BUILD_MAJOR_MINOR_VERSION || "N/A", + kener_major_version: process.env.KENER_BUILD_MAJOR_VERSION || "N/A", +}; + +// Render README.md +const output = Mustache.render(template, data); + +// Write to README.md +fs.writeFileSync(path.resolve(__dirname, "../README.md"), output); + +console.log("โœ… README.md generated successfully!");