Skip to content

Commit c2d604b

Browse files
committed
add rpm publish script
1 parent 38a3f01 commit c2d604b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

scripts/publish-rpm-packages.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# This script is used to publish new packages to the CLI RPM repository
4+
# Usage: ./publish-rpm-packages.sh
5+
set -eo pipefail
6+
7+
ROOT_DIR=$(git rev-parse --show-toplevel)
8+
9+
PACKAGES_BUCKET_URL="https://packages.stackit.cloud"
10+
RPM_REPO_PATH="rpm/cli"
11+
RPM_BUCKET_NAME="distribution"
12+
CUSTOM_KEYRING_FILE="rpm-keyring.gpg"
13+
GORELEASER_PACKAGES_FOLDER="dist/"
14+
TEMP_DIR=$(mktemp -d)
15+
16+
# We need to disable the key database daemon (keyboxd)
17+
# This can be done by removing "use-keyboxd" from ~/.gnupg/common.conf (see https://github.com/gpg/gnupg/blob/master/README)
18+
echo -n >~/.gnupg/common.conf
19+
20+
# Create a local mirror of the current state of the remote RPM repository
21+
printf ">>> Creating mirror \n"
22+
curl ${PACKAGES_BUCKET_URL}/${RPM_REPO_PATH}/repodata/repomd.xml >${TEMP_DIR}/repomd.xml || echo "No existing repository found, creating new one"
23+
24+
# Create RPM repository structure
25+
mkdir -p ${TEMP_DIR}/rpm-repo/RPMS
26+
27+
# Copy existing RPMs from remote repository (if any)
28+
printf "\n>>> Downloading existing RPMs \n"
29+
aws s3 sync s3://${RPM_BUCKET_NAME}/${RPM_REPO_PATH}/RPMS/ ${TEMP_DIR}/rpm-repo/RPMS/ --endpoint-url https://object.storage.eu01.onstackit.cloud || echo "No existing RPMs found"
30+
31+
# Copy new generated .rpm packages to the local repo
32+
# Note: GoReleaser already signs these RPM packages with embedded signatures
33+
printf "\n>>> Adding new packages to local repo \n"
34+
cp ${GORELEASER_PACKAGES_FOLDER}/*.rpm ${TEMP_DIR}/rpm-repo/RPMS/
35+
36+
# Create RPM repository metadata using createrepo_c
37+
printf "\n>>> Creating RPM repository metadata \n"
38+
docker run --rm \
39+
-v "${TEMP_DIR}/rpm-repo:/repo" \
40+
fedora:latest \
41+
bash -c "
42+
# Install createrepo_c
43+
dnf install -y createrepo_c
44+
45+
# Create repository metadata
46+
createrepo_c /repo
47+
"
48+
49+
# Sign the repository metadata using the same GPG key as APT
50+
if [ -n "$GPG_PRIVATE_KEY_FINGERPRINT" ] && [ -n "$GPG_PASSPHRASE" ]; then
51+
printf "\n>>> Signing repository metadata \n"
52+
gpg --batch --yes --pinentry-mode loopback --local-user="${GPG_PRIVATE_KEY_FINGERPRINT}" --passphrase="${GPG_PASSPHRASE}" --detach-sign --armor ${TEMP_DIR}/rpm-repo/repodata/repomd.xml
53+
else
54+
echo ">>> Skipping repository metadata signing (GPG environment variables not set)"
55+
fi
56+
57+
# Upload to S3
58+
printf "\n>>> Uploading to S3 \n"
59+
aws s3 sync ${TEMP_DIR}/rpm-repo/ s3://${RPM_BUCKET_NAME}/${RPM_REPO_PATH}/ --endpoint-url https://object.storage.eu01.onstackit.cloud
60+
61+
# Clean up
62+
rm -rf ${TEMP_DIR}
63+
64+
printf "\n>>> RPM repository published successfully to ${PACKAGES_BUCKET_URL}/${RPM_REPO_PATH} \n"

0 commit comments

Comments
 (0)