Skip to content

Commit

Permalink
feat: auto deployment (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre authored Dec 27, 2024
1 parent 9df147d commit 59652e6
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 193 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploying

on:
push:
branches:
- main
tags:
- 'v*'

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: SSH into server and deploy Pagu
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
script: |
cd source
git pull
export PAGU_DB_ROOT_PASSWORD=${{ secrets.PAGU_DB_ROOT_PASSWORD }}
export PAGU_DB_USER=${{ secrets.PAGU_DB_USER }}
export PAGU_DB_USER_PASSWORD=${{ secrets.PAGU_DB_USER_PASSWORD }}
export PHPMYADMIN_PORT=${{ secrets.PHPMYADMIN_PORT }}
bash ./deployment/deploy.sh
18 changes: 18 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Builder stage
FROM golang:1.23.3-alpine AS builder
RUN apk add --no-cache bash make
WORKDIR /pagu
COPY .. .
RUN make build-discord build-telegram

# Discord bot
FROM alpine:3.14 AS discord
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"]
11 changes: 0 additions & 11 deletions deployment/Makefile

This file was deleted.

26 changes: 26 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Auto-Deployment for Pagu Project

This project includes an automated deployment process for
both the `stable` and `latest` versions of the Pagu Discord and Telegram bots.

### Deployment Overview

The deployment system uses the following mechanisms:

- **Stable Version**: Activated when a Git tag is pushed to the repository.
- **Latest Version**: Activated when changes are pushed to the `main` branch.

### How to Create a Tag:

To create a tag and push it to the repository, follow these steps:

1. Ensure that the origin is set to the current repository, not your fork.
2. Ensure that the Pagu's [version](../version.go) is updated.
3. Run the following commands:

```bash
VERSION=0.?.?
git pull origin
git tag -s -a v${VERSION} -m "Version ${VERSION}"
git push origin v${VERSION}
```
19 changes: 0 additions & 19 deletions deployment/cli/Dockerfile

This file was deleted.

26 changes: 26 additions & 0 deletions deployment/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

DOCKER_TAG="latest"

TAG=$(git describe --tags --exact-match 2> /dev/null) || echo ""

if [[ -n "$TAG" ]]; then
DOCKER_TAG="stable"
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 compose -f ./deployment/docker-compose.yml down
docker compose -f ./deployment/docker-compose.yml up -d

## Some cleanup
echo "Cleanup"

docker builder prune -f
docker image prune -f
docker container prune -f
21 changes: 0 additions & 21 deletions deployment/discord/Dockerfile.Mainnet

This file was deleted.

21 changes: 0 additions & 21 deletions deployment/discord/Dockerfile.Mod

This file was deleted.

21 changes: 0 additions & 21 deletions deployment/discord/Dockerfile.Testnet

This file was deleted.

130 changes: 51 additions & 79 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,115 +1,87 @@
version: '3'

networks:
pagu-network:
external: true

services:
pagu-db:
image: mysql:5.7.42-debian
image: mysql:8.0.40-debian
hostname: pagu-db
environment:
MYSQL_ROOT_PASSWORD: ${PAGU_DB_PASSWORD}
MYSQL_DATABASE: pagu
expose:
- 4417
ports:
- "4417:3306"
MYSQL_ROOT_PASSWORD: ${PAGU_DB_ROOT_PASSWORD}
MYSQL_USER: ${PAGU_DB_USER}
MYSQL_PASSWORD: ${PAGU_DB_USER_PASSWORD}
container_name: pagu-db
networks:
pagu-network:
volumes:
- pagu-db-data:/var/lib/mysql
- ${HOME}/mysql_data:/var/lib/mysql
networks:
- pagu-network
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", pagu-db]
timeout: 5s
retries: 10

pagu-phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: pagu-db
container_name: pagu-phpmyadmin
ports:
- "4418:80"
networks:
pagu-network:
- "${PHPMYADMIN_PORT}:80"
depends_on:
- pagu-db
pagu-cli:
build:
context: ../.
dockerfile: deployment/cli/Dockerfile
hostname: pagu-cli
container_name: pagu-cli
pagu-db:
condition: service_healthy
networks:
pagu-network:
depends_on:
- pagu-db
volumes:
- ../config/config.yml:/config/config.yml
- ../config/wallets/main_wallet:/config/wallets/main_wallet
- ../config/wallets/test_wallet:/config/wallets/test_wallet
pagu-discord:
build:
context: ../.
dockerfile: deployment/discord/Dockerfile.Mainnet
hostname: pagu-discord-mainnet
container_name: pagu-discord
- pagu-network

pagu-discord-mainnet:
image: pagu-discord:stable
container_name: pagu-discord-mainnet
networks:
pagu-network:
depends_on:
- pagu-db
- pagu-phpmyadmin
volumes:
- ../config/config.mainnet.yml:/config/config.yml
- ../config/wallets/main_wallet:/config/wallets/main_wallet
pagu-discord-mod:
build:
context: ../.
dockerfile: deployment/discord/Dockerfile.Mod
hostname: pagu-discord-mod
container_name: pagu-discord-mod
- ${HOME}/pagu-discord-mainnet:/pagu

pagu-discord-staging:
image: pagu-discord:latest
container_name: pagu-discord-staging
networks:
pagu-network:
depends_on:
- pagu-db
- pagu-phpmyadmin
volumes:
- ../config/config.mod.yml:/config/config.yml
- ../config/templates:/config/templates
- ../config/wallets/main_wallet:/config/wallets/main_wallet
- ${HOME}/pagu-discord-staging:/pagu

pagu-discord-testnet:
build:
context: ../.
dockerfile: deployment/discord/Dockerfile.Testnet
hostname: pagu-discord-testnet
image: pagu-discord:latest
container_name: pagu-discord-testnet
networks:
pagu-network:
depends_on:
- pagu-db
- pagu-phpmyadmin
volumes:
- ../config/config.testnet.yml:/config/config.yml
- ../config/wallets/testnet_wallet:/config/wallets/testnet_wallet
pagu-telegram:
build:
context: ../.
dockerfile: deployment/telegram/Dockerfile.Mainnet
hostname: pagu-telegram-mainnet
container_name: pagu-telegram
- ${HOME}/pagu-discord-testnet:/pagu

pagu-discord-moderator:
image: pagu-discord:stable
container_name: pagu-discord-moderator
networks:
pagu-network:
depends_on:
- pagu-db
- pagu-phpmyadmin
volumes:
- ../config/config.mainnet.yml:/config/config.yml
- ../config/wallets/main_wallet:/config/wallets/main_wallet
pagu-node:
hostname: pagu-node
domainname: pagu-node
container_name: pagu-node
image: pactus/pactus:latest
command: pactus-daemon start -w ./../../../pactus
restart: always
ports:
- "50051:50051"
volumes:
- ./../../../pactus:/pactus
- ${HOME}/pagu-discord-moderator:/pagu

pagu-telegram-mainnet:
image: pagu-telegram:stable
container_name: pagu-telegram-mainnet
networks:
pagu-network:
depends_on:
- pagu-phpmyadmin
volumes:
- ${HOME}/pagu-telegram-mainnet:/pagu

volumes:
pagu-db-data: { }
pagu-volume:

networks:
pagu-network:
21 changes: 0 additions & 21 deletions deployment/telegram/Dockerfile.Mainnet

This file was deleted.

0 comments on commit 59652e6

Please sign in to comment.