Skip to content

Commit

Permalink
Merge pull request #26 from gobicycle/develop
Browse files Browse the repository at this point in the history
deploy fix
  • Loading branch information
gobicycle authored Oct 14, 2024
2 parents c9fb035 + 1bcac6a commit 19a0ed7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
environment: TESTS
services:
postgres:
Expand Down
48 changes: 25 additions & 23 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cmd/processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"errors"
"fmt"
"github.com/gobicycle/bicycle/api"
"github.com/gobicycle/bicycle/blockchain"
"github.com/gobicycle/bicycle/config"
Expand Down Expand Up @@ -100,7 +101,7 @@ func main() {
h := api.NewHandler(dbClient, bcClient, config.Config.APIToken, wallets.Shard, *wallets.TonHotWallet.Address())
api.RegisterHandlers(apiMux, h)
go func() {
err := http.ListenAndServe(config.Config.APIHost, apiMux)
err := http.ListenAndServe(fmt.Sprintf(":%d", config.Config.APIPort), apiMux)
if err != nil {
log.Fatalf("api error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var Config = struct {
LiteServerKey string `env:"LITESERVER_KEY,required"`
Seed string `env:"SEED,required"`
DatabaseURI string `env:"DB_URI,required"`
APIHost string `env:"API_HOST" envDefault:"0.0.0.0:8081"`
APIPort int `env:"API_PORT,required"`
APIToken string `env:"API_TOKEN,required"`
Testnet bool `env:"IS_TESTNET" envDefault:"true"`
ColdWalletString string `env:"COLD_WALLET"`
Expand Down
14 changes: 14 additions & 0 deletions deploy/db/02_create_readonly_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

if [ -z "$POSTGRES_READONLY_PASSWORD" ]; then
echo "Environment variable POSTGRES_READONLY_PASSWORD is not set. Exiting."
exit 1
fi

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER pp_readonly WITH PASSWORD '$POSTGRES_READONLY_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO pp_readonly;
GRANT USAGE ON SCHEMA payments TO pp_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA payments TO pp_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA payments GRANT SELECT ON TABLES TO pp_readonly;
EOSQL
6 changes: 3 additions & 3 deletions deploy/grafana/main/provisioning/datasources/data_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ datasources:
uid: DS_POSTGRES
type: postgres
url: payment_processor_db:5432
database: payment_processor
user: pp_user
database: $POSTGRES_DB
user: pp_readonly
secureJsonData:
password: $POSTGRES_PASSWORD
password: $POSTGRES_READONLY_PASSWORD
isDefault: true
jsonData:
sslmode: disable # disable/require/verify-ca/verify-full
Expand Down
36 changes: 14 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,27 @@ services:
image: postgres:14
container_name: payment_processor_db
volumes:
- ./deploy/db/01_init.up.sql:/docker-entrypoint-initdb.d/init.sql
- ./deploy/db/01_init.up.sql:/docker-entrypoint-initdb.d/01_init.up.sql
- ./deploy/db/02_create_readonly_user.sh:/docker-entrypoint-initdb.d/02_create_readonly_user.sh
- bicycle-postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
restart: always
env_file:
- .env
environment:
POSTGRES_DB: "payment_processor"
POSTGRES_USER: "pp_user"
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_READONLY_PASSWORD: ${POSTGRES_READONLY_PASSWORD} # For grafana
networks:
- p-network

payment-processor:
image: payment-processor
container_name: payment_processor
ports:
- "8081:8081"
- "127.0.0.1:8081:${API_PORT}"
restart: unless-stopped
env_file:
- .env
environment:
DB_URI: "postgres://pp_user:${POSTGRES_PASSWORD}@payment_processor_db:5432/payment_processor"
DB_URI: ${DB_URI} # example: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@payment_processor_db:5432/${POSTGRES_DB}"
API_PORT: ${API_PORT}
API_TOKEN: ${API_TOKEN}
COLD_WALLET: ${COLD_WALLET}
JETTONS: ${JETTONS}
Expand All @@ -46,17 +43,16 @@ services:
container_name: payment_grafana
restart: always
ports:
- '3001:3000'
- '127.0.0.1:3001:3000'
volumes:
- ./deploy/grafana/main/provisioning/datasources:/etc/grafana/provisioning/datasources
- ./deploy/grafana/main/provisioning/dashboards:/etc/grafana/provisioning/dashboards
- ./deploy/grafana/main/dashboards:/etc/dashboards
env_file:
- .env
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: admin
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
GF_SECURITY_ADMIN_USER: admin # TODO: change
GF_SECURITY_ADMIN_PASSWORD: admin # TODO: change
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_READONLY_PASSWORD: ${POSTGRES_READONLY_PASSWORD}
networks:
- p-network

Expand All @@ -65,23 +61,19 @@ services:
container_name: payment_rabbitmq
restart: always
ports:
- '15672:15672'
- '5672:5672'
- '127.0.0.1:5672:5672'
networks:
- p-network

payment-prometheus:
image: prom/prometheus:latest
container_name: payment_prometheus
restart: always
ports:
- '9090:9090'
volumes:
- ./deploy/prometheus/main:/etc/prometheus
user: "$UID:$GID"
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--web.external-url=http://localhost:9090'
networks:
- p-network

Expand Down
12 changes: 6 additions & 6 deletions docker-compose-tests.yml → tests/docker-compose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- "5433:5432"
restart: always
env_file:
- .env
- ../.env
environment:
POSTGRES_DB: "payment_processor"
POSTGRES_USER: "pp_user"
Expand All @@ -28,7 +28,7 @@ services:
- "5434:5432"
restart: always
env_file:
- .env
- ../.env
environment:
POSTGRES_DB: "payment_processor"
POSTGRES_USER: "pp_user"
Expand All @@ -43,7 +43,7 @@ services:
- "8082:8081"
restart: unless-stopped
env_file:
- .env
- ../.env
environment:
DB_URI: "postgres://pp_user:${POSTGRES_PASSWORD}@payment_processor_db_a:5432/payment_processor"
API_TOKEN: ${API_TOKEN}
Expand All @@ -64,7 +64,7 @@ services:
- "8083:8081"
restart: unless-stopped
env_file:
- .env
- ../.env
environment:
DB_URI: "postgres://pp_user:${POSTGRES_PASSWORD}@payment_processor_db_b:5432/payment_processor"
API_TOKEN: ${API_TOKEN}
Expand All @@ -89,7 +89,7 @@ services:
- ./deploy/grafana/test/provisioning/dashboards:/etc/grafana/provisioning/dashboards
- ./deploy/grafana/test/dashboards:/etc/dashboards
env_file:
- .env
- ../.env
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: admin
Expand Down Expand Up @@ -117,7 +117,7 @@ services:
container_name: payment_test
restart: unless-stopped
env_file:
- .env
- ../.env
environment:
DB_URI: "postgres://pp_user:${POSTGRES_PASSWORD}@payment_processor_db:5432/payment_processor"
API_TOKEN: ${API_TOKEN}
Expand Down

0 comments on commit 19a0ed7

Please sign in to comment.