Skip to content

Commit 4078828

Browse files
Merge pull request #83 from fmount/os_git_version
Add OS_GIT_VERSION to the openstack-must-gather build system
2 parents b929cdf + 3f65aed commit 4078828

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ FROM quay.io/openshift/origin-must-gather:4.15.0 as builder
22

33
FROM quay.io/centos/centos:stream9
44

5+
ARG OS_GIT_VERSION
6+
57
RUN dnf update -y && dnf install jq xz rsync python3-pyyaml openssh-clients -y && dnf clean all
68

79
COPY --from=builder /usr/bin/oc /usr/bin/oc
@@ -15,5 +17,9 @@ COPY collection-scripts/* /usr/bin/
1517
# Copy the python script used to mask sensitive data
1618
COPY pyscripts/mask.py /usr/bin/
1719

20+
# Set openstack-must-gather image version based on
21+
# the current git info
22+
ENV OS_GIT_VERSION=${OS_GIT_VERSION}
23+
1824
# Entrypoint not used when calling `oc adm must-gather`
1925
ENTRYPOINT /usr/bin/gather

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
IMAGE_REGISTRY ?= quay.io/openstack-k8s-operators
22
IMAGE_TAG ?= latest
33

4+
OS_GIT_COMMIT := $(shell git rev-parse --short "HEAD^{commit}")
5+
OS_GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
6+
OS_GIT_COMMIT_COUNT := $(shell git rev-list HEAD --count)
7+
OS_GIT_VERSION := $(OS_GIT_BRANCH)-$(OS_GIT_COMMIT_COUNT)-g$(OS_GIT_COMMIT)
8+
9+
BUILD_ARGS ?= --build-arg OS_GIT_VERSION=${OS_GIT_VERSION}
10+
411
check-image: ## Check if the MUST_GATHER_IMAGE variable is set
512
ifndef MUST_GATHER_IMAGE
613
$(error MUST_GATHER_IMAGE is not set.)
@@ -15,7 +22,7 @@ pytest: ## Run sanity check against python scripts in pydir
1522
tox -c pyscripts/tox.ini
1623

1724
podman-build: check-image ## build the must-gather image
18-
podman build -t ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG} .
25+
podman build -t ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG} ${BUILD_ARGS} .
1926

2027
podman-push: check-image ## push the must-gather image to the image registry
2128
podman push ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG}

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ The targets for `make` are as follows:
236236
- `podman-build`: builds the must-gather image
237237
- `podman-push`: pushes an already-built `must-gather` image
238238
239+
As per the [must-gather
240+
guidelines](https://github.com/openshift/must-gather/blob/master/must-gather.md#must-gather-images),
241+
when a must-gather image is built, a `OS_GIT_VERSION` environment variable is
242+
set within the image in the form `major.minor.micro.qualifier`, so that
243+
programmatic analysis can be developed.
244+
For OpenStack must-gather, instad, the version is created starting from the
245+
last commit, and it creates a qualifier based on the following commands:
246+
247+
```bash
248+
OS_GIT_COMMIT=$(git rev-parse --short "HEAD^{commit}")
249+
OS_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
250+
OS_GIT_COMMIT_COUNT=$(git rev-list HEAD --count)
251+
OS_GIT_VERSION=$(OS_GIT_BRANCH)-$(OS_GIT_COMMIT_COUNT)-g$(OS_GIT_COMMIT)
252+
```
253+
The resulting format is in the form: `<branch>-<number-of-commits>-g<commit-hash>`
254+
255+
For example, if you are on `18.0-FR2` branch, a potential output might look
256+
like:
257+
258+
```
259+
18.0-FR2-165-g1234567
260+
```
261+
262+
Where:
263+
264+
- 18.0-FR2 is the current branch
265+
- The middle number (165) is how many commits are present in the branch
266+
- g1234567 is the abbreviated commit hash
267+
239268
### Debugging container
240269
241270
One possible workflow that can be used for development is to run the openstack

0 commit comments

Comments
 (0)