Skip to content

Commit

Permalink
clean README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
shamrin committed Dec 27, 2020
1 parent efad108 commit 931377a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# To configure this workflow, set up secrets in your workspace:
# 1. GCP_PROJECT with the name of the project
# 2. GKE_SA_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs).
# 2. GCP_SA_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs).
# 3. AIVEN_*

name: sitewatch deploy
Expand Down
52 changes: 34 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Retool demo](./sitewatch.gif)

**(The UI is made in [Retool](https://retool.com/), drag-and-drop build-your-own-admin-UI service. It's very easy.)**
**(The UI above was quickly made in [Retool](https://retool.com/), drag-and-drop build-your-own-admin-UI service.)**

`sitewatch` is an experiment to play with:

Expand All @@ -14,6 +14,8 @@
- [Posgres](https://www.postgresql.org/): LISTEN/NOTIFY
- [Retool](https://retool.com/): quickly build admin UI

It's also a template for a Python daemon running on Google Cloud.

## Start hacking

Prerequisites:
Expand All @@ -22,29 +24,39 @@ Prerequisites:
* [poetry](https://python-poetry.org/docs/#installation)
* Docker
* [Google Cloud SDK](https://cloud.google.com/sdk/docs/install)
* [jq](https://stedolan.github.io/jq/)
* Aiven project with Kafka and Postgres running

Setup:
```
poetry env use python3.9
poetry install
```

Start server directly:
Load Aiven credentials and service URIs to `.env/` (replace `pg-123456` and `kafka-123456` with correct service names in Aiven):
```
./start
poetry run avn user login
./save-aiven-creds pg-123456 kafka-123456
```

Build and start Docker container:
Start services directly:
```
./docker-start
./start watch
./start report
```

Build and start services via Docker container:
```
./docker-start watch
./docker-start report
```

Lint and test:
```
./lint && ./test
```

To update the snapshots (in case of "snapshots failed" error):
To update test snapshots (in case of "snapshots failed" error):
```
./test.sh --snapshot-update
```
Expand All @@ -56,28 +68,32 @@ Format code with [black](https://github.com/ambv/black):

## Deploy

Create Kafka and Postgres services on [Aiven](aiven.io). Add `report-topic` topic in Kafka. Note project name and services' names. For example: `project-12345`, `pg-123456`, `kafka-123456`.

Install [jq](https://stedolan.github.io/jq/).
Dependencies:

Create Aiven access token and save it to `.env/`:
* [Aiven](https://aiven.io): Kafka and Postgres
* Google Cloud: [Containers](https://cloud.google.com/compute/docs/containers)

```
poetry run avn user access-token create --description 'google cloud container' --json | jq -r '.[0].full_token' > .env/AIVEN_TOKEN
```
Service is automatically deployed on each commit to `main` branch via GitHub Actions [deploy.yml](.github/workflows/deploy.yml) workflow. The workflow requires the following repository secrets to be defined:

Configure Google Cloud SDK:
| Secret name | Description |
| --- | --- |
| `AIVEN_TOKEN` | Aiven API token |
| `AIVEN_EMAIL` | Aiven user email |
| `AIVEN_PROJECT` | Aiven project name, e.g. `project-12345` |
| `AIVEN_PG_SERVICE` | Aiven Postgres service name, e.g. `pg-123456` |
| `AIVEN_KAFKA_SERVICE` | Aiven Kafka service name, e.g. `kafka-123456`. Should have `report-topic` topic. |
| `GCP_PROJECT` | Google Cloud project name |
| `GCP_SA_KEY` | Google Cloud service account key, see `deploy.yml` for details. |

Getting `AIVEN_TOKEN`:
```
gcloud init
gcloud config set run/region europe-north1
poetry run avn user access-token create --description 'google cloud container' --json | jq -r '.[0].full_token'
```

*to be continued*

## View container logs on Compute Engine

```
gcloud init
./logs watch
./logs report
```

0 comments on commit 931377a

Please sign in to comment.