From acc3bee809055e038a9f579ebfa445305360060a Mon Sep 17 00:00:00 2001 From: Tushar <30565750+tushar5526@users.noreply.github.com> Date: Thu, 18 Jan 2024 18:26:22 +0530 Subject: [PATCH] feat: run linter once on all files --- .github/workflows/lint.yml | 24 ++++----- .github/workflows/test.yml | 53 +++++++++---------- .pre-commit-config.yaml | 2 +- README.md | 45 +++++++--------- docker-compose.yml | 9 ++-- .../grafana/dashboards/dashboard.yml | 6 +-- .../grafana/dashboards/docker_logs.json | 2 +- .../grafana/datasources/datasources.yml | 2 +- logging-config/loki/loki-config.yaml | 14 ++--- logging-config/promtail/promtail-config.yaml | 14 ++--- vault/vault.json | 34 ++++++------ 11 files changed, 98 insertions(+), 107 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3709600..acb5f60 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,18 +11,18 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pre-commit + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pre-commit - - name: Run pre-commit hooks - run: pre-commit run --all-files \ No newline at end of file + - name: Run pre-commit hooks + run: pre-commit run --all-files diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b6cc22e..04b1049 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,30 +11,29 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.11 # Choose your Python version - - - name: Cache Python dependencies - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - - name: Install main dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Install development dependencies - run: pip install -r requirements-dev.txt - - - name: Run pytest - run: python -m pytest -vvv + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.11 # Choose your Python version + + - name: Cache Python dependencies + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install main dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Install development dependencies + run: pip install -r requirements-dev.txt + + - name: Run pytest + run: python -m pytest -vvv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 73b3eb4..6e54db1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,4 +30,4 @@ repos: rev: v3.0.0 hooks: - id: prettier - exclude: ^(frontend/|CHANGELOG.md) \ No newline at end of file + exclude: ^(frontend/|CHANGELOG.md) diff --git a/README.md b/README.md index 6f419b3..251e99e 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,20 @@ - # Sarthi -[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) ![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square) ![GitHub contributors](https://img.shields.io/github/contributors-anon/tushar5526/sarthi) +[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) ![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square) ![GitHub contributors](https://img.shields.io/github/contributors-anon/tushar5526/sarthi) -Self-host Ephemeral (Preview) Environments with ease and forget about server management. +Self-host Ephemeral (Preview) Environments with ease and forget about server management. Sarthi uses other open-source projects to export logs, enable monitoring, manage secrets and create preview environments. It is meant to be used along with [sarthi-deploy](https://github.com/tushar5526/sarthi-deploy) GitHub Action for setting up preview environments in your project. Every time there is a new branch or a PR created, Sarthi GHA will create a preview environment for that. It also takes care of cleaning up preview environments when respective branches or PRs are merged. -Pre-requisites 🛠️ -------------------- +## Pre-requisites 🛠️ 1. Dockerized projects with a `docker-compose`. - - It is **MANDATORY** to have a `docker-compose` file at the root of the project's folder. -2. A public Linux machine (preferred Ubuntu 20+ LTS versions) and user with root access. -3. A wildcard subdomain pointing to the above machine (*.sarthi.your-domain.io) + - It is **MANDATORY** to have a `docker-compose` file at the root of the project's folder. +2. A public Linux machine (preferred Ubuntu 20+ LTS versions) and user with root access. +3. A wildcard subdomain pointing to the above machine (\*.sarthi.your-domain.io) - -General Flow ------------- +## General Flow 1. Create a public machine (preferred 4GB RAM, Ubuntu 20+ LTS versions) and map a [wildcard domain](https://docs.digitalocean.com/glossary/wildcard-record/) to it. 2. Set up the project using the [setup-sarthi.sh](https://github.com/tushar5526/sarthi/blob/main/setup-sarthi.sh) script present in the root folder. @@ -33,17 +29,16 @@ General Flow
Sarthi-Deploy GHA will not clutter your PR with comments - it will keep updating its earlier comment
+## Setup Instructions ⚙️ +1. SSH into your server and clone the project. -Setup Instructions ⚙️ ------------------------- - -1. SSH into your server and clone the project. ```commandline git clone https://github.com/tushar5526/sarthi.git ``` 2. Run the setup script. + ```commandline chmod +x setup-sarthi.sh chmod +x setup-vault.sh @@ -53,34 +48,32 @@ sudo ./setup-sarthi.sh 3. Follow the prompts and specify the values, you will be requested to specify the wild card domain name created earlier. (using localhost is possible, but that would require setting up `dnsmaq`) -Services Installed 🤖 ---------------------- +## Services Installed 🤖 The following services are exposed: 1. [Grafana](https://grafana.com/) + [Loki](https://grafana.com/oss/loki/) to export service logs from the deployed environments. [http://grafana.sarthi.your_domain.io](http://grafana.sarthi.your_domain.io) - A dashboard named `Service Logs` is pre-seeded in Grafana. You can use this to filter service logs based on deployments, containers etc. - - -2. [Portainer](https://www.portainer.io/) for admin access to manage deployments if needed. [http://portainer.sarthi.your_domain.io](http://portainer.sarthi.your_domain.io) + +2. [Portainer](https://www.portainer.io/) for admin access to manage deployments if needed. [http://portainer.sarthi.your_domain.io](http://portainer.sarthi.your_domain.io) 3. [Hashicorp Vault](https://www.vaultproject.io/) to specify environment secrets. [http://hashicorp.sarthi.your_domain.io](http://hashicorp.sarthi.your_domain.io) + - For each deployed branch/PR a path will be created by default in the vault where developers can specify branch-specific secrets. - 👉 PS: Hashicorp vault gets sealed on restarts. Unseal keys are generated by the setup script and stored in a `keys.txt` on the server. There is no RBAC yet and the root token is used to modify the env vars for different deployments. Root tokens can be found in `keys.txt` - + 4. [Sarthi](https://github.com/tushar5526/sarthi) Backend for GHA. [http://api.sarthi.your_domain.io](http://api.sarthi.your_domain.io) -Tips 💡 -------- +## Tips 💡 + 1. Use `docker-compose's` service discovery to connect within the same services in your projects. -High-Level Architecture ------------------------ +## High-Level Architecture ![sarthi](https://github.com/tushar5526/sarthi/assets/30565750/d08cf07e-f235-457c-952d-2406920319cb) - ### License 📄 + This action is licensed under some specific terms. Check [here](LICENSE) for more information. diff --git a/docker-compose.yml b/docker-compose.yml index 2e59881..4e71b79 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ -version: '3' +version: "3" services: - nginx: image: nginx:latest restart: always @@ -41,7 +40,7 @@ services: SECRET_TEXT: ${SECRET_TEXT} depends_on: - vault - + loki: image: grafana/loki:latest restart: always @@ -58,7 +57,7 @@ services: restart: always volumes: - /var/log:/var/log - - ./logging-config/promtail:/etc/promtail + - ./logging-config/promtail:/etc/promtail command: -config.file=/etc/promtail/promtail-config.yaml grafana: @@ -105,4 +104,4 @@ services: volumes: grafana: portainer_data: - vault-secrets: \ No newline at end of file + vault-secrets: diff --git a/logging-config/grafana/dashboards/dashboard.yml b/logging-config/grafana/dashboards/dashboard.yml index 3eb36b6..b02e33c 100644 --- a/logging-config/grafana/dashboards/dashboard.yml +++ b/logging-config/grafana/dashboards/dashboard.yml @@ -1,12 +1,12 @@ apiVersion: 1 providers: - - name: 'Loki' + - name: "Loki" orgId: 1 - folder: '' + folder: "" type: file disableDeletion: false editable: true allowUiUpdates: true options: - path: /etc/grafana/provisioning/dashboards \ No newline at end of file + path: /etc/grafana/provisioning/dashboards diff --git a/logging-config/grafana/dashboards/docker_logs.json b/logging-config/grafana/dashboards/docker_logs.json index 71626bf..2a4bcf5 100644 --- a/logging-config/grafana/dashboards/docker_logs.json +++ b/logging-config/grafana/dashboards/docker_logs.json @@ -185,4 +185,4 @@ "uid": "c9398592-6dc7-48c7-9d19-fba0afa195d0", "version": 7, "weekStart": "" -} \ No newline at end of file +} diff --git a/logging-config/grafana/datasources/datasources.yml b/logging-config/grafana/datasources/datasources.yml index 8d64e92..9a07fef 100644 --- a/logging-config/grafana/datasources/datasources.yml +++ b/logging-config/grafana/datasources/datasources.yml @@ -8,4 +8,4 @@ datasources: url: http://loki:3100 basicAuth: false isDefault: true - editable: true \ No newline at end of file + editable: true diff --git a/logging-config/loki/loki-config.yaml b/logging-config/loki/loki-config.yaml index a270bd7..4102315 100644 --- a/logging-config/loki/loki-config.yaml +++ b/logging-config/loki/loki-config.yaml @@ -15,11 +15,11 @@ ingester: store: inmemory replication_factor: 1 final_sleep: 0s - chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed - max_chunk_age: 1h # All chunks will be flushed when they hit this age, default is 1h - chunk_target_size: 1048576 # Loki will attempt to build chunks up to 1.5MB, flushing first if chunk_idle_period or max_chunk_age is reached first - chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m) - max_transfer_retries: 0 # Chunk transfers disabled + chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed + max_chunk_age: 1h # All chunks will be flushed when they hit this age, default is 1h + chunk_target_size: 1048576 # Loki will attempt to build chunks up to 1.5MB, flushing first if chunk_idle_period or max_chunk_age is reached first + chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m) + max_transfer_retries: 0 # Chunk transfers disabled schema_config: configs: @@ -35,7 +35,7 @@ storage_config: boltdb_shipper: active_index_directory: /tmp/loki/boltdb-shipper-active cache_location: /tmp/loki/boltdb-shipper-cache - cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space + cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space shared_store: filesystem filesystem: directory: /tmp/loki/chunks @@ -65,4 +65,4 @@ ruler: ring: kvstore: store: inmemory - enable_api: true \ No newline at end of file + enable_api: true diff --git a/logging-config/promtail/promtail-config.yaml b/logging-config/promtail/promtail-config.yaml index c2bcbfe..bbbff83 100644 --- a/logging-config/promtail/promtail-config.yaml +++ b/logging-config/promtail/promtail-config.yaml @@ -9,10 +9,10 @@ clients: - url: http://loki:3100/loki/api/v1/push scrape_configs: -- job_name: system - static_configs: - - targets: - - localhost - labels: - job: varlogs - __path__: /var/log/*log \ No newline at end of file + - job_name: system + static_configs: + - targets: + - localhost + labels: + job: varlogs + __path__: /var/log/*log diff --git a/vault/vault.json b/vault/vault.json index ba37ced..dd38942 100644 --- a/vault/vault.json +++ b/vault/vault.json @@ -1,18 +1,18 @@ { - "listener": { - "tcp": { - "address": "0.0.0.0:8200", - "tls_disable": 1 - } - }, - "backend": { - "file": { - "path": "/vault/file" - } - }, - "default_lease_ttl": "168h", - "max_lease_ttl": "0h", - "api_addr": "http://0.0.0.0:8200", - "ui": "true", - "disable_mlock": "true" - } \ No newline at end of file + "listener": { + "tcp": { + "address": "0.0.0.0:8200", + "tls_disable": 1 + } + }, + "backend": { + "file": { + "path": "/vault/file" + } + }, + "default_lease_ttl": "168h", + "max_lease_ttl": "0h", + "api_addr": "http://0.0.0.0:8200", + "ui": "true", + "disable_mlock": "true" +}