@@ -175,3 +175,134 @@ curl http://localhost:8000/health
175175curl http://localhost:8000/kpis
176176```
177177
178+ ## Build and Push Docker Image
179+
180+ The project includes CI/CD automation to build and publish Docker images to GitLab Container Registry.
181+
182+ ### Version Management
183+
184+ The API version is managed through semantic versioning in ` src/sum_impact_assessment/__version__.py ` :
185+
186+ ``` python
187+ __version__ = " 0.0.0" # MAJOR.MINOR.PATCH
188+ ```
189+
190+ ** To release a new version:**
191+
192+ 1 . Update the version number in ` src/sum_impact_assessment/__version__.py `
193+ 2 . Commit the version change
194+ 3 . Trigger the Docker build workflow (see below)
195+
196+ Follow [ semantic versioning] ( https://semver.org/ ) guidelines:
197+ - ** MAJOR** : Breaking changes
198+ - ** MINOR** : New features, backward compatible
199+ - ** PATCH** : Bug fixes, backward compatible
200+
201+ ### Requirements Management
202+
203+ The project uses ` pipenv ` for dependency management but generates ` requirements.txt ` for Docker builds.
204+
205+ ** After installing new packages:**
206+
207+ ``` bash
208+ # Install a new package
209+ pipenv install < package-name>
210+
211+ # Regenerate requirements.txt for Docker
212+ pipenv requirements > requirements.txt
213+
214+ # Commit both Pipfile.lock and requirements.txt
215+ git add Pipfile.lock requirements.txt
216+ git commit -m " Add <package-name> dependency"
217+ ```
218+
219+ > ** Important:** Always regenerate ` requirements.txt ` after modifying dependencies to keep Docker builds in sync.
220+
221+ ### Manual Docker Build (Local)
222+
223+ Build and test the Docker image locally before pushing to registry:
224+
225+ ``` bash
226+ # Build the image
227+ docker build -t sum-impact-api:local .
228+
229+ # Run the container
230+ docker run -p 8000:8000 \
231+ -e DB_HOST=host.docker.internal \
232+ -e DB_PORT=3306 \
233+ -e DB_USER=your_user \
234+ -e DB_PASSWORD=your_password \
235+ -e DB_NAME=sum_odp \
236+ sum-impact-api:local
237+
238+ # Test the health endpoint
239+ curl http://localhost:8000/health
240+ ```
241+
242+ ### CI/CD Workflow (GitHub Actions)
243+
244+ The project uses GitHub Actions to automatically build and push Docker images to GitLab Container Registry.
245+
246+ ** Workflow file:** ` .github/workflows/docker-build.yml `
247+
248+ ** Prerequisites:**
249+
250+ Configure the following secrets and variables in your GitHub repository:
251+
252+ ** Secrets (Settings → Secrets and variables → Actions → Secrets):**
253+ - ` GITLAB_REGISTRY ` - GitLab Container Registry URL (e.g., ` registry.gitlab.com ` )
254+ - ` GITLAB_USER ` - GitLab username or deploy token username
255+ - ` GITLAB_PASSWORD ` - GitLab access token or deploy token password
256+
257+ ** Variables (Settings → Secrets and variables → Actions → Variables):**
258+ - ` GITLAB_PROJECT_PATH ` - GitLab project path (e.g., ` inria/sum-odp ` )
259+
260+ ** Trigger the workflow:**
261+
262+ 1 . Go to ** Actions** tab in GitHub repository
263+ 2 . Select ** "Build and Push Docker image to GitLab Registry"**
264+ 3 . Click ** "Run workflow"**
265+ 4 . Select branch and click ** "Run workflow"**
266+
267+ ** Workflow steps:**
268+
269+ 1 . ** Test** - Runs full test suite with pytest
270+ 2 . ** Version** - Extracts version from ` __version__.py `
271+ 3 . ** Build** - Builds multi-stage Docker image and pushes with two tags:
272+ - ` <registry>/<project>/<image>:<version> ` (e.g., ` registry.gitlab.com/inria/sum-odp/inocs-sum-odp-api:0.0.0 ` )
273+ - ` <registry>/<project>/<image>:latest `
274+
275+ ** Pull the image from GitLab:**
276+
277+ ``` bash
278+ # Login to GitLab Container Registry
279+ docker login registry.gitlab.com
280+
281+ # Pull specific version
282+ docker pull registry.gitlab.com/inria/sum-odp/inocs-sum-odp-api:0.0.0
283+
284+ # Pull latest
285+ docker pull registry.gitlab.com/inria/sum-odp/inocs-sum-odp-api:latest
286+ ```
287+
288+ ### Docker Image Details
289+
290+ ** Base image:** ` python:3.13-slim `
291+
292+ ** Features:**
293+ - Multi-stage build for optimized image size
294+ - Non-root user (` appuser ` ) for security
295+ - Health check on ` /health ` endpoint
296+ - Exposed port: ` 8000 `
297+ - Automatic dependency installation from ` requirements.txt `
298+
299+ ** Environment variables:**
300+
301+ All configuration is done via environment variables. See ` .env.example ` for available options.
302+
303+ ** Image tags:**
304+
305+ - ` <version> ` - Immutable version tag (e.g., ` 0.0.0 ` , ` 1.2.3 ` )
306+ - ` latest ` - Always points to the most recent build
307+
308+
0 commit comments