Skip to content

Commit 2bc41a4

Browse files
authored
Add script to update the git-sync image (#2064)
1 parent c7841d4 commit 2bc41a4

3 files changed

Lines changed: 68 additions & 14 deletions

File tree

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ HELM_STAGING_DIR := $(OUTPUT_DIR)/third_party/helm
8989
COSIGN_VERSION := v2.4.1
9090
COSIGN := $(BIN_DIR)/cosign
9191

92+
# To automatically update, run this command:
93+
# UPDATE_TYPE=<latest-version|latest-build> make update-git-sync-image
9294
GIT_SYNC_VERSION := v4.4.2-gke.16__linux_amd64
9395
GIT_SYNC_IMAGE_NAME := gcr.io/config-management-release/git-sync:$(GIT_SYNC_VERSION)
9496

@@ -541,6 +543,10 @@ print-%:
541543
update-debian-base-image:
542544
@./scripts/update-debian-base-image.sh
543545

546+
.PHONY: update-git-sync-image
547+
update-git-sync-image:
548+
@./scripts/update-git-sync-image.sh
549+
544550
####################################################################################################
545551
# MANUAL TESTING COMMANDS
546552

scripts/update-debian-base-image.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@
1616

1717
set -euo pipefail
1818

19-
####################################################################################################
20-
# FUNCTION DECLARATIONS
21-
#
22-
# It's crucial that error messages in these functions be sent to stderr with 1>&2.
23-
# Otherwise, they will not bubble up to the make target that calls this script.
24-
25-
err() {
26-
local msg="$1"
27-
echo "${msg}" 1>&2
28-
exit 1
29-
}
30-
31-
####################################################################################################
32-
3319
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
3420
cd "${REPO_ROOT}"
3521

scripts/update-git-sync-image.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
20+
cd "${REPO_ROOT}"
21+
22+
UPDATE_TYPE=${UPDATE_TYPE:-latest-build}
23+
24+
set +e
25+
# Get the current tag from the Makefile
26+
CURRENT_TAG=$(grep "^GIT_SYNC_VERSION :=" Makefile | sed 's/.*:= //')
27+
if [ -z "${CURRENT_TAG}" ]; then
28+
echo "Failed to find GIT_SYNC_VERSION" >&2
29+
exit 1
30+
fi
31+
set -e
32+
33+
if [[ "${UPDATE_TYPE}" == "latest-version" ]]; then
34+
FILTER="NOT tags:no-new-use-public-image*"
35+
GREP_PATTERN="__linux_amd64"
36+
elif [[ "${UPDATE_TYPE}" == "latest-build" ]]; then
37+
# Strip the -gke.N__linux_amd64 suffix to get the base version
38+
BASE_VERSION=${CURRENT_TAG%-gke.*__linux_amd64}
39+
FILTER="tags:${BASE_VERSION}*"
40+
GREP_PATTERN="^${BASE_VERSION}"
41+
else
42+
echo "Usage: $0 [latest-version|latest-build]" >&2
43+
exit 1
44+
fi
45+
46+
echo "Fetching ${UPDATE_TYPE//-/ } tag for git-sync"
47+
LATEST_TAG=$(gcloud container images list-tags gcr.io/config-management-release/git-sync \
48+
--filter="${FILTER}" \
49+
--format="value(tags)" | tr ',' '\n' | grep "${GREP_PATTERN}" | sort -V | tail -n 1)
50+
51+
if [ -z "${LATEST_TAG}" ]; then
52+
echo "Failed to find latest tag for git-sync" >&2
53+
exit 1
54+
fi
55+
56+
if [ "$LATEST_TAG" == "$CURRENT_TAG" ]; then
57+
echo "GIT_SYNC_VERSION is already up to date ($LATEST_TAG)."
58+
exit 0
59+
fi
60+
61+
echo "Updating GIT_SYNC_VERSION from $CURRENT_TAG to $LATEST_TAG"
62+
sed -i "s|^GIT_SYNC_VERSION := .*|GIT_SYNC_VERSION := ${LATEST_TAG}|" Makefile

0 commit comments

Comments
 (0)