Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README | LICENSE

README.md (2202B)


      1 # 02 — Docker Compose API Tests
      2 
      3 This Jaypore CI example shows how to bring up a multi-service stack with
      4 **Docker Compose** and run API tests against it.
      5 
      6 ## What’s in the stack
      7 
      8 | Service    | Image                | Purpose                       |
      9 |------------|----------------------|-------------------------------|
     10 | `postgres` | `postgres:16-alpine` | Primary database              |
     11 | `redis`    | `redis:7-alpine`     | Cache / message broker        |
     12 | `web`      | Built from repo      | Django app serving the API    |
     13 
     14 All three services have Docker health checks so the CI script can wait
     15 until everything is ready before running tests.
     16 
     17 ## Files
     18 
     19 ```
     20 02-docker-compose-api-tests/
     21 ├── .jci/
     22 │   └── run.sh            # Jaypore CI entry point
     23 ├── docker-compose.yml    # Service definitions
     24 ├── Dockerfile            # Django app image
     25 ├── test_api.sh           # Curl-based API test suite
     26 └── README.md             # This file
     27 ```
     28 
     29 ## How it works
     30 
     31 1. **`.jci/run.sh`** is executed by Jaypore CI.  
     32    It receives `JCI_COMMIT`, `JCI_REPO_ROOT`, and `JCI_OUTPUT_DIR` as
     33    environment variables.
     34 
     35 2. The script runs `docker compose up -d --build` to start postgres,
     36    redis, and the Django web service.
     37 
     38 3. It polls the Docker health checks until all three services report
     39    healthy (up to 120 s).
     40 
     41 4. **`test_api.sh`** fires `curl` requests at the Django app:
     42    - `GET /health/` — expects `{"status": "ok"}`
     43    - `GET /items/` — expects a JSON list of items
     44    - `GET /nonexistent/` — expects a 404
     45 
     46 5. Results are saved into `$JCI_OUTPUT_DIR` so they become CI artifacts:
     47    - `api-test-results.txt` — pass/fail summary
     48    - `test-output.log` — full test console output
     49    - `compose-logs.log` — container logs for debugging
     50    - `compose-up.log` — docker compose build/start output
     51 
     52 6. `docker compose down` tears everything down (via a `trap` so it runs
     53    even on failure).
     54 
     55 ## Running locally
     56 
     57 ```bash
     58 export JCI_COMMIT=$(git rev-parse HEAD)
     59 export JCI_REPO_ROOT=$(git rev-parse --show-toplevel)
     60 export JCI_OUTPUT_DIR=$(mktemp -d)
     61 
     62 bash 02-docker-compose-api-tests/.jci/run.sh
     63 
     64 ls "$JCI_OUTPUT_DIR"   # see the artifacts
     65 ```