Skip to content

Commit ac725cc

Browse files
committed
add label
1 parent 4ded6a8 commit ac725cc

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
lines changed

ptp-tools/Dockerfile.cep

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@ ENV GOPATH=/go
77
ENV GOMAXPROCS=16
88

99
WORKDIR /go/src/github.com/redhat-cne/cloud-event-proxy
10-
RUN git clone -b main https://github.com/redhat-cne/cloud-event-proxy.git /go/src/github.com/redhat-cne/cloud-event-proxy
10+
RUN git clone -b main https://github.com/redhat-cne/cloud-event-proxy.git /go/src/github.com/redhat-cne/cloud-event-proxy && \
11+
cd /go/src/github.com/redhat-cne/cloud-event-proxy && \
12+
git rev-parse HEAD > /tmp/COMMIT_HASH
1113

1214
RUN hack/build-go.sh
1315

1416
FROM quay.io/centos/centos:stream9
17+
18+
ARG COMMIT_HASH
19+
1520
COPY --from=builder /go/src/github.com/redhat-cne/cloud-event-proxy/build/cloud-event-proxy /
1621
COPY --from=builder /go/src/github.com/redhat-cne/cloud-event-proxy/plugins/*.so /plugins/
22+
COPY --from=builder /tmp/COMMIT_HASH /tmp/COMMIT_HASH
23+
24+
# If COMMIT_HASH not provided as build-arg, read it from the file
25+
RUN if [ -z "$COMMIT_HASH" ]; then COMMIT_HASH=$(cat /tmp/COMMIT_HASH); fi && \
26+
echo "Commit: $COMMIT_HASH"
27+
1728
LABEL io.k8s.display-name="Cloud Event Proxy" \
1829
io.k8s.description="This is a component of OpenShift Container Platform and provides a side car to handle cloud events." \
1930
io.openshift.tags="openshift" \
31+
io.openshift.build.commit.url="https://github.com/redhat-cne/cloud-event-proxy/commit/${COMMIT_HASH:-unknown}" \
2032
maintainer="PTP Team <ptp-dev@redhat.com>"
2133

2234
ENTRYPOINT ["./cloud-event-proxy"]

ptp-tools/Dockerfile.krp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM docker.io/golang:1.24.3 AS builder
22
WORKDIR /go/src/github.com/brancz/kube-rbac-proxy
3-
RUN git clone https://github.com/openshift/kube-rbac-proxy.git /go/src/github.com/brancz/kube-rbac-proxy
3+
RUN git clone https://github.com/openshift/kube-rbac-proxy.git /go/src/github.com/brancz/kube-rbac-proxy && \
4+
cd /go/src/github.com/brancz/kube-rbac-proxy && \
5+
git rev-parse HEAD > /tmp/COMMIT_HASH
46
ENV GO111MODULE=on
57
ENV GOMAXPROCS=16
68

@@ -10,15 +12,24 @@ RUN GITHUB_URL=github.com/openshift/kube-rbac-proxy VERSION=$(cat VERSION) make
1012
cp _output/kube-rbac-proxy-$(go env GOOS)-$(go env GOARCH) _output/kube-rbac-proxy
1113

1214
FROM quay.io/centos/centos:stream9
15+
16+
ARG COMMIT_HASH
17+
ARG FROM_DIRECTORY=/go/src/github.com/brancz/kube-rbac-proxy
18+
19+
COPY --from=builder ${FROM_DIRECTORY}/_output/kube-rbac-proxy /usr/bin/kube-rbac-proxy
20+
COPY --from=builder /tmp/COMMIT_HASH /tmp/COMMIT_HASH
21+
22+
# If COMMIT_HASH not provided as build-arg, read it from the file
23+
RUN if [ -z "$COMMIT_HASH" ]; then COMMIT_HASH=$(cat /tmp/COMMIT_HASH); fi && \
24+
echo "Commit: $COMMIT_HASH"
25+
1326
LABEL io.k8s.display-name="kube-rbac-proxy" \
1427
io.k8s.description="This is a proxy, that can perform Kubernetes RBAC authorization." \
1528
io.openshift.tags="openshift,kubernetes" \
29+
io.openshift.build.commit.url="https://github.com/openshift/kube-rbac-proxy/commit/${COMMIT_HASH:-unknown}" \
1630
summary="" \
1731
maintainer="OpenShift Monitoring Team <team-monitoring@redhat.com>"
1832

19-
ARG FROM_DIRECTORY=/go/src/github.com/brancz/kube-rbac-proxy
20-
COPY --from=builder ${FROM_DIRECTORY}/_output/kube-rbac-proxy /usr/bin/kube-rbac-proxy
21-
2233
USER 65534
2334
EXPOSE 8080
2435
ENTRYPOINT ["/usr/bin/kube-rbac-proxy"]

ptp-tools/Dockerfile.lptpd

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@ FROM docker.io/golang:1.24.3 AS builder
22
WORKDIR /go/src/github.com/k8snetworkplumbingwg/linuxptp-daemon
33
ENV GOMAXPROCS=16
44

5-
RUN git clone -b main https://github.com/k8snetworkplumbingwg/linuxptp-daemon.git /go/src/github.com/k8snetworkplumbingwg/linuxptp-daemon
5+
RUN git clone -b main https://github.com/k8snetworkplumbingwg/linuxptp-daemon.git /go/src/github.com/k8snetworkplumbingwg/linuxptp-daemon && \
6+
cd /go/src/github.com/k8snetworkplumbingwg/linuxptp-daemon && \
7+
git rev-parse HEAD > /tmp/COMMIT_HASH
68

79
RUN make clean && make -j 16
810

911
FROM quay.io/centos/centos:stream9
12+
13+
ARG COMMIT_HASH
1014
RUN yum install -y gpsd-minimal glibc gpsd-minimal-clients linuxptp ethtool hwdata synce4l && yum clean all
1115

1216
# Create symlinks for executables to match references
1317
RUN ln -s /usr/bin/gpspipe /usr/local/bin/gpspipe
1418
RUN ln -s /usr/sbin/gpsd /usr/local/sbin/gpsd
1519
RUN ln -s /usr/bin/ubxtool /usr/local/bin/ubxtool
1620

17-
1821
COPY --from=builder /go/src/github.com/k8snetworkplumbingwg/linuxptp-daemon/bin/ptp /usr/local/bin/
22+
COPY --from=builder /tmp/COMMIT_HASH /tmp/COMMIT_HASH
23+
24+
# If COMMIT_HASH not provided as build-arg, read it from the file
25+
RUN if [ -z "$COMMIT_HASH" ]; then COMMIT_HASH=$(cat /tmp/COMMIT_HASH); fi && \
26+
echo "Commit: $COMMIT_HASH"
27+
28+
LABEL io.openshift.build.commit.url="https://github.com/k8snetworkplumbingwg/linuxptp-daemon/commit/${COMMIT_HASH:-unknown}"
1929

2030
CMD ["/usr/local/bin/ptp"]

ptp-tools/Dockerfile.ptpop

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@ COPY .. .
44
ENV GO111MODULE=off
55
ENV GOMAXPROCS=16
66

7+
# Capture the commit hash from the copied repository
8+
RUN if [ -d .git ]; then git rev-parse HEAD > /tmp/COMMIT_HASH; else echo "unknown" > /tmp/COMMIT_HASH; fi
9+
710
RUN make -j 16
811

912
FROM quay.io/centos/centos:stream9
13+
14+
ARG COMMIT_HASH
15+
1016
COPY --from=builder /go/src/github.com/k8snetworkplumbingwg/ptp-operator/build/_output/bin/ptp-operator /usr/local/bin/
1117
COPY --from=builder /go/src/github.com/k8snetworkplumbingwg/ptp-operator/manifests /manifests
18+
COPY --from=builder /tmp/COMMIT_HASH /tmp/COMMIT_HASH
1219
COPY bindata /bindata
1320

21+
# If COMMIT_HASH not provided as build-arg, read it from the file
22+
RUN if [ -z "$COMMIT_HASH" ]; then COMMIT_HASH=$(cat /tmp/COMMIT_HASH); fi && \
23+
echo "Commit: $COMMIT_HASH"
24+
1425
LABEL io.k8s.display-name="OpenShift ptp-operator" \
1526
io.k8s.description="This is a component that manages cluster PTP configuration." \
1627
io.openshift.tags="openshift,ptp" \
28+
io.openshift.build.commit.url="https://github.com/k8snetworkplumbingwg/ptp-operator/commit/${COMMIT_HASH:-unknown}" \
1729
com.redhat.delivery.appregistry=true \
1830
maintainer="PTP Dev Team <ptp-dev@redhat.com>"
1931

ptp-tools/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ podman-push-%:
4040

4141
build-image:
4242
podman manifest create ${IMG_PREFIX}:$(VAR)
43-
podman build --no-cache --platform $(PLATFORM) -f Dockerfile.$(VAR) --manifest ${IMG_PREFIX}:$(VAR) ..
43+
# Optionally pass COMMIT_HASH as build argument if set
44+
$(eval BUILD_ARGS := $(if $(COMMIT_HASH),--build-arg COMMIT_HASH=$(COMMIT_HASH),))
45+
podman build --no-cache --platform $(PLATFORM) $(BUILD_ARGS) -f Dockerfile.$(VAR) --manifest ${IMG_PREFIX}:$(VAR) ..
4446

4547
clean-image:
4648
podman image rm ${IMG_PREFIX}:$(VAR) || true

ptp-tools/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
# PTP Tools - Container Image Builder
1+
# PTP Tools
2+
3+
## Build Commit Labels
4+
5+
All CI images built from these Dockerfiles include an `io.openshift.build.commit.url` label that points to the exact commit of the source code compiled into the image:
6+
7+
- **Dockerfile.lptpd**: Points to the linuxptp-daemon commit from github.com/k8snetworkplumbingwg/linuxptp-daemon
8+
- **Dockerfile.cep**: Points to the cloud-event-proxy commit from github.com/redhat-cne/cloud-event-proxy
9+
- **Dockerfile.krp**: Points to the kube-rbac-proxy commit from github.com/openshift/kube-rbac-proxy
10+
- **Dockerfile.ptpop**: Points to the ptp-operator commit from github.com/k8snetworkplumbingwg/ptp-operator
11+
12+
The commit hash is automatically captured during the build process from the cloned/copied repository.
13+
14+
### Overriding Commit Hash
15+
16+
You can optionally override the commit hash by passing it as a build argument:
17+
18+
```bash
19+
make build-image VAR=lptpd COMMIT_HASH=abc123def456
20+
``` - Container Image Builder
221
322
This directory contains tools and scripts for building all container images required to run the PTP operator.
423

0 commit comments

Comments
 (0)