Skip to content

Commit

Permalink
feat: update deployment files
Browse files Browse the repository at this point in the history
  • Loading branch information
samwang0723 committed Jul 22, 2024
1 parent d1dfebd commit eea6763
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ LAST_MAIN_COMMIT_TIME=$(shell git show --no-patch --format=%cd --date=iso-strict
RELEASE_TAG=$(shell git describe --abbrev=0 --tags)
REPO_NAME=samwang0723

docker-build: lint test docker-build-api ## build docker image in M1 device
docker-build: docker-build-api ## build docker image in M1 device
@printf "\nyou can now deploy to your env of choice:\ncd deploy\nENV=dev make deploy-latest\n"

docker-build-api: TAG_NAME=$(REPO_NAME)/$(APP_NAME) ## docker build for api
Expand Down
2 changes: 2 additions & 0 deletions bin/export_mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if [ -z "$1" ]; then
exit 1
fi

# For migrating the legacy MySQL tables
# Usage: ./bin/export_mysql.sh {TABLE_NAME}
TABLE=$1

kubectl exec -it mysql-primary-0 -- mysqldump -u root -piori2008 jarvis --tables ${TABLE} --no-create-info --skip-comments --complete-insert --compatible=ansi --compact > ./${TABLE}_raw.sql
Expand Down
41 changes: 41 additions & 0 deletions bin/split_sql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#!/bin/bash

# Name of the input file
input_file="daily_closes.sql"

# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Error: $input_file not found!"
exit 1
fi

# Counter for INSERT statements
count=0

# Counter for output files
file_number=1

# Name of the current output file
output_file="daily_closes_${file_number}.sql"

# Read the input file line by line
while IFS= read -r line
do
# Write the line to the current output file
echo "$line" >> "$output_file"

# If the line starts with "INSERT INTO", increment the counter
if [[ $line == INSERT\ INTO* ]]; then
((count++))
fi

# If we've reached 10 INSERT statements, start a new file
if [ $count -eq 10 ]; then
count=0
((file_number++))
output_file="daily_closes_${file_number}.sql"
fi
done < "$input_file"

echo "Splitting complete. Check the daily_closes_*.sql files."
18 changes: 5 additions & 13 deletions configs/config.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# Server configurations
server:
name: "jarvis-api"
version: "v2.0.1"
version: "v3.0.0"
host: "0.0.0.0"
port: 8080
grpcPort: 8081

# Database credentials
database:
host: "mysql-primary-headless.default.svc.cluster.local"
port: 3306
database: "jarvis"
host: "postgres-postgresql-hl.default.svc.cluster.local"
port: "5432"
database: "jarvis_main"
maxLifetime: 10
minIdleConns: 20
maxOpenConns: 200

replica:
host: "mysql-secondary-headless.default.svc.cluster.local"
port: 3306
database: "jarvis"
maxLifetime: 10
minIdleConns: 40
maxOpenConns: 800

kafka:
brokers: ["kafka-headless.default.svc.cluster.local:9092"]
topics: ["dailycloses-v1", "stocks-v1", "threeprimary-v1", "stakeconcentration-v1"]
Expand All @@ -34,4 +26,4 @@ redis:

# Logging
log:
level: "debug"
level: "info"
6 changes: 3 additions & 3 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var (
func GetCurrentEnv() string {
envOnce.Do(func() {
inputEnv := os.Getenv(EnvCoreKey)
if env == "" {
if inputEnv == "" {
flag.StringVar(&inputEnv, "env", "local", "environment you want start the server")
flag.StringVar(&dbuser, "dbuser", "", "database username")
flag.StringVar(&jwtsecretLocal, "jwtsecret", "", "jwt secret key")
Expand All @@ -120,15 +120,15 @@ func GetCurrentEnv() string {

flag.Parse()
}
env = EnvLocal

switch inputEnv {
case "dev":
env = EnvDev
case "staging":
env = EnvStaging
case "prod":
env = EnvProd
default:
env = EnvLocal
}
})

Expand Down
2 changes: 0 additions & 2 deletions deployments/helm/jarvis/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ spec:
fieldPath: status.podIP
- name: ENVIRONMENT
value: "dev"
- name: START_CRON
value: "true"
- name: DB_USERNAME
valueFrom:
secretKeyRef:
Expand Down
49 changes: 49 additions & 0 deletions deployments/helm/postgresql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## @param architecture PostgreSQL architecture (`standalone` or `replication`)
architecture: standalone
primary:
name: primary
resources:
requests:
memory: "4Gi"
limits:
memory: "8Gi"
replication:
## @param replication.synchronousCommit Set synchronous commit mode. Allowed values: `on`, `remote_apply`, `remote_write`, `local` and `off`
## @param replication.numSynchronousReplicas Number of replicas that will have synchronous replication. Note: Cannot be greater than `readReplicas.replicaCount`.
## ref: https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT
##
synchronousCommit: "off"
numSynchronousReplicas: 0
## @param replication.applicationName Cluster application name. Useful for advanced replication settings
##
applicationName: postgres-jarvis
readReplicas:
name: replica
replicaCount: 0
auth:
postgresPassword: "postgres"
## @param auth.enablePostgresUser Assign a password to the "postgres" admin user. Otherwise, remote access will be blocked for this user
##
enablePostgresUser: false
## @param auth.replicationUsername Name of the replication user
##
replicationUsername: replica
## @param auth.existingSecret Name of existing secret to use for PostgreSQL credentials. `auth.postgresPassword`, `auth.password`, and `auth.replicationPassword` will be ignored and picked up from this secret. The secret might also contains the key `ldap-password` if LDAP is enabled. `ldap.bind_password` will be ignored and picked from this secret in this case.
##
# existingSecret: postgres-secret
## @param auth.secretKeys.adminPasswordKey Name of key in existing secret to use for PostgreSQL credentials. Only used when `auth.existingSecret` is set.
## @param auth.secretKeys.userPasswordKey Name of key in existing secret to use for PostgreSQL credentials. Only used when `auth.existingSecret` is set.
## @param auth.secretKeys.replicationPasswordKey Name of key in existing secret to use for PostgreSQL credentials. Only used when `auth.existingSecret` is set.
##
# secretKeys:
# adminPasswordKey: postgres-password
# userPasswordKey: password
# replicationPasswordKey: replication-password
postgresql:
postgresqlConfiguration:
work_mem: "64MB"
maintenance_work_mem: "512MB"
effective_cache_size: "8GB"
shared_buffers: "2GB"
metrics:
enabled: false
5 changes: 2 additions & 3 deletions internal/db/pginit/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pginit
import (
"context"
"fmt"
"net"
"time"

gofrs "github.com/jackc/pgx-gofrs-uuid"
Expand Down Expand Up @@ -49,8 +48,8 @@ type Config struct {
// opts is not provided it will initializes PGInit with default configuration.
func New(conf *Config, opts ...Option) (*PGInit, error) {
databaseURL := fmt.Sprintf(
"postgres://%s:%s@%s/%s",
conf.User, conf.Password, net.JoinHostPort(conf.Host, conf.Port), conf.Database,
"postgres://%s:%s@%s:%s/%s?sslmode=disable",
conf.User, conf.Password, conf.Host, conf.Port, conf.Database,
)

pgxConf, err := pgxpool.ParseConfig(databaseURL)
Expand Down

0 comments on commit eea6763

Please sign in to comment.