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

ci: refacor deployment #202

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (

const (
BotNamePaguMainnet = "Pagu-Mainnet"
BotNamePaguStaging = "Pagu-Staging"
BotNamePaguTestnet = "Pagu-Testnet"
BotNamePaguModerator = "Pagu-Moderator"
)
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:${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_mysql:
image: mysql:8.0.40-debian
hostname: pagu-db
hostname: pagu_mysql
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_mysql
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_mysql]
timeout: 5s
retries: 10

pagu-phpmyadmin:
pagu_phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: pagu-db
container_name: pagu-phpmyadmin
PMA_HOST: pagu_mysql
container_name: pagu_phpmyadmin
ports:
- "${PHPMYADMIN_PORT}:80"
depends_on:
pagu-db:
pagu_mysql:
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/config_discord_mainnet.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-mainnet:/pagu
- ${HOME}/pagu:/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/config_discord_staging.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-staging:/pagu
- ${HOME}/pagu:/pagu

pagu-discord-testnet:
image: pagu-discord:latest
container_name: pagu-discord-testnet
pagu_discord_testnet:
image: pagu:stable
container_name: pagu_discord_testnet
command: "./pagu-discord -c /pagu/config_discord_testnet.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-testnet:/pagu
- ${HOME}/pagu:/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/config_discord_moderator.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-discord-moderator:/pagu
- ${HOME}/pagu:/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-telegram -c /pagu/config_telegram_mainnet.yml run"
networks:
pagu-network:
pagu_network:
depends_on:
- pagu-phpmyadmin
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu-telegram-mainnet:/pagu
- ${HOME}/pagu:/pagu

volumes:
pagu-volume:

networks:
pagu-network:
pagu_network:
6 changes: 3 additions & 3 deletions internal/engine/command/calculator/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (bc *Calculator) GetCommand() *command.Command {
SubCommands: nil,
AppIDs: entity.AllAppIDs(),
Handler: bc.calcRewardHandler,
TargetFlag: command.TargetMaskMain,
TargetFlag: command.TargetMaskMainnet,
}

subCmdCalcFee := &command.Command{
Expand All @@ -61,7 +61,7 @@ func (bc *Calculator) GetCommand() *command.Command {
SubCommands: nil,
AppIDs: entity.AllAppIDs(),
Handler: bc.calcFeeHandler,
TargetFlag: command.TargetMaskMain,
TargetFlag: command.TargetMaskMainnet,
}

cmdBlockchain := &command.Command{
Expand All @@ -71,7 +71,7 @@ func (bc *Calculator) GetCommand() *command.Command {
AppIDs: entity.AllAppIDs(),
SubCommands: make([]*command.Command, 0),
Handler: nil,
TargetFlag: command.TargetMaskMain,
TargetFlag: command.TargetMaskMainnet,
}

cmdBlockchain.AddSubCommand(subCmdCalcReward)
Expand Down
6 changes: 3 additions & 3 deletions internal/engine/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

var (
TargetMaskMain = 1
TargetMaskTest = 2
TargetMaskMainnet = 1
TargetMaskTestnet = 2
TargetMaskModerator = 4

TargetMaskAll = TargetMaskMain | TargetMaskTest | TargetMaskModerator
TargetMaskAll = TargetMaskMainnet | TargetMaskTestnet | TargetMaskModerator
)

type InputBox int
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/command/market/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (m *Market) GetCommand() *command.Command {
SubCommands: nil,
AppIDs: entity.AllAppIDs(),
Handler: m.getPrice,
TargetFlag: command.TargetMaskMain,
TargetFlag: command.TargetMaskMainnet,
}

cmdMarket := &command.Command{
Expand All @@ -43,7 +43,7 @@ func (m *Market) GetCommand() *command.Command {
AppIDs: entity.AllAppIDs(),
SubCommands: make([]*command.Command, 0),
Handler: nil,
TargetFlag: command.TargetMaskMain,
TargetFlag: command.TargetMaskMainnet,
}

cmdMarket.AddSubCommand(subCmdPrice)
Expand Down
Loading
Loading