-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·69 lines (54 loc) · 2.83 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·69 lines (54 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
REGISTRY_URL="https://registry.hub.docker.com/v1/repositories/__IMAGE_NAME__/tags"
DEFAULT_FILE_PATH="templates/deployment.yaml"
SEARCH_PATH=${INPUT_FILEPATH:-$DEFAULT_FILE_PATH}
# Remove optional leading slash
SEARCH_PATH=${SEARCH_PATH#/}
shopt -s nullglob
COMPONENTS=(*/)
shopt -u nullglob # Turn off nullglob to make sure it doesn't interfere with anything later
for COMPONENT in ${COMPONENTS[@]}; do
# Remove optional trailing slash
COMPONENT=${COMPONENT/\//""}
SR_FILE="${COMPONENT}/${SEARCH_PATH}" #S(earchAnd)R(eplace)_FILE
echo "Updating GitOps YAMLs for '${COMPONENT}'"
echo "Search path: '${SR_FILE}'"
if [[ ! -f "${SR_FILE}" ]]; then
echo "Skipping... File '${SR_FILE}' does not exist for '${COMPONENT}'."
echo ""
continue
fi
#Initial implementation
# - updated to support both 'image' and 'applicationImage'
# - 'image' is standard in k8s Deployment YAMLs
# - 'applicationImage' is used in Appsody app-deploy.yaml
#IMAGE_NAME=$(cat ${COMPONENT}/${SEARCH_PATH} | grep "image:" | sed 's/.*image\: \"//' | sed 's/\:.*$//')
IMAGE_NAME=$(cat ${COMPONENT}/${SEARCH_PATH} | grep "mage:" | sed -e 's/^.*mage\: //' -e 's/\:.*$//' -e 's/"//g')
echo "Calculated image name: ${IMAGE_NAME}"
# Extract {REPO_NAME} from {REPO_NAME}/{IMAGE_NAME}
REPO_NAME=$(echo $IMAGE_NAME | sed 's/\(.*\)\/.*/\1/')
echo "Calculated image repository: ${REPO_NAME}"
# Split {REPO_NAME}/{IMAGE_NAME} into only {IMAGE_NAME}
IMAGE_SHORT_NAME=${IMAGE_NAME/${REPO_NAME}\//""}
echo "Calculated image short name: ${IMAGE_SHORT_NAME}"
#Initial implementation
# - updated to support both 'image' and 'applicationImage'
# - 'image' is standard in k8s Deployment YAMLs
# - 'applicationImage' is used in Appsody app-deploy.yaml
#CURRENT_VER_TAG=$(cat ${COMPONENT}/${SEARCH_PATH} | grep "image:" | grep --only-matching -e "[Vv]\?[0-9]*\.[0-9]*\.[0-9]*")
CURRENT_VER_TAG=$(cat ${COMPONENT}/${SEARCH_PATH} | grep "mage:" | grep --only-matching -e "[Vv]\?[0-9]*\.[0-9]*\.[0-9]*")
echo "Calculated current tag: ${CURRENT_VER_TAG}"
LATEST_VER_URL=${REGISTRY_URL/__IMAGE_NAME__/${IMAGE_NAME}}
#Get latest tag, formatted for greatest semantic version value with explicit format of X.Y.Z only
LATEST_VER_TAG=$(curl --silent ${LATEST_VER_URL} | jq -r '.[] | select(.name|test("^[0-9]+\\.[0-9]+\\.[0-9]+$")) | .name' | sort -V | tail -n1)
echo "Calculated latest tag: ${LATEST_VER_TAG}"
## TODO REFACTOR TO USE yq SINCE WE ARE RUNNING IN CONTAINER
IMAGE_TAG_PATTERN="s/${IMAGE_SHORT_NAME}\:${CURRENT_VER_TAG}/${IMAGE_SHORT_NAME}\:${LATEST_VER_TAG}/"
# Replace current version (in the pattern of kcontainer-ui:X.Y.Z)
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' -e ${IMAGE_TAG_PATTERN} ${COMPONENT}/${SEARCH_PATH}
else
sed --in-place --expression ${IMAGE_TAG_PATTERN} ${COMPONENT}/${SEARCH_PATH}
fi
echo ""
done