-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepogen.sh
More file actions
executable file
·252 lines (207 loc) · 9.08 KB
/
repogen.sh
File metadata and controls
executable file
·252 lines (207 loc) · 9.08 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
set -e
# Parse arguments
PACKAGE_MANAGER="${1:-all}" # debian, rpm, alpine, or all (default)
if [[ ! "$PACKAGE_MANAGER" =~ ^(debian|rpm|alpine|all)$ ]]; then
echo "Usage: $0 [debian|rpm|alpine|all]"
echo " Default: all"
exit 1
fi
echo "Package manager filter: $PACKAGE_MANAGER"
# Required environment variables:
# - VERSION: Version of the CLI being released (auto-detected from dist/ if not set)
# - AWS credentials: Configured via AWS CLI or environment
# - GPG_PRIVATE_KEY_FILE: Path to GPG private key file for signing Debian/RPM packages
# OR GPG_PRIVATE_KEY: Base64-encoded GPG private key (legacy)
# - RSA_PRIVATE_KEY_FILE: Path to RSA private key file for signing Alpine packages
# OR RSA_PRIVATE_KEY: RSA private key content (legacy)
# - RSA_PUBLIC_KEY_FILE: Path to RSA public key file for Alpine users
# OR RSA_PUBLIC_KEY: RSA public key content (legacy)
# Auto-detect VERSION from dist/ if not set
if [ -z "$VERSION" ]; then
# Use glob instead of ls to avoid parsing ls output
for deb_file in dist/*-cli_*_linux_*.deb; do
if [ -f "$deb_file" ]; then
VERSION=$(basename "$deb_file" | sed -E 's/.*-cli_(.+)_linux_.*/\1/')
break
fi
done
if [ -n "$VERSION" ]; then
echo "Auto-detected VERSION: $VERSION"
fi
fi
# Validate VERSION format (should be semver-like)
if [ -n "$VERSION" ] && ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'; then
echo "Warning: VERSION '$VERSION' does not look like a valid semver format"
fi
# Check required environment variables
MISSING_VARS=()
if [ -z "$VERSION" ]; then
MISSING_VARS+=("VERSION")
fi
if [ -z "$GPG_PRIVATE_KEY_FILE" ] && [ -z "$GPG_PRIVATE_KEY" ]; then
MISSING_VARS+=("GPG_PRIVATE_KEY_FILE or GPG_PRIVATE_KEY")
fi
if [ -z "$RSA_PRIVATE_KEY_FILE" ] && [ -z "$RSA_PRIVATE_KEY" ]; then
MISSING_VARS+=("RSA_PRIVATE_KEY_FILE or RSA_PRIVATE_KEY")
fi
if [ -z "$RSA_PUBLIC_KEY_FILE" ] && [ -z "$RSA_PUBLIC_KEY" ]; then
MISSING_VARS+=("RSA_PUBLIC_KEY_FILE or RSA_PUBLIC_KEY")
fi
if [ ${#MISSING_VARS[@]} -ne 0 ]; then
echo "Error: The following required environment variables are not set:"
for var in "${MISSING_VARS[@]}"; do
echo " - $var"
done
exit 1
fi
# AWS bucket for package repositories
export AWS_BUCKET="${AWS_BUCKET:-public-repogen-repositories-upsun-com}"
# Set AWS region
export AWS_DEFAULT_REGION="${AWS_REGION:-eu-west-1}"
# Create temporary directories for repository work
WORK_DIR=$(mktemp -d)
# Use a temporary GNUPGHOME to avoid polluting the user's keyring
export GNUPGHOME=$(mktemp -d)
trap "rm -rf \"$WORK_DIR\" \"$GNUPGHOME\"" EXIT
# Handle GPG key - from file or environment variable
if [ -n "$GPG_PRIVATE_KEY_FILE" ]; then
GPG_KEY_FILE="$GPG_PRIVATE_KEY_FILE"
else
GPG_KEY_FILE="${WORK_DIR}/gpg-private-key.asc"
echo "$GPG_PRIVATE_KEY" | base64 -d > "$GPG_KEY_FILE"
fi
# Import GPG key
gpg --import "$GPG_KEY_FILE"
# Handle RSA private key - from file or environment variable
if [ -n "$RSA_PRIVATE_KEY_FILE" ]; then
RSA_KEY_FILE="$RSA_PRIVATE_KEY_FILE"
else
RSA_KEY_FILE="${WORK_DIR}/rsa-private-key.pem"
echo "$RSA_PRIVATE_KEY" > "$RSA_KEY_FILE"
fi
# Handle RSA public key - from file or environment variable
if [ -n "$RSA_PUBLIC_KEY_FILE" ]; then
RSA_PUB_KEY_FILE="$RSA_PUBLIC_KEY_FILE"
else
RSA_PUB_KEY_FILE="${WORK_DIR}/repositories-upsun-com.rsa.pub"
echo "$RSA_PUBLIC_KEY" > "$RSA_PUB_KEY_FILE"
fi
# Packages are expected to be pre-built by goreleaser in the dist/ directory
# goreleaser builds signed .deb, .rpm, and .apk packages via nfpm
# Check that packages exist
if [ ! -d "dist" ]; then
echo "Error: dist/ directory not found. Run 'goreleaser release' or 'make snapshot' first."
exit 1
fi
# Create shared staging directories for all packages
# Both platformsh and upsun packages go in the same directories so they're
# processed together and appear in the same repository indexes
PACKAGES_DEB_DIR="${WORK_DIR}/packages-deb"
PACKAGES_RPM_DIR="${WORK_DIR}/packages-rpm"
PACKAGES_APK_DIR="${WORK_DIR}/packages-apk"
REPO_DIR="${WORK_DIR}/repo"
mkdir -p "$PACKAGES_DEB_DIR" "$PACKAGES_RPM_DIR" "$PACKAGES_APK_DIR" "$REPO_DIR"
echo "=== Copying packages to staging directories ==="
# Copy Platform.sh packages
cp dist/platformsh-cli_${VERSION}_linux_amd64.deb "$PACKAGES_DEB_DIR/"
cp dist/platformsh-cli_${VERSION}_linux_arm64.deb "$PACKAGES_DEB_DIR/"
cp dist/platformsh-cli_${VERSION}_linux_amd64.apk "$PACKAGES_APK_DIR/"
cp dist/platformsh-cli_${VERSION}_linux_arm64.apk "$PACKAGES_APK_DIR/"
cp dist/platformsh-cli_${VERSION}_linux_amd64.rpm "$PACKAGES_RPM_DIR/"
cp dist/platformsh-cli_${VERSION}_linux_arm64.rpm "$PACKAGES_RPM_DIR/"
# Copy Upsun packages
cp dist/upsun-cli_${VERSION}_linux_amd64.deb "$PACKAGES_DEB_DIR/"
cp dist/upsun-cli_${VERSION}_linux_arm64.deb "$PACKAGES_DEB_DIR/"
cp dist/upsun-cli_${VERSION}_linux_amd64.apk "$PACKAGES_APK_DIR/"
cp dist/upsun-cli_${VERSION}_linux_arm64.apk "$PACKAGES_APK_DIR/"
cp dist/upsun-cli_${VERSION}_linux_amd64.rpm "$PACKAGES_RPM_DIR/"
cp dist/upsun-cli_${VERSION}_linux_arm64.rpm "$PACKAGES_RPM_DIR/"
echo "Packages staged:"
ls -la "$PACKAGES_DEB_DIR" "$PACKAGES_RPM_DIR" "$PACKAGES_APK_DIR" 2>/dev/null
# Check that at least some packages were found
pkg_count=$(find "$PACKAGES_DEB_DIR" "$PACKAGES_RPM_DIR" "$PACKAGES_APK_DIR" -type f 2>/dev/null | wc -l)
if [ "$pkg_count" -eq 0 ]; then
echo "Error: No packages found in staging directories. Check that goreleaser produced the expected packages."
exit 1
fi
echo "Found $pkg_count package(s) to process."
# --- Debian Repository ---
if [[ "$PACKAGE_MANAGER" == "all" || "$PACKAGE_MANAGER" == "debian" ]]; then
echo "=== Processing Debian packages ==="
DEB_REPO_DIR="${REPO_DIR}/debian"
mkdir -p "$DEB_REPO_DIR"
# Sync Debian metadata from S3 (if exists)
aws s3 sync "s3://${AWS_BUCKET}/debian/dists" "${DEB_REPO_DIR}/dists" --delete 2>/dev/null || true
# Run repogen for Debian packages
repogen generate \
--input-dir "$PACKAGES_DEB_DIR" \
--output-dir "$DEB_REPO_DIR" \
--incremental \
--arch amd64,arm64 \
--codename stable \
--origin "Upsun" \
--label "Upsun CLI" \
--gpg-key "$GPG_KEY_FILE"
# Sync Debian back to S3
aws s3 sync "${DEB_REPO_DIR}" "s3://${AWS_BUCKET}/debian"
echo "=== Done processing Debian packages ==="
fi
# --- RPM Repository ---
# Generates repos for multiple Fedora versions to support $releasever in yum/dnf configs
if [[ "$PACKAGE_MANAGER" == "all" || "$PACKAGE_MANAGER" == "rpm" ]]; then
echo "=== Processing RPM packages ==="
# Fedora versions to support (configurable via environment variable)
FEDORA_VERSIONS="${FEDORA_VERSIONS:-40 41 42 43}"
for FEDORA_VER in $FEDORA_VERSIONS; do
echo "--- Processing Fedora $FEDORA_VER ---"
# Use a separate output directory per version to avoid repogen's ParseExistingMetadata
# scanning all version directories and detecting conflicts
RPM_REPO_DIR="${REPO_DIR}/fedora-${FEDORA_VER}"
mkdir -p "$RPM_REPO_DIR"
# Sync only repodata metadata from S3 (not packages)
for arch in x86_64 aarch64; do
mkdir -p "${RPM_REPO_DIR}/${FEDORA_VER}/${arch}/repodata"
aws s3 sync "s3://${AWS_BUCKET}/fedora/${FEDORA_VER}/${arch}/repodata" "${RPM_REPO_DIR}/${FEDORA_VER}/${arch}/repodata" --delete 2>/dev/null || true
done
# Run repogen for RPM packages with explicit version
# repogen will create $version/$arch/Packages/ and $version/$arch/repodata/ inside output-dir
repogen generate \
--input-dir "$PACKAGES_RPM_DIR" \
--output-dir "$RPM_REPO_DIR" \
--incremental \
--arch amd64,arm64 \
--origin "Upsun" \
--label "Upsun CLI" \
--version "$FEDORA_VER" \
--gpg-key "$GPG_KEY_FILE"
# Sync this Fedora version back to S3 (without --delete to preserve existing packages)
aws s3 sync "${RPM_REPO_DIR}/${FEDORA_VER}" "s3://${AWS_BUCKET}/fedora/${FEDORA_VER}"
done
echo "=== Done processing RPM packages ==="
fi
# --- Alpine Repository ---
if [[ "$PACKAGE_MANAGER" == "all" || "$PACKAGE_MANAGER" == "alpine" ]]; then
echo "=== Processing Alpine packages ==="
APK_REPO_DIR="${REPO_DIR}/alpine"
mkdir -p "$APK_REPO_DIR"
# Sync Alpine metadata from S3 (if exists)
for arch in x86_64 aarch64; do
mkdir -p "${APK_REPO_DIR}/${arch}"
aws s3 cp "s3://${AWS_BUCKET}/alpine/${arch}/APKINDEX.tar.gz" "${APK_REPO_DIR}/${arch}/APKINDEX.tar.gz" 2>/dev/null || true
done
# Run repogen for Alpine packages with RSA signing
repogen generate \
--input-dir "$PACKAGES_APK_DIR" \
--output-dir "$APK_REPO_DIR" \
--incremental \
--arch amd64,arm64 \
--rsa-key "$RSA_KEY_FILE" \
--key-name "repositories-upsun-com"
# Copy RSA public key for users to download
cp "$RSA_PUB_KEY_FILE" "${APK_REPO_DIR}/"
# Sync Alpine back to S3
aws s3 sync "${APK_REPO_DIR}" "s3://${AWS_BUCKET}/alpine"
echo "=== Done processing Alpine packages ==="
fi
echo "All packages uploaded successfully!"