-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathset-latest.sh
More file actions
executable file
·125 lines (101 loc) · 3.09 KB
/
set-latest.sh
File metadata and controls
executable file
·125 lines (101 loc) · 3.09 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
if [[ -z $1 || "$1" == "-h" ]]
then
cat << EOF
$0 -v[ersion] -t[ag] [-e] [-h]
where
- Version: of Stata (17, 18, ...) (required)
- Tag: tag to pull (required)
- -e: use template README for early version of Stata
- -h: this helpfile
This script pulls down a Stata version with specified tag, tags it as "latest",
pushes that tag, and updates the README using the early.md template.
EOF
exit 2
fi
source ./_version.sh
EARLY=0
while getopts v:t:eh flag
do
case "${flag}" in
v) VERSION=${OPTARG};;
t) TAG=${OPTARG};;
e) EARLY=1;;
h)
# Show help and exit
exec "$0" -h
;;
esac
done
# Check required parameters
if [[ -z $VERSION ]]; then
echo "Error: Version (-v) is required"
exit 1
fi
if [[ -z $TAG ]]; then
echo "Error: Tag (-t) is required"
exit 1
fi
SHORTDESC="Docker image for Stata, to be used in automation and reproducibility."
TEMPLATE="README-containers.template.md"
[[ -n $EARLY ]] && TEMPLATE="README-containers.early.md"
EXTRAMD="README-containers.$VERSION.md"
OUTPUTMD="README-containers.md"
MYHUBID=dataeditors
MYIMG=stata${VERSION}
echo "Pulling images with tag $TAG for Stata $VERSION..."
# Find all available image variants for this version
available_images=$(docker search ${MYHUBID}/${MYIMG} --limit 100 2>/dev/null | grep "${MYHUBID}/${MYIMG}" | awk '{print $1}' | grep -E "${MYIMG}-(be|se|mp)" || echo "${MYHUBID}/${MYIMG}")
if [[ -z "$available_images" ]]; then
# Fallback to basic image name
available_images="${MYHUBID}/${MYIMG}"
fi
echo "Found images to pull:"
for img in $available_images; do
echo " $img:$TAG"
done
echo ""
echo "Ready to pull and retag? (y/N)"
read answer
case $answer in
y|Y)
# Pull, retag as latest, and push for each image
for img in $available_images
do
echo "Processing $img..."
# Pull the specified tag
docker pull ${img}:$TAG
if [[ $? -ne 0 ]]; then
echo "Failed to pull ${img}:$TAG, skipping..."
continue
fi
# Tag as latest
docker tag ${img}:$TAG ${img}:latest
# Push the latest tag
docker push ${img}:latest
# Update README on Docker Hub
docker pushrm ${img} --short "$SHORTDESC"
done
# Generate README-containers.md from template
if [[ -f "$TEMPLATE" ]]; then
echo "Updating README using $TEMPLATE..."
# Extract base version (e.g., "19" from "19_5")
BASE_VERSION=$(echo "$VERSION" | cut -d'_' -f1)
# Replace template placeholders
sed -e "s/{{ base_version }}/$BASE_VERSION/g" \
-e "s/{{ full_version }}/$VERSION/g" \
"$TEMPLATE" > "$OUTPUTMD"
if [[ -f "$EXTRAMD" ]]; then
echo "" >> "$OUTPUTMD"
cat "$EXTRAMD" >> "$OUTPUTMD"
fi
echo "README updated: $OUTPUTMD"
else
echo "Warning: Template $TEMPLATE not found"
fi
echo "Pull and retag operation completed!"
;;
*)
exit 0
;;
esac