Skip to content

Commit 3046c88

Browse files
committed
Added AI instructions.
1 parent ba5d7d7 commit 3046c88

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This project provides a MariaDB Docker image for Drupal that captures database data as Docker layers. Unlike traditional MariaDB containers that use volumes, this image stores database files in a non-volume location (`/home/db-data`) allowing the entire database to be captured, stored, and distributed as a Docker image.
8+
9+
**Key Innovation**: Database files are stored as Docker layers rather than volumes, enabling instant database availability without time-consuming imports.
10+
11+
## Architecture
12+
13+
### Core Components
14+
15+
1. **Dockerfile** - Extends `uselagoon/mariadb-10.11-drupal` base image:
16+
- Sets custom data directory via `MARIADB_DATA_DIR=/home/db-data` (not a volume)
17+
- Replaces entrypoint script to support custom data directory
18+
- Overrides CMD to use `--datadir=/home/db-data`
19+
20+
2. **entrypoint.bash** - Modified from [upstream](https://github.com/uselagoon/lagoon-images/blob/main/images/mariadb/entrypoints/9999-mariadb-init.bash):
21+
- Supports `MARIADB_DATA_DIR` environment variable
22+
- Handles database initialization in custom location
23+
- Supports `MARIADB_COPY_DATA_DIR_SOURCE` for pre-filling data
24+
- Includes `FORCE_MYSQL_UPGRADE` flag for forcing upgrades
25+
26+
3. **seed.sh** - Three-phase database seeding script:
27+
- **Phase 1**: Import SQL dump into temporary container and extract database files
28+
- **Phase 2**: Build new image with extracted database files using `docker buildx`
29+
- **Phase 3**: Verify database exists in the new image
30+
- Supports multi-platform builds (linux/amd64, linux/arm64)
31+
- Uses `docker buildx` to push directly to registry during build
32+
33+
### Important Patterns
34+
35+
- Database files must be in `/home/db-data` (not `/var/lib/mysql`)
36+
- Upstream base image version follows [uselagoon/mariadb-drupal tags](https://hub.docker.com/r/uselagoon/mariadb-drupal/tags)
37+
- The entrypoint script is minimally modified for easy upstream updates
38+
- Containers typically run as user `1000` (not `mysql`) in production
39+
40+
## Development Commands
41+
42+
### Testing
43+
44+
Run all BATS tests:
45+
```bash
46+
npm --prefix tests/bats ci
47+
tests/bats/node_modules/.bin/bats tests/bats
48+
```
49+
50+
Run specific BATS test file:
51+
```bash
52+
tests/bats/node_modules/.bin/bats tests/bats/image.bats --tap
53+
tests/bats/node_modules/.bin/bats tests/bats/seed.bats --tap
54+
```
55+
56+
Run Goss tests (structural tests):
57+
```bash
58+
docker build -t testorg/testimage:test-tag .
59+
GOSS_FILES_PATH=tests/dgoss dgoss run -i testorg/testimage:test-tag
60+
```
61+
62+
### Linting
63+
64+
Lint shell scripts:
65+
```bash
66+
shfmt -i 2 -ci -s -d seed.sh tests/bats/*.bash tests/bats/*.bats
67+
shellcheck seed.sh tests/bats/*.bash tests/bats/*.bats
68+
```
69+
70+
### Building and Seeding
71+
72+
Build image locally:
73+
```bash
74+
docker build -t drevops/mariadb-drupal-data:local .
75+
```
76+
77+
Seed image with database (single platform):
78+
```bash
79+
./seed.sh path/to/db.sql myorg/myimage:latest
80+
```
81+
82+
Seed image with database (multi-platform):
83+
```bash
84+
DESTINATION_PLATFORMS=linux/amd64,linux/arm64 ./seed.sh path/to/db.sql myorg/myimage:latest
85+
```
86+
87+
Use custom base image:
88+
```bash
89+
BASE_IMAGE=drevops/mariadb-drupal-data:canary ./seed.sh path/to/db.sql myorg/myimage:latest
90+
```
91+
92+
### Platform-specific Testing
93+
94+
Test for ARM64:
95+
```bash
96+
BUILDX_PLATFORMS=linux/arm64 DOCKER_DEFAULT_PLATFORM=linux/arm64 tests/bats/node_modules/.bin/bats tests/bats/image.bats
97+
```
98+
99+
## CI/CD
100+
101+
- Uses CircleCI with `drevops/ci-runner:25.9.0` image
102+
- Publishes to DockerHub:
103+
- `main` branch → `canary` tag
104+
- Git tags → versioned tag + `latest`
105+
- Feature branches → `feature-branch-name` tag (but renovate branches are skipped)
106+
- Multi-platform builds: `linux/amd64,linux/arm64`
107+
- Code coverage uploaded to Codecov via kcov
108+
109+
## Important Notes
110+
111+
- Always test changes by committing first (BATS tests copy code from last commit)
112+
- The entrypoint script should remain minimally modified for easy upstream syncing
113+
- When updating base image version, follow upstream versioning
114+
- seed.sh requires being logged into Docker registry (it pushes during buildx)
115+
- Tests always run for linux/amd64 unless explicitly configured otherwise

0 commit comments

Comments
 (0)