Skip to content

Commit

Permalink
ci: separate deployment process for stable and latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Jan 6, 2025
1 parent 13eb309 commit 736e6df
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 79 deletions.
38 changes: 35 additions & 3 deletions deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,47 @@

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

### First-Time Setup

#### Database User Setup

To grant the correct privileges to a single database user, execute the following SQL commands.
Make sure to replace `<MYSQL_USER>` and `<MYSQL_PASSWORD>` with the appropriate values for your setup.

```sql
CREATE DATABASE IF NOT EXISTS pagu;
CREATE DATABASE IF NOT EXISTS pagu_staging;

-- Ensure the user exists
CREATE USER IF NOT EXISTS '<MYSQL_USER>'@'%' IDENTIFIED BY '<MYSQL_PASSWORD>';

-- Grant privileges to the user on both databases
GRANT ALL PRIVILEGES ON pagu.* TO '<MYSQL_USER>'@'%';
GRANT ALL PRIVILEGES ON pagu_staging.* TO '<MYSQL_USER>'@'%';

-- Apply the changes
FLUSH PRIVILEGES;
```

#### Docker Network Setup

To enable Docker containers to communicate with each other on the same network, you need to create an external network and share it between the containers.
Use the following command to create the network:

```bash
docker network create pagu_network
```

### Deployment Overview

The deployment system operates as follows:

- **Stable Version**: Triggered when a new stable version is released.
- **Latest Version**: Triggered when changes are pushed to the `main` branch.
- **Stable Version**: Triggered when a new stable version is released.

### Releasing a Stable Version

To release and deploy a stable version, create a Git tag and push it to the repository. Follow these steps:
To release and deploy a *Stable* version, create a Git tag and push it to the repository. Follow these steps:

1. Ensure that the `origin` remote points to the current repository, not your fork.
2. Verify that Pagu's [version](../version.go) is updated and matches the release version.
Expand All @@ -29,5 +60,6 @@ After creating the tag, the stable version will be released, and the deployment

### Updating the Working Version

Once a stable version is released, immediately update the [version.go](../version.go) file and open a Pull Request.
Once a stable version is released, immediately update the [version.go](../version.go) file and open a Pull Request.
For reference, you can check this [Pull Request](https://github.com/pagu-project/pagu/pull/215).

18 changes: 10 additions & 8 deletions deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

set -e

DOCKER_TAG="latest"
# Ensure Database is up and running
docker compose -f ./deployment/docker-compose.db.yml up -d


export DEPLOY_TAG="latest"

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

if [[ -n "$TAG" ]]; then
DOCKER_TAG="stable"
export DEPLOY_TAG="stable"
fi

echo "Building ${DOCKER_TAG} version"

docker build -t pagu:${DOCKER_TAG} -f ./deployment/Dockerfile .
echo "Building ${DEPLOY_TAG} version..."
docker build -t pagu:${DEPLOY_TAG} -f ./deployment/Dockerfile .

docker compose -f ./deployment/docker-compose.yml down
docker compose -f ./deployment/docker-compose.yml up -d
docker compose -p pagu_${DEPLOY_TAG} -f ./deployment/docker-compose.yml up -d

## Some cleanup
echo "Cleanup"
echo "Cleanup..."

docker builder prune -f
docker image prune -f
30 changes: 30 additions & 0 deletions deployment/docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
pagu_mysql:
image: mysql:8.0.40-debian
hostname: pagu_mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
container_name: pagu_mysql
volumes:
- ${HOME}/mysql_data:/var/lib/mysql
networks:
- pagu_network

pagu_phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: pagu_mysql
container_name: pagu_phpmyadmin
ports:
- "${PHPMYADMIN_PORT}:80"
networks:
- pagu_network

volumes:
pagu-volume:

networks:
pagu_network:
external: true
86 changes: 18 additions & 68 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,41 @@
services:
pagu_mysql:
image: mysql:8.0.40-debian
hostname: pagu_mysql
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
container_name: pagu_mysql
volumes:
- ${HOME}/mysql_data:/var/lib/mysql
networks:
- pagu_network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", pagu_mysql]
timeout: 5s
retries: 10

pagu_phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: pagu_mysql
container_name: pagu_phpmyadmin
ports:
- "${PHPMYADMIN_PORT}:80"
depends_on:
pagu_mysql:
condition: service_healthy
networks:
- pagu_network

pagu_discord_mainnet:
image: pagu:stable
container_name: pagu_discord_mainnet
command: "./pagu-discord -c /pagu/config_discord_mainnet.yml run"
networks:
pagu_network:
depends_on:
- pagu_phpmyadmin
volumes:
- ${HOME}/pagu:/pagu
extra_hosts:
- "host.docker.internal:host-gateway"

pagu_discord_staging:
image: pagu:latest
container_name: pagu_discord_staging
command: "./pagu-discord -c /pagu/config_discord_staging.yml run"
image: pagu:${DEPLOY_TAG}
container_name: pagu_discord_mainnet_${DEPLOY_TAG}
command: "./pagu-discord -c /pagu/config_discord_mainnet.${DEPLOY_TAG}.yml run"
networks:
pagu_network:
depends_on:
- pagu_phpmyadmin
- pagu_network
volumes:
- ${HOME}/pagu:/pagu
extra_hosts:
- "host.docker.internal:host-gateway"

pagu_discord_moderator:
image: pagu:latest
container_name: pagu_discord_moderator
command: "./pagu-discord -c /pagu/config_discord_moderator.yml run"
image: pagu:${DEPLOY_TAG}
container_name: pagu_discord_moderator_${DEPLOY_TAG}
command: "./pagu-discord -c /pagu/config_discord_moderator.${DEPLOY_TAG}.yml run"
networks:
pagu_network:
depends_on:
- pagu_phpmyadmin
- pagu_network
volumes:
- ${HOME}/pagu:/pagu
extra_hosts:
- "host.docker.internal:host-gateway"

pagu_discord_testnet:
image: pagu:stable
container_name: pagu_discord_testnet
command: "./pagu-discord -c /pagu/config_discord_testnet.yml run"
image: pagu:${DEPLOY_TAG}
container_name: pagu_discord_testnet_${DEPLOY_TAG}
command: "./pagu-discord -c /pagu/config_discord_testnet.${DEPLOY_TAG}.yml run"
networks:
pagu_network:
depends_on:
- pagu_phpmyadmin
- pagu_network
volumes:
- ${HOME}/pagu:/pagu

pagu_telegram_mainnet:
image: pagu:stable
container_name: pagu_telegram_mainnet
command: "./pagu-telegram -c /pagu/config_telegram_mainnet.yml run"
image: pagu:${DEPLOY_TAG}
container_name: pagu_telegram_mainnet_${DEPLOY_TAG}
command: "./pagu-telegram -c /pagu/config_telegram_mainnet.${DEPLOY_TAG}.yml run"
networks:
pagu_network:
depends_on:
- pagu_phpmyadmin
- pagu_network
volumes:
- ${HOME}/pagu:/pagu
extra_hosts:
Expand All @@ -98,3 +46,5 @@ volumes:

networks:
pagu_network:
external: true

0 comments on commit 736e6df

Please sign in to comment.