This GitHub Actions workflow is designed to automatically deploy a Discord bot whenever changes are pushed to the main branch or manually triggered. It utilizes Docker and SSH to build and run the bot in a remote server environment.
-
Build & Push (push job): This step builds the Docker image for the Discord bot and pushes it to the target server.
- It connects to the remote server using SSH.
- It navigates to the project directory on the server and pulls the latest changes from the Git repository.
- It builds the Docker image using
docker compose build.
-
Run (run job): This step starts the deployed Discord bot.
- It connects to the remote server using SSH.
- It navigates to the project directory on the server.
- It starts the Docker containers using
docker compose up -d, running the bot in detached mode.
The workflow uses the following environment variables:
REPO_NAME: The name of the GitHub repository.REPO_OWNER: The owner of the GitHub repository.USER: The username on the remote server.
To set up and use this workflow, you need to ensure the following:
- You have a remote server accessible via SSH, where the Discord bot will be deployed.
- Docker and Docker Compose are installed on the remote server.
- SSH private key and passphrase are set up as GitHub secrets. The private key should have access to the remote server.
- In the repository settings, add the following secrets:
SSH_HOST: The hostname or IP address of the remote server.SSH_PRIVATE_KEY: The SSH private key with access to the remote server.SSH_PASSPHRASE: The passphrase for the SSH private key.
- The
.github/workflows/deploy.ymlfile with the workflow definition is present in the repository.
Whenever changes are pushed to the main branch or the workflow is manually triggered, the following deployment process will occur:
- The workflow connects to the remote server via SSH.
- It navigates to the project directory on the server and pulls the latest changes from the Git repository.
- The Docker image for the Discord bot is built using
docker compose build. - The deployed bot is started using
docker compose up -d, running in detached mode.
This workflow simplifies the deployment process of your Discord bot, ensuring that it is always up to date on your remote server.