|
| 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 |
0 commit comments