Skip to content

Commit 4e11b81

Browse files
authored
Pass ldflags to the Dockerfile (#681)
<!-- Provide a brief summary of your changes --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> The following fixes an issue where the ldflags were not passed to the Dockerfile, so the binary cannot populate its version-related variables accordingly ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> ## Breaking Changes <!-- Will users need to update their code or configurations? --> ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [ ] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 893e31b commit 4e11b81

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

.github/workflows/deploy-staging.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jobs:
3434
username: ${{ github.actor }}
3535
password: ${{ secrets.GITHUB_TOKEN }}
3636

37+
- name: Get build timestamp
38+
id: build-time
39+
run: echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
40+
3741
- name: Extract metadata
3842
id: meta
3943
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f
@@ -54,6 +58,10 @@ jobs:
5458
labels: ${{ steps.meta.outputs.labels }}
5559
cache-from: type=gha
5660
cache-to: type=gha,mode=max
61+
build-args: |
62+
VERSION=${{ steps.meta.outputs.version }}
63+
GIT_COMMIT=${{ github.sha }}
64+
BUILD_TIME=${{ steps.build-time.outputs.timestamp }}
5765
5866
deploy-staging:
5967
name: Deploy to Staging

.github/workflows/release.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ jobs:
5656
username: ${{ github.actor }}
5757
password: ${{ secrets.GITHUB_TOKEN }}
5858

59+
- name: Get build timestamp
60+
id: build-time
61+
run: echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
62+
5963
- name: Extract metadata
6064
id: meta
6165
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f
@@ -75,4 +79,8 @@ jobs:
7579
tags: ${{ steps.meta.outputs.tags }}
7680
labels: ${{ steps.meta.outputs.labels }}
7781
cache-from: type=gha
78-
cache-to: type=gha,mode=max
82+
cache-to: type=gha,mode=max
83+
build-args: |
84+
VERSION=${{ steps.meta.outputs.version }}
85+
GIT_COMMIT=${{ github.sha }}
86+
BUILD_TIME=${{ steps.build-time.outputs.timestamp }}

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ RUN go mod download
1010
COPY . .
1111

1212
ARG GO_BUILD_TAGS
13-
RUN go build ${GO_BUILD_TAGS:+-tags="$GO_BUILD_TAGS"} -o /build/registry ./cmd/registry
13+
ARG VERSION=dev
14+
ARG GIT_COMMIT=unknown
15+
ARG BUILD_TIME=unknown
16+
17+
RUN go build \
18+
${GO_BUILD_TAGS:+-tags="$GO_BUILD_TAGS"} \
19+
-ldflags="-X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.BuildTime=${BUILD_TIME}" \
20+
-o /build/registry ./cmd/registry
1421

1522
FROM alpine:latest
1623
WORKDIR /app

0 commit comments

Comments
 (0)