Skip to content

Commit

Permalink
ci: refacor deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Dec 28, 2024
1 parent 5f03a72 commit 7c00f34
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 125 deletions.
20 changes: 8 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ type Database struct {
}

type Wallet struct {
Enable bool `yaml:"enable"`
Address string `yaml:"address"`
Path string `yaml:"path"`
Password string `yaml:"password"`
RPCUrl string `yaml:"rpc"`
}

type DiscordBot struct {
Expand Down Expand Up @@ -105,19 +103,17 @@ func Load(path string) (*Config, error) {

// BasicCheck validate presence of required config variables.
func (cfg *Config) BasicCheck() error {
if cfg.Wallet.Enable {
if cfg.Wallet.Address == "" {
return fmt.Errorf("config: basic check error: WALLET_ADDRESS dose not set")
}

// Check if the WalletPath exists.
if !util.PathExists(cfg.Wallet.Path) {
return fmt.Errorf("config: basic check error: WALLET_PATH does not exist: %s", cfg.Wallet.Path)
}
if cfg.Wallet.Address == "" {
return fmt.Errorf("config: Wallet address dose not set")
}

// Check if the WalletPath exists.
if !util.PathExists(cfg.Wallet.Path) {
return fmt.Errorf("config: Wallet does not exist: %s", cfg.Wallet.Path)
}

if len(cfg.NetworkNodes) == 0 {
return fmt.Errorf("config: basic check error: NETWORK_NODES is not set or incorrect")
return fmt.Errorf("config: network nodes is empty")
}

return nil
Expand Down
54 changes: 34 additions & 20 deletions config/config.sample.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bot_name: "Pagu-Development"
network: "Mainnet" # Specify the network the bot will use: Mainnet, Testnet, or Localnet.

# Specify the network the bot will use: Mainnet, Testnet, or Localnet.
network: "Mainnet"

# Pactus clients
local_node: "localhost:50051" # Address of the local Pactus node for direct communication.
Expand All @@ -15,36 +17,48 @@ network_nodes:
]

# Wallet configuration
#
# Use the Pactus Wallet command-line tool to create a wallet.
# For detailed instructions, visit:
# https://docs.pactus.org/tutorials/pactus-wallet/
#
# The sample wallet here is neutered, which means it is read-only and can't be used to sign any transactions.
# You can create a full wallet and replace it.
wallet:
# Set to true to enable wallet functionality.
enable: false
# Use the `./pactus-wallet` command-line tool to create a wallet.
# For detailed instructions, visit:
# https://docs.pactus.org/tutorials/pactus-wallet/
# Uncomment and set the following fields if the wallet is enabled:
# address: <PAGU-WALLET-ADDRESS> # Wallet address for transactions.
# rpc: <PAGU-WALLET-RPC> # RPC endpoint of the wallet.
# path: <PATH-TO-WALLET> # Path to the wallet file.
# password: <WALLET-PASSWORD> # Password for the wallet file.

# Phoenix TestNet faucet configuration
# This is the Pagu wallet address to send transactions
address: pc1re5uxrtdve6gama8veqt0ttz5vgfne73w9e03w6

# Path to the wallet file.
path: ./config/wallet.sample.neutered

# Password for the wallet file.
password:

# Phoenix (TestNet) configuration
phoenix:
faucet_amount: 5 # Number of coins to send when the faucet is used.
# Number of coins to send when the faucet is used.
faucet_amount: 5

# Database configuration
database:
url: "sqlite:db.sqlite" # Database type or connection string.
# The database URL specifies the database type and connection string.
# Pagu supports MySQL and SQLite.
url: "sqlite:db.sqlite"

# Discord integration configuration
# Uncomment and set appropriate values to integrate Pagu with your Discord server.
# Set appropriate values to integrate Pagu with your Discord server.
discord:
# token: <DISCORD_APPLICATION_TOKEN> # Discord bot application token.
# guild_id: <DISCORD_SERVER_GUILD_ID> # Discord server ID where the bot will operate.
# Discord bot application token.
token:

# Discord server ID where the bot will operate.
guild_id:

# Telegram integration configuration
# Uncomment and set appropriate values to integrate Pagu with your Telegram account.
# Set appropriate values to integrate Pagu with your Telegram account.
telegram:
# bot_token: <TELEGRAM-BOT-TOKEN> # Telegram bot token for authentication.
# Telegram bot token for authentication.
bot_token:

# Logger configuration
logger:
Expand Down
37 changes: 37 additions & 0 deletions config/wallet.sample.neutered
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": 2,
"uuid": "dc445698-cd6f-46d6-adcb-bb90254ae506",
"created_at": "2024-12-28T12:18:37Z",
"network": 0,
"crc": 2550816060,
"vault": {
"type": 2,
"coin_type": 21888,
"addresses": {
"pc1re5uxrtdve6gama8veqt0ttz5vgfne73w9e03w6": {
"address": "pc1re5uxrtdve6gama8veqt0ttz5vgfne73w9e03w6",
"public_key": "public1ryxkxpppc4ef8pcnjxn8sph4u3lahemzdeeuvsc0hsdg2eewv7pmstyzp87",
"label": "Pagu Address",
"path": "m/44'/21888'/3'/0'"
}
},
"encrypter": {},
"key_store": "{}",
"purposes": {
"purpose_bls": {
"xpub_account": "xpublic1pqdwnqqyqsp2spqqpqqqgqgx8avwvym2mlmhk5tatlmp8smml62rtclyj732wrr7xfpzngkjkluqxpy082d9dst4r5lhw4f4p9a4yycdtlgm5qve4pgw79kdu029e44ke7csjdlpwuy0dcys7m77zfflt7yvakwc8qt9dutjukk2xxzmkrexg2mg6c9p3ysdgvja26m7rl8pcdhxfmnyq3x27gmgpzvf79ru3xxqjsfl9g",
"xpub_validator": "xpublic1pqdwnqqyqsp2spqqzqqqgqgzkpldp7s5y29mxpngx49qznj4wttkkan7tpphcmp0f702ef50cmsqxppzjt8tayuns0rcp5js90rg6dct9krtdg29yfspxm0zpnl5uyqypecqgpp3azx884tzer5wrk9rjnufqk3hejjusr4wy8wtf2gum8a4ls58v255kllg25kz4lxlmulkfaxcklqh6dxsdxk4zrd3kevgcc0sd9ww4k",
"next_account_index": 0,
"next_validator_index": 0
},
"purpose_bip44": {
"next_ed25519_index": 1
}
}
},
"history": {
"transactions": null,
"activities": null,
"pendings": null
}
}
9 changes: 1 addition & 8 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ WORKDIR /pagu
COPY .. .
RUN make build-discord build-telegram

# Discord bot
FROM alpine:3.14 AS discord
FROM alpine:3.14 AS pagu
WORKDIR /bin
COPY --from=builder /pagu/build/pagu-discord .
CMD ["./pagu-discord", "-c", "/pagu/config.yml", "run"]

# Telegram bot
FROM alpine:3.14 AS telegram
WORKDIR /bin
COPY --from=builder /pagu/build/pagu-telegram .
CMD ["./pagu-telegram", "-c", "/pagu/config.yml", "run"]
3 changes: 1 addition & 2 deletions deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ fi

echo "Building ${DOCKER_TAG} version"

docker build -t pagu-discord:${DOCKER_TAG} -f ./deployment/Dockerfile . --target discord
docker build -t pagu-telegram:${DOCKER_TAG} -f ./deployment/Dockerfile . --target telegram
docker build -t pagu-discord:${DOCKER_TAG} -f ./deployment/Dockerfile .

docker compose -f ./deployment/docker-compose.yml down
docker compose -f ./deployment/docker-compose.yml up -d
Expand Down
87 changes: 46 additions & 41 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,94 @@
services:
pagu-db:
pagu_db:
image: mysql:8.0.40-debian
hostname: pagu-db
hostname: pagu_db
environment:
MYSQL_DATABASE: pagu
MYSQL_ROOT_PASSWORD: ${PAGU_DB_ROOT_PASSWORD}
MYSQL_USER: ${PAGU_DB_USER}
MYSQL_PASSWORD: ${PAGU_DB_USER_PASSWORD}
container_name: pagu-db
container_name: pagu_db
volumes:
- ${HOME}/mysql_data:/var/lib/mysql
networks:
- pagu-network
- pagu_network
env_file: "secrets.env"
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", pagu-db]
test: ["CMD", "mysqladmin" ,"ping", "-h", pagu_db]
timeout: 5s
retries: 10

pagu-phpmyadmin:
pagu_phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: pagu-db
container_name: pagu-phpmyadmin
PMA_HOST: pagu_db
container_name: pagu_phpmyadmin
ports:
- "${PHPMYADMIN_PORT}:80"
depends_on:
pagu-db:
pagu_db:
condition: service_healthy
networks:
- pagu-network
- pagu_network
env_file: "secrets.env"

pagu-discord-mainnet:
image: pagu-discord:stable
container_name: pagu-discord-mainnet
pagu_discord_mainnet:
image: pagu:stable
container_name: pagu_discord_mainnet
command: "./pagu-discord -c /pagu/pagu_discord_mainnet.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-mainnet:/pagu
- ${HOME}/pagu_discord_mainnet:/pagu

pagu-discord-staging:
image: pagu-discord:latest
container_name: pagu-discord-staging
pagu_discord_staging:
image: pagu:latest
container_name: pagu_discord_staging
command: "./pagu-discord -c /pagu/pagu_discord_staging.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-staging:/pagu
- ${HOME}/pagu_discord_staging:/pagu

pagu-discord-testnet:
image: pagu-discord:latest
container_name: pagu-discord-testnet
pagu_discord_testnet:
image: pagu:latest
container_name: pagu_discord_testnet
command: "./pagu-discord -c /pagu/pagu_discord_testnet.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-testnet:/pagu
- ${HOME}/pagu_discord_testnet:/pagu

pagu-discord-moderator:
image: pagu-discord:stable
container_name: pagu-discord-moderator
pagu_discord_moderator:
image: pagu:stable
container_name: pagu_discord_moderator
command: "./pagu-discord -c /pagu/pagu_discord_moderator.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-moderator:/pagu
- ${HOME}/pagu_discord_moderator:/pagu

pagu-telegram-mainnet:
image: pagu-telegram:stable
container_name: pagu-telegram-mainnet
pagu_telegram_mainnet:
image: pagu:stable
container_name: pagu_telegram_mainnet
command: "./pagu-discord -c /pagu/pagu_discord_telegram.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-telegram-mainnet:/pagu
- ${HOME}/pagu_telegram_mainnet:/pagu

volumes:
pagu-volume:

networks:
pagu-network:
pagu_network:
24 changes: 6 additions & 18 deletions internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ func NewBotEngine(cfg *config.Config) (*BotEngine, error) {

db, err := repository.NewDB(cfg.Database.URL)
if err != nil {
cancel()

return nil, err

Check failure on line 52 in internal/engine/engine.go

View workflow job for this annotation

GitHub Actions / lint

lostcancel: this return statement may be reached without using the cancel var defined on line 48 (govet)
}
log.Info("database loaded successfully")

mgr := client.NewClientMgr(ctx)

if cfg.LocalNode != "" {
localClient, err := client.NewClient(cfg.LocalNode)
if err != nil {
cancel()

return nil, err
}

Expand All @@ -71,25 +66,18 @@ func NewBotEngine(cfg *config.Config) (*BotEngine, error) {
for _, nn := range cfg.NetworkNodes {
c, err := client.NewClient(nn)
if err != nil {
log.Error("can't add new network node client", "err", err, "addr", nn)
log.Warn("error on adding new network client", "err", err, "addr", nn)
}
mgr.AddClient(c)
}

var wlt wallet.IWallet
if cfg.Wallet.Enable {
// load or create wallet.
wlt, err = wallet.Open(cfg.Wallet)
if err != nil {
cancel()

return nil, WalletError{
Reason: err.Error(),
}
wlt, err := wallet.Open(cfg.Wallet)
if err != nil {
return nil, WalletError{
Reason: err.Error(),
}

log.Info("wallet opened successfully", "address", wlt.Address())
}
log.Info("wallet opened successfully", "address", wlt.Address())

if cfg.BotName == config.BotNamePaguModerator {
zapToMailConfig := zoho.ZapToMailerConfig{
Expand Down
Loading

0 comments on commit 7c00f34

Please sign in to comment.