Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added console #714

Merged
merged 19 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .config/python/dev/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests==2.31.0
docker==6.1.3
molecule==6.0.3
molecule-plugins==23.5.3
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ jobs:
- distro: centosstream9
tag: latest
namespace: glillico
- distro: centosstream8
tag: latest
namespace: glillico

steps:
- name: Set TERM environment variable
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/molecule_pg_upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ jobs:
- distro: centosstream9
tag: latest
namespace: glillico
- distro: centosstream8
tag: latest
namespace: glillico

steps:
- name: Set TERM environment variable
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/schedule_pg_centosstream8.yml

This file was deleted.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ RedHat and Debian based distros (x86_64)
###### Supported Linux Distributions:
- **Debian**: 10, 11, 12
- **Ubuntu**: 20.04, 22.04
- **CentOS**: 7, 8
- **CentOS Stream**: 8, 9
- **Oracle Linux**: 7, 8, 9
- **CentOS Stream**: 9
- **Oracle Linux**: 8, 9
- **Rocky Linux**: 8, 9
- **AlmaLinux**: 8, 9

Expand All @@ -109,7 +108,6 @@ _Table of results of daily automated testing of cluster deployment:_
| Debian 12 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_debian11.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_debian12.yml) |
| Ubuntu 20.04 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_ubuntu2004.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_ubuntu2004.yml) |
| Ubuntu 22.04 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_ubuntu2204.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_ubuntu2204.yml) |
| CentOS Stream 8 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_centosstream8.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_centosstream8.yml) |
| CentOS Stream 9 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_centosstream9.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_centosstream9.yml) |
| Oracle Linux 8 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_oracle_linux8.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_oracle_linux8.yml) |
| Oracle Linux 9 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_oracle_linux9.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_oracle_linux9.yml) |
Expand Down
16 changes: 16 additions & 0 deletions console/service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.22.3-bookworm as builder
WORKDIR /go/src/pg-console

COPY . .

RUN make build_in_docker

FROM debian:bookworm-slim

ENV PROJECT_NAME=pg-console
ENV PROJECT_PATH=/go/src/${PROJECT_NAME}

COPY --from=builder ${PROJECT_PATH}/${PROJECT_NAME} /usr/local/bin/
COPY --from=builder ${PROJECT_PATH}/db/migrations /etc/db/migrations

CMD ${PROJECT_NAME}
31 changes: 31 additions & 0 deletions console/service/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ifndef GO_BIN
override GO_BIN = "pg-console"
endif

APP = main.go

swagger_install:
{ \
export my_dir=$$(pwd) ;\
export dir=$$(mktemp -d) ;\
retry_count=0 ;\
max_retries=5 ;\
until [ "$$retry_count" -ge "$$max_retries" ]; do \
git clone https://github.com/go-swagger/go-swagger "$$dir" && break ;\
retry_count=$$((retry_count+1)) ;\
echo "Retry $$retry_count/$$max_retries" ;\
sleep 1 ;\
done ;\
cd "$$dir" ;\
go install ./cmd/swagger ;\
cd "$$my_dir" ;\
swagger version ;\
}

build: ## Build app
@go build -o $(GO_BIN) $(APP)

swagger:
@swagger generate server --name PgConsole --spec api/swagger.yaml --principal interface{} --exclude-main

build_in_docker: swagger_install swagger build
104 changes: 104 additions & 0 deletions console/service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# postgesql-cluster-console server

Server side for postgresql-cluster-console.
REST service that implements API for WEB integration.
Project is written on `golang` and used [swagger](https://github.com/go-swagger/go-swagger) for server-side auto generation.
Server is received requests from WEB for creation and manage clusters.
Under the hood server uses docker for running ansible scripts with cluster deploy logic.

## Build
Swagger specification is used for creating server REST API. First of all you need to install swagger tool to build auto generated go-files.
```
export dir=$$(mktemp -d)
git clone https://github.com/go-swagger/go-swagger "$$dir"
cd "$$dir"
go install ./cmd/swagger
```
Then you need to generate server side files:
```
swagger generate server --name DbConsole --spec api/swagger.yaml --principal interface{} --exclude-main
```

After that you can build server with following command:
```
go build -o pg-console main.go
```

The project also contains makefile with all commands. So you can just do next steps:
```
make swagger_install
make swagger
make build
```

## Configuration
Server is configured via the environment. The following environment variables can be used:
```
KEY TYPE DEFAULT REQUIRED DESCRIPTION
PG_CONSOLE_LOGGER_LEVEL String DEBUG Log level. Accepted values: [TRACE, DEBUG, INFO, WARN, ERROR, FATAL, PANIC]
PG_CONSOLE_HTTP_HOST String 0.0.0.0 Accepted host for connection. '0.0.0.0' for all hosts
PG_CONSOLE_HTTP_PORT Integer 8080 Listening port
PG_CONSOLE_HTTP_WRITETIMEOUT Duration 10s Maximum duration before timing out write of the response
PG_CONSOLE_HTTP_READTIMEOUT Duration 10s Maximum duration before timing out read of the request
PG_CONSOLE_HTTPS_ISUSED True or False false Flag for turn on/off https
PG_CONSOLE_HTTPS_HOST String 0.0.0.0 Accepted host for connection. '0.0.0.0' for all hosts
PG_CONSOLE_HTTPS_PORT Integer 8081 Listening port
PG_CONSOLE_HTTPS_CACERT String /etc/pg_console/cacert.pem The certificate to use for secure connections
PG_CONSOLE_HTTPS_SERVERCERT String /etc/pg_console/server-cert.pem The certificate authority file to be used with mutual tls auth
PG_CONSOLE_HTTPS_SERVERKEY String /etc/pg_console/server-key.pem The private key to use for secure connections
PG_CONSOLE_AUTHORIZATION_TOKEN String auth_token Authorization token for REST API
PG_CONSOLE_DB_HOST String localhost Database host
PG_CONSOLE_DB_PORT Unsigned Integer 5432 Database port
PG_CONSOLE_DB_DBNAME String postgres Database name
PG_CONSOLE_DB_USER String postgres Database user name
PG_CONSOLE_DB_PASSWORD String postgres-pass Database user password
PG_CONSOLE_DB_MAXCONNS Integer 10 MaxConns is the maximum size of the pool
PG_CONSOLE_DB_MAXCONNLIFETIME Duration 60s MaxConnLifetime is the duration since creation after which a connection will be automatically closed
PG_CONSOLE_DB_MAXCONNIDLETIME Duration 60s MaxConnIdleTime is the duration after which an idle connection will be automatically closed by the health check
PG_CONSOLE_DB_MIGRATIONDIR String /etc/db/migrations Path to directory with migration scripts
PG_CONSOLE_ENCRYPTIONKEY String super_secret Encryption key for secret storage
PG_CONSOLE_DOCKER_HOST String unix:///var/run/docker.sock Docker host
PG_CONSOLE_DOCKER_LOGDIR String /tmp/ansible Directory inside docker container for ansible json log
PG_CONSOLE_DOCKER_IMAGE String vitabaks/postgresql_cluster:cloud Docker image for postgresql_cluster
PG_CONSOLE_LOGWATCHER_RUNEVERY Duration 1m LogWatcher run interval
PG_CONSOLE_LOGWATCHER_ANALYZEPAST Duration 48h LogWatcher gets operations to analyze which created_at > now() - AnalyzePast
PG_CONSOLE_CLUSTERWATCHER_RUNEVERY Duration 1m ClusterWatcher run interval
PG_CONSOLE_CLUSTERWATCHER_POOLSIZE Integer 4 Amount of async request from ClusterWatcher
```

## Project architecture
```
|-api - swagger specification
|-internal - folder with all internal logic
| |-controllers - REST fuctions and basic logic for handlers
| | |-cluster - REST API for clusters objects
| | |-dictionary - REST API for dictionaries objects
| | |-operation - REST API for operations objects
| | |-project - REST API for projects objects
| | |-secret - REST API for secrets objects
| |-convert - functions for convert DB model for REST model
| |-db - base DB functions
| |-service - common logic for aggrigation all server logic
| |-storage - DB logic
| |-watcher - async watchers
| | |-log_collector.go - collecting logs from running docker container
| | |-log_watcher.go - JSON container log parser
| | |-server_watcher.go - collecting servers statuses
| |-xdocker - basic logic for docker
|-middleware - common REST middlewares for server
|-migrations - DB migrations logic
|-pkg - folder with common logic
| |-patroni - client for patroni integration
| |-tracer - base structure for tracing
|-*models - auto-generated files with REST models
|-*restapi - auto-generated files with REST server
|-main.go - entry point
```

## Secrets
Server handles different kind of secrets, such as:
* cloud secrets, that uses for cloud connections
* ssh keys and passwords for connection to owm machine servers
* database secrets

Be attention to use `TRACE` level of logging. With `TRACE` level some kind of secrets can be present in logs.
1 change: 1 addition & 0 deletions console/service/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Loading
Loading