Skip to content

Commit

Permalink
feat: run linter once on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed Jan 18, 2024
1 parent 1a329df commit acc3bee
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 107 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- name: Run pre-commit hooks
run: pre-commit run --all-files
53 changes: 26 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ repos:
rev: v3.0.0
hooks:
- id: prettier
exclude: ^(frontend/|CHANGELOG.md)
exclude: ^(frontend/|CHANGELOG.md)
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -33,17 +29,16 @@ General Flow
<p align='center'><i>Sarthi-Deploy GHA will not clutter your PR with comments - it will keep updating its earlier comment</i></p>
<img width="937" alt="Screenshot 2024-01-08 at 2 31 14 PM" src="https://github.com/tushar5526/sarthi/assets/30565750/31697b06-fd67-40d5-84ce-c5d43dcdd2bf">

## 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
Expand All @@ -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.
<p align="center"><img width="720" alt="Screenshot 2024-01-04 at 1 39 59 AM" src="https://github.com/tushar5526/sarthi/assets/30565750/a42db693-fcee-4a4d-8095-a1bdd2954f33"></p>

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)
<p align="center"><img width="720" alt="Screenshot 2024-01-04 at 1 39 59 AM" src="https://github.com/tushar5526/sarthi/assets/30565750/a42db693-fcee-4a4d-8095-a1bdd2954f33"></p>
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)
<p align="center"><img width="720" alt="Screenshot 2024-01-04 at 1 42 56 AM" src="https://github.com/tushar5526/sarthi/assets/30565750/13429693-78a1-4349-9a9c-cc2d921b4ad1"></p>

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`
<p align="center"><img width="720" alt="Screenshot 2024-01-04 at 1 44 44 AM" src="https://github.com/tushar5526/sarthi/assets/30565750/842704b8-33b3-4aca-abae-6739878bae69"></p>
<p align="center"><img width="720" alt="Screenshot 2024-01-04 at 1 44 44 AM" src="https://github.com/tushar5526/sarthi/assets/30565750/842704b8-33b3-4aca-abae-6739878bae69"></p>

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.
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3'
version: "3"

services:

nginx:
image: nginx:latest
restart: always
Expand Down Expand Up @@ -41,7 +40,7 @@ services:
SECRET_TEXT: ${SECRET_TEXT}
depends_on:
- vault

loki:
image: grafana/loki:latest
restart: always
Expand All @@ -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:
Expand Down Expand Up @@ -105,4 +104,4 @@ services:
volumes:
grafana:
portainer_data:
vault-secrets:
vault-secrets:
6 changes: 3 additions & 3 deletions logging-config/grafana/dashboards/dashboard.yml
Original file line number Diff line number Diff line change
@@ -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
path: /etc/grafana/provisioning/dashboards
2 changes: 1 addition & 1 deletion logging-config/grafana/dashboards/docker_logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@
"uid": "c9398592-6dc7-48c7-9d19-fba0afa195d0",
"version": 7,
"weekStart": ""
}
}
2 changes: 1 addition & 1 deletion logging-config/grafana/datasources/datasources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ datasources:
url: http://loki:3100
basicAuth: false
isDefault: true
editable: true
editable: true
14 changes: 7 additions & 7 deletions logging-config/loki/loki-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -65,4 +65,4 @@ ruler:
ring:
kvstore:
store: inmemory
enable_api: true
enable_api: true
14 changes: 7 additions & 7 deletions logging-config/promtail/promtail-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
34 changes: 17 additions & 17 deletions vault/vault.json
Original file line number Diff line number Diff line change
@@ -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"
}
"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"
}

0 comments on commit acc3bee

Please sign in to comment.