Source code → GitHub → GitHub Actions → Build + Push (Docker Hub) → Pull + Deploy (Server) via Portainer
You can use the language of your choice. In this repo I choose Python + FastAPI ⚡️.
The repository is hosted on GitHub and serves as the single source of truth for our application code and configuration.
Dockerfile- Defines how to build the application imagedocker-compose.yml- Defines the Docker Swarm stack configuration.github/workflows/deploy.yml- GitHub Actions workflow for CI/CD
Automated workflow that triggers on every push to the main branch.
- Checkout code - Pulls the latest code from the repository
- Set up Docker Buildx - Prepares Docker build environment
- Login to Docker Hub - Authenticates using secrets (
DOCKER_USERNAME,DOCKER_TOKEN) - Build and push image - Builds the Docker image and pushes to Docker Hub as
sammexkita/fastapi:latest - Deploy via Portainer API - Triggers deployment through Portainer's REST API
DOCKER_USERNAME- Docker Hub usernameDOCKER_TOKEN- Docker Hub access tokenPORTAINER_URL- Portainer URLPORTAINER_TOKEN- Portainer API tokenPORTAINER_CLUSTER_ID- Docker Swarm cluster ID
Acts as our container registry, storing versioned images of our application. This allows:
- Separation of build and deployment environments
- Easy rollback to previous versions
- Multiple servers to pull the same image
- Build process happens on GitHub's infrastructure, not on production server
Running Docker Swarm mode with Portainer for container management.
- Docker Swarm - Container orchestration platform
- Portainer - Web UI for Docker management
- Traefik - Reverse proxy handling SSL certificates and routing
- GitHub Actions calls Portainer API with the updated
docker-compose.yml - Portainer creates/updates the stack in Docker Swarm
- Docker Swarm pulls the new image from Docker Hub
- Rolling update replaces old containers with new ones (zero downtime)
- Traefik routes traffic to
fastapi.mydomain
✅ Automated Deployment - Push to main = automatic deploy
✅ No SSH Required - Uses Portainer API (more secure with firewall)
✅ Zero Downtime - Rolling updates via Docker Swarm
✅ Easy Rollback - All images versioned in Docker Hub
✅ Scalable - Add more replicas or servers easily
✅ Manageable - Full control via Portainer UI
Simply push your changes to the main branch:
git add .
git commit -m "Your changes"
git push origin mainGitHub Actions will automatically build, push, and deploy your application!