|
| 1 | +# Docker & Environment Setup |
| 2 | + |
| 3 | +This directory contains Docker configuration files for developing and testing the **iLoveIMG Python** library in an isolated, reproducible environment. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/) installed on your system. |
| 10 | +- Environment variables configured as described below. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Environment Variables |
| 15 | + |
| 16 | +Before running Docker containers, you must set up the required environment variables: |
| 17 | + |
| 18 | +1. Copy the sample environment file: |
| 19 | + |
| 20 | + ```bash |
| 21 | + cp .docker/.env.sample .docker/.env |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Edit `.docker/.env` and set the following variables: |
| 25 | + |
| 26 | + - `ILOVEIMG_PUBLIC_KEY` – Your iLoveIMG project public key |
| 27 | + - `ILOVEIMG_SECRET_KEY` – Your iLoveIMG project secret key |
| 28 | + - `FOLDER_SAMPLE_PATH` – Path to sample files (default: `tests/integration/files_samples`) |
| 29 | + |
| 30 | +**Note:** |
| 31 | +The `.env` file is used by both local development and Docker containers. Never commit your real credentials. |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Quick Start |
| 36 | + |
| 37 | +### 1. Build Docker Images |
| 38 | + |
| 39 | +To build all Python version images (3.9–3.12): |
| 40 | + |
| 41 | +```bash |
| 42 | +docker-compose -f .docker/docker-compose.yml build |
| 43 | +``` |
| 44 | + |
| 45 | +To build a specific Python version (e.g., Python 3.12): |
| 46 | + |
| 47 | +```bash |
| 48 | +docker-compose -f .docker/docker-compose.yml build python312 |
| 49 | +``` |
| 50 | + |
| 51 | +To force a rebuild (ignore cache): |
| 52 | + |
| 53 | +```bash |
| 54 | +docker-compose -f .docker/docker-compose.yml build --no-cache |
| 55 | +``` |
| 56 | + |
| 57 | +### 2. Run Tests |
| 58 | + |
| 59 | +To run all tests (unit and integration) in a specific Python version: |
| 60 | + |
| 61 | +```bash |
| 62 | +docker-compose -f .docker/docker-compose.yml run python39 |
| 63 | +``` |
| 64 | + |
| 65 | +For Python 3.10: |
| 66 | + |
| 67 | +```bash |
| 68 | +docker-compose -f .docker/docker-compose.yml run python310 |
| 69 | +``` |
| 70 | + |
| 71 | +Available services: `python39`, `python310`, `python311`, `python312` |
| 72 | + |
| 73 | +#### Run Only Unit or Integration Tests |
| 74 | + |
| 75 | +```bash |
| 76 | +docker-compose -f .docker/docker-compose.yml run python39 pytest tests/unit |
| 77 | +docker-compose -f .docker/docker-compose.yml run python39 pytest tests/integration |
| 78 | +``` |
| 79 | + |
| 80 | +#### Run a Specific Test File |
| 81 | + |
| 82 | +```bash |
| 83 | +docker-compose -f .docker/docker-compose.yml run python39 pytest tests/unit/test_compress_task.py |
| 84 | +``` |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Development Workflow |
| 89 | + |
| 90 | +- The project directory is mounted into the container as a volume. |
| 91 | +- **Live code editing:** Changes to Python files are immediately reflected in the container. |
| 92 | +- **No rebuilds needed:** Modify code and run tests without rebuilding the image. |
| 93 | +- **Efficient iteration:** Quickly test changes across multiple Python versions. |
| 94 | + |
| 95 | +Example workflow: |
| 96 | + |
| 97 | +```bash |
| 98 | +# Terminal 1: Run tests in Python 3.9 |
| 99 | +docker-compose -f .docker/docker-compose.yml run python39 |
| 100 | + |
| 101 | +# Terminal 2: Edit code in your IDE |
| 102 | +# Changes are instantly available in the running container |
| 103 | +``` |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Using Direct Docker Commands |
| 108 | + |
| 109 | +If you prefer to use Docker directly instead of Docker Compose: |
| 110 | + |
| 111 | +```bash |
| 112 | +# Build |
| 113 | +docker build -t iloveimg-python39 -f .docker/Dockerfile . |
| 114 | + |
| 115 | +# Run with environment file |
| 116 | +docker run --env-file .docker/.env iloveimg-python39 |
| 117 | +``` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Troubleshooting |
| 122 | + |
| 123 | +### Container exits after running tests |
| 124 | + |
| 125 | +This is expected. The container runs tests and exits when complete. |
| 126 | +To keep it running for debugging: |
| 127 | + |
| 128 | +```bash |
| 129 | +docker-compose -f .docker/docker-compose.yml run python39 bash |
| 130 | +``` |
| 131 | + |
| 132 | +### Changes not reflected in container |
| 133 | + |
| 134 | +- Ensure files are saved in your editor. |
| 135 | +- Re-run tests (container picks up changes from mounted volume). |
| 136 | + |
| 137 | +### Clear cache and rebuild |
| 138 | + |
| 139 | +```bash |
| 140 | +docker-compose -f .docker/docker-compose.yml down |
| 141 | +docker-compose -f .docker/docker-compose.yml build --no-cache |
| 142 | +``` |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Reference |
| 147 | + |
| 148 | +- Main project documentation: [../README.md](../README.md) |
| 149 | +- Environment variable sample: [.env.sample](.env.sample) |
| 150 | +- Official iLoveIMG API docs: [https://developer.iloveimg.com/docs](https://developer.iloveimg.com/docs) |
0 commit comments