Skip to content

Commit c8908a1

Browse files
committed
feat: add dockerhub ci
Signed-off-by: slashexx <dhruvpuri.35@gmail.com>
1 parent e92469d commit c8908a1

6 files changed

Lines changed: 601 additions & 0 deletions

File tree

.github/workflows/dockerhub-ci.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build and Push Docker Images to DockerHub
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [ published ]
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
include:
17+
- service: database
18+
dockerfile: ./docker/database/Dockerfile
19+
context: .
20+
- service: key-manager
21+
dockerfile: ./docker/key-manager/Dockerfile
22+
context: .
23+
- service: otp-server
24+
dockerfile: ./docker/otp-server/Dockerfile
25+
context: .
26+
- service: aes-server
27+
dockerfile: ./docker/aes-server/Dockerfile
28+
context: .
29+
- service: auth-service
30+
dockerfile: ./docker/auth/Dockerfile
31+
context: .
32+
- service: backend
33+
dockerfile: ./docker/backend/Dockerfile
34+
context: .
35+
- service: quantum-server
36+
dockerfile: ./quantum-secure-email-client/quant-sec-server/Dockerfile
37+
context: ./quantum-secure-email-client
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
43+
- name: Validate secrets
44+
if: github.event_name != 'pull_request'
45+
run: |
46+
if [ -z "${{ secrets.DOCKERHUB_USERNAME }}" ]; then
47+
echo "❌ DOCKERHUB_USERNAME secret is not set"
48+
exit 1
49+
fi
50+
if [ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
51+
echo "❌ DOCKERHUB_TOKEN secret is not set"
52+
exit 1
53+
fi
54+
echo "✅ DockerHub secrets are properly configured"
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- name: Log in to DockerHub
60+
if: github.event_name != 'pull_request'
61+
uses: docker/login-action@v3
62+
with:
63+
username: ${{ secrets.DOCKERHUB_USERNAME }}
64+
password: ${{ secrets.DOCKERHUB_TOKEN }}
65+
66+
- name: Build and push Docker image
67+
if: github.event_name != 'pull_request'
68+
uses: docker/build-push-action@v5
69+
with:
70+
context: ${{ matrix.context }}
71+
file: ${{ matrix.dockerfile }}
72+
push: true
73+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/quantum-secure-${{ matrix.service }}:latest,${{ secrets.DOCKERHUB_USERNAME }}/quantum-secure-${{ matrix.service }}:${{ github.sha }}
74+
cache-from: type=gha
75+
cache-to: type=gha,mode=max
76+
77+
- name: Build Docker image (PR)
78+
if: github.event_name == 'pull_request'
79+
uses: docker/build-push-action@v5
80+
with:
81+
context: ${{ matrix.context }}
82+
file: ${{ matrix.dockerfile }}
83+
push: false
84+
tags: quantum-secure-${{ matrix.service }}:pr-${{ github.event.number }}
85+
cache-from: type=gha
86+
cache-to: type=gha,mode=max
87+
88+
- name: Build Summary
89+
if: github.event_name != 'pull_request'
90+
run: |
91+
echo "🎉 Docker image ${{ matrix.service }} has been successfully built and pushed to DockerHub:"
92+
echo "- ${{ secrets.DOCKERHUB_USERNAME }}/quantum-secure-${{ matrix.service }}:latest"
93+
echo "- ${{ secrets.DOCKERHUB_USERNAME }}/quantum-secure-${{ matrix.service }}:${{ github.sha }}"
94+
95+
- name: PR Build Summary
96+
if: github.event_name == 'pull_request'
97+
run: |
98+
echo "🧪 Docker image ${{ matrix.service }} has been successfully built for PR validation:"
99+
echo "- quantum-secure-${{ matrix.service }}:pr-${{ github.event.number }}"

DOCKERHUB_SETUP.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# DockerHub CI/CD Setup
2+
3+
This repository includes automated CI/CD pipeline for building and pushing Docker images to DockerHub.
4+
5+
## Setup Instructions
6+
7+
### 1. GitHub Secrets Configuration
8+
9+
Add the following secrets to your GitHub repository:
10+
11+
1. Go to your repository settings
12+
2. Navigate to "Secrets and variables" → "Actions"
13+
3. Add the following repository secrets:
14+
15+
- `DOCKERHUB_USERNAME`: Your DockerHub username
16+
- `DOCKERHUB_TOKEN`: Your DockerHub access token
17+
18+
### 2. Creating DockerHub Access Token
19+
20+
1. Log in to [DockerHub](https://hub.docker.com/)
21+
2. Go to Account Settings → Security
22+
3. Click "New Access Token"
23+
4. Give it a name (e.g., "GitHub Actions")
24+
5. Copy the token and add it as `DOCKERHUB_TOKEN` secret
25+
26+
### 3. Docker Images
27+
28+
The CI/CD pipeline builds and pushes the following Docker images:
29+
30+
| Service | Image Name | Dockerfile Location |
31+
|---------|------------|-------------------|
32+
| Database | `quantum-secure-database` | `docker/database/Dockerfile` |
33+
| Key Manager | `quantum-secure-key-manager` | `docker/key-manager/Dockerfile` |
34+
| OTP Server | `quantum-secure-otp-server` | `docker/otp-server/Dockerfile` |
35+
| AES Server | `quantum-secure-aes-server` | `docker/aes-server/Dockerfile` |
36+
| Auth Service | `quantum-secure-auth-service` | `docker/auth/Dockerfile` |
37+
| Backend | `quantum-secure-backend` | `docker/backend/Dockerfile` |
38+
| Quantum Server | `quantum-secure-server` | `quantum-secure-email-client/quant-sec-server/Dockerfile` |
39+
40+
## Workflow Triggers
41+
42+
The CI/CD pipeline runs on:
43+
44+
- **Push to main/develop branches**: Builds and pushes images with `latest` and commit SHA tags
45+
- **Pull requests**: Builds images locally for testing (no push to DockerHub)
46+
- **Releases**: Builds and pushes images with version tags
47+
48+
## Parallel Execution
49+
50+
The workflow uses GitHub Actions matrix strategy to build all Docker images **in parallel**, significantly reducing build time:
51+
52+
- Each service builds in its own parallel job
53+
- All 7 images build simultaneously instead of sequentially
54+
- Faster CI/CD pipeline execution
55+
56+
## Using DockerHub Images
57+
58+
### Option 1: Using Docker Compose Override
59+
60+
Use the provided override file to run with DockerHub images:
61+
62+
```bash
63+
# Set your DockerHub username
64+
export DOCKERHUB_USERNAME=your-username
65+
66+
# Run with DockerHub images
67+
docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dockerhub.yml up
68+
```
69+
70+
### Option 2: Manual Docker Commands
71+
72+
```bash
73+
# Pull and run individual services
74+
docker pull your-username/quantum-secure-database:latest
75+
docker pull your-username/quantum-secure-key-manager:latest
76+
docker pull your-username/quantum-secure-otp-server:latest
77+
docker pull your-username/quantum-secure-aes-server:latest
78+
docker pull your-username/quantum-secure-auth-service:latest
79+
docker pull your-username/quantum-secure-backend:latest
80+
docker pull your-username/quantum-secure-server:latest
81+
```
82+
83+
## Image Tags
84+
85+
- `latest`: Latest build from main branch
86+
- `{commit-sha}`: Specific commit SHA
87+
- `pr-{number}`: Pull request builds (not pushed to DockerHub)
88+
- `{version}`: Release version tags
89+
90+
## Troubleshooting
91+
92+
### Common Issues
93+
94+
1. **Authentication Failed**: Ensure `DOCKERHUB_USERNAME` and `DOCKERHUB_TOKEN` secrets are correctly set
95+
2. **Build Failures**: Check Dockerfile paths and context in the workflow
96+
3. **Push Failures**: Verify DockerHub permissions and token validity
97+
98+
### Checking Workflow Status
99+
100+
1. Go to your repository on GitHub
101+
2. Click on "Actions" tab
102+
3. View the "Build and Push Docker Images to DockerHub" workflow runs
103+
104+
### Local Testing
105+
106+
You can test the Docker builds locally:
107+
108+
```bash
109+
# Test database build
110+
docker build -f docker/database/Dockerfile -t test-database .
111+
112+
# Test key manager build
113+
docker build -f docker/key-manager/Dockerfile -t test-key-manager .
114+
115+
# Test other services similarly...
116+
```
117+
118+
## Environment Variables
119+
120+
The following environment variables are used in the workflow:
121+
122+
- `DOCKERHUB_USERNAME`: Your DockerHub username (from GitHub secrets)
123+
- `DOCKERHUB_TOKEN`: Your DockerHub access token (from GitHub secrets)
124+
125+
## Security Notes
126+
127+
- Never commit DockerHub credentials to the repository
128+
- Use GitHub secrets for sensitive information
129+
- Regularly rotate DockerHub access tokens
130+
- Consider using DockerHub organization accounts for team projects

docker/PORT_ANALYSIS.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Port Analysis for Quantum Secure Email Client
2+
3+
## Server Port Status Analysis
4+
5+
### Currently Used Ports on Server:
6+
- **4666** - llvm-obfuscator-frontend
7+
- **6379** - Redis (infisical-dev-redis)
8+
- **5432** - PostgreSQL (infisical-db) ⚠️ **CONFLICT RESOLVED**
9+
- **3000** - Grafana (monitoring)
10+
- **9090** - Prometheus (monitoring)
11+
- **8081** - cAdvisor (monitoring)
12+
- **9115** - Blackbox Exporter (monitoring)
13+
- **9091** - Pushgateway (monitoring)
14+
- **9100** - Node Exporter (monitoring)
15+
- **8080** - Ghost
16+
17+
### Quantum Secure Email Client Ports:
18+
19+
| Service | Internal Port | External Port | Status |
20+
|---------|---------------|----------------|--------|
21+
| PostgreSQL | 5432 | **5433** |**CHANGED** (was 5432) |
22+
| Key Manager | 2020 | - | ✅ Available |
23+
| OTP Server | 2021 | - | ✅ Available |
24+
| AES Server | 2022 | - | ✅ Available |
25+
| Auth Service | 2023 | - | ✅ Available |
26+
| Backend API | 5001 | **5001** | ✅ Available |
27+
28+
## Changes Made:
29+
30+
### 1. PostgreSQL Port Conflict Resolution
31+
- **Problem**: Server already has PostgreSQL on port 5432
32+
- **Solution**: Changed external port mapping to 5433
33+
- **Internal**: Services still connect to PostgreSQL on port 5432 internally
34+
- **External**: Access PostgreSQL via `localhost:5433`
35+
36+
### 2. Port Mapping Summary
37+
```yaml
38+
# External access ports
39+
5433 -> PostgreSQL (was 5432)
40+
5001 -> Backend API
41+
42+
# Internal service ports (no external access needed)
43+
2020 -> Key Manager
44+
2021 -> OTP Server
45+
2022 -> AES Server
46+
2023 -> Auth Service
47+
```
48+
49+
## Deployment Commands:
50+
51+
```bash
52+
# Navigate to docker directory
53+
cd docker
54+
55+
# Start all services
56+
docker-compose up -d
57+
58+
# Check running containers
59+
docker ps
60+
61+
# View logs
62+
docker-compose logs -f
63+
64+
# Stop services
65+
docker-compose down
66+
```
67+
68+
## Service Dependencies:
69+
1. **PostgreSQL** (5433) - Database
70+
2. **Key Manager** (2020) - Key management service
71+
3. **OTP Server** (2021) - Depends on Key Manager
72+
4. **AES Server** (2022) - Depends on Key Manager
73+
5. **Auth Service** (2023) - Depends on PostgreSQL
74+
6. **Backend API** (5001) - Depends on all services
75+
76+
## Health Checks:
77+
- PostgreSQL: `pg_isready` on port 5432
78+
- Auth Service: HTTP health check on port 2023
79+
- Backend: Health check available (currently commented out)
80+
81+
## Network Configuration:
82+
- All services use `quantum_network` bridge network
83+
- Internal communication uses service names
84+
- External access only for PostgreSQL (5433) and Backend (5001)

0 commit comments

Comments
 (0)