Skip to content

Commit cfa21a0

Browse files
authored
Add build script and enhance Dockerfile with metadata labels for comm… (#41)
* Add build script and enhance Dockerfile with metadata labels for commit hash and build date - Introduced a new `build.sh` script to automate Docker image builds, including git commit hash and build date as arguments. - Updated `Dockerfile` to accept build arguments for git commit hash and build date, adding corresponding metadata labels. - Enhanced `README.md` with instructions for using the new build script and building with arguments. - Modified GitHub Actions workflow to set the build date and pass it along with the commit hash during Docker image builds. * Enhance build script and update README.md for Docker inspection commands - Added 'set -euo pipefail' to the build.sh script for improved error handling. - Updated Docker inspection commands in README.md to use the '--format' option for better output formatting and clarity.
1 parent 1a73a1f commit cfa21a0

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

.github/workflows/docker.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ jobs:
4343
type=semver,pattern={{major}}.{{minor}}
4444
type=raw,value=latest
4545
46+
- name: Set build timestamp
47+
id: timestamp
48+
run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
49+
4650
- name: Build and push Docker image
4751
uses: docker/build-push-action@v6
4852
with:
@@ -51,6 +55,9 @@ jobs:
5155
push: ${{ github.event_name != 'pull_request' }}
5256
tags: ${{ steps.meta.outputs.tags }}
5357
labels: ${{ steps.meta.outputs.labels }}
58+
build-args: |
59+
GIT_COMMIT_HASH=${{ github.sha }}
60+
BUILD_DATE=${{ steps.timestamp.outputs.BUILD_DATE }}
5461
cache-from: type=gha
5562
cache-to: type=gha,mode=max
5663

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ RUN uv venv /opt/venv && \
1818
# Runtime stage - use Python image with same version as builder
1919
FROM python:3.10-slim-bookworm AS runtime
2020

21+
# Accept build arguments for labels
22+
ARG GIT_COMMIT_HASH="unknown"
23+
ARG BUILD_DATE="unknown"
24+
25+
# Add metadata labels
26+
LABEL org.opencontainers.image.revision="${GIT_COMMIT_HASH}" \
27+
org.opencontainers.image.created="${BUILD_DATE}" \
28+
org.opencontainers.image.title="MCP Server Couchbase" \
29+
org.opencontainers.image.description="Model Context Protocol server for Couchbase" \
30+
org.opencontainers.image.source="https://github.com/couchbaselabs/mcp-server-couchbase"
31+
2132
# Create non-root user
2233
RUN useradd --system --uid 1001 mcpuser
2334

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,41 @@ Alternatively, we are part of the [Docker MCP Catalog](https://hub.docker.com/mc
261261
docker build -t mcp/couchbase .
262262
```
263263

264+
<details>
265+
<summary>Building with Arguments</summary>
266+
If you want to build with the build arguments for commit hash and the build time, you can build using:
267+
268+
```bash
269+
docker build --build-arg GIT_COMMIT_HASH=$(git rev-parse HEAD) \
270+
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
271+
-t mcp/couchbase .
272+
```
273+
274+
**Alternatively, use the provided build script:**
275+
276+
```bash
277+
./build.sh
278+
```
279+
280+
This script automatically:
281+
282+
- Generates git commit hash and build timestamp
283+
- Creates multiple useful tags (`latest`, `<short-commit>`)
284+
- Shows build information and results
285+
- Uses the same arguments as CI/CD builds
286+
287+
**Verify image labels:**
288+
289+
```bash
290+
# View git commit hash in image
291+
docker inspect --format='{{index .Config.Labels "org.opencontainers.image.revision"}}' mcp/couchbase:latest
292+
293+
# View all metadata labels
294+
docker inspect --format='{{json .Config.Labels}}' mcp/couchbase:latest
295+
```
296+
297+
</details>
298+
264299
### Running
265300

266301
The MCP server can be run with the environment variables being used to configure the Couchbase settings. The environment variables are the same as described in the [Configuration section](#server-configuration-for-mcp-clients).

build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Get git information
5+
GIT_COMMIT=$(git rev-parse HEAD)
6+
GIT_SHORT_COMMIT=$(git rev-parse --short HEAD)
7+
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
8+
9+
echo "Building Docker image with:"
10+
echo " Git Commit: $GIT_COMMIT"
11+
echo " Build Date: $BUILD_DATE"
12+
13+
# Build the Docker image
14+
docker build \
15+
--build-arg GIT_COMMIT_HASH="$GIT_COMMIT" \
16+
--build-arg BUILD_DATE="$BUILD_DATE" \
17+
-t "mcp/couchbase:$GIT_SHORT_COMMIT" \
18+
-t "mcp/couchbase:latest" \
19+
.
20+
21+
echo "Build complete!"
22+
echo "Tagged as:"
23+
echo " - mcp/couchbase:$GIT_SHORT_COMMIT"
24+
echo " - mcp/couchbase:latest"

0 commit comments

Comments
 (0)