Skip to content

Commit 4fa461b

Browse files
Publish packages with GitHub Pages deployment (#10)
- Add workflow to build full APT and YUM repositories from latest documentdb/documentdb release - Create package browser page with setup instructions - Add Packages link to navbar and homepage - Include setup scripts for easy repository installation - Support GPG signing for packages (optional) - Download packages including pre-releases - Build proper debian and RPM repository metadata
1 parent 90084d1 commit 4fa461b

File tree

5 files changed

+397
-5
lines changed

5 files changed

+397
-5
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Repository to download packages from
5+
REPO="documentdb/documentdb"
6+
7+
# Repository configuration
8+
SUITE="${SUITE:-stable}"
9+
COMPONENTS="${COMPONENTS:-main}"
10+
ORIGIN="${ORIGIN:-DocumentDB}"
11+
DESCRIPTION="${DESCRIPTION:-DocumentDB APT and YUM Repository}"
12+
13+
GOT_DEB=0
14+
GOT_RPM=0
15+
DEB_POOL="out/deb/pool/${COMPONENTS}"
16+
DEB_DISTS="dists/${SUITE}"
17+
DEB_DISTS_COMPONENTS="${DEB_DISTS}/${COMPONENTS}/binary-amd64"
18+
GPG_TTY=""
19+
export GPG_TTY
20+
21+
generate_hashes() {
22+
HASH_TYPE="$1"
23+
HASH_COMMAND="$2"
24+
echo "${HASH_TYPE}:"
25+
find "${COMPONENTS}" -type f | while read -r file
26+
do
27+
echo " $(${HASH_COMMAND} "$file" | cut -d" " -f1) $(wc -c "$file" | awk '{print $1}')"
28+
done
29+
}
30+
31+
echo "Downloading packages from $REPO releases"
32+
33+
# Get the latest release info (including pre-releases)
34+
if release=$(curl -fqs "https://api.github.com/repos/${REPO}/releases" | python3 -c "import sys, json; releases = json.load(sys.stdin); print(json.dumps(releases[0])) if releases else sys.exit(1)")
35+
then
36+
tag="$(echo "$release" | python3 -c "import sys, json; print(json.load(sys.stdin)['tag_name'])")"
37+
echo "Found latest release: $tag"
38+
39+
# Create packages directory for direct downloads
40+
mkdir -p out/packages
41+
42+
# Process each asset
43+
echo "$release" | python3 -c "
44+
import sys, json
45+
data = json.load(sys.stdin)
46+
for asset in data.get('assets', []):
47+
print(f\"{asset['name']}|{asset['browser_download_url']}\")
48+
" | while IFS='|' read -r filename download_url
49+
do
50+
if [ -z "$filename" ]; then
51+
continue
52+
fi
53+
54+
echo "Processing: $filename"
55+
56+
# Determine file type and handle accordingly
57+
if [[ "$filename" == *.deb ]]; then
58+
GOT_DEB=1
59+
mkdir -p "$DEB_POOL"
60+
echo " Downloading DEB package to pool"
61+
wget -q -P "$DEB_POOL" "$download_url"
62+
# Also copy to packages for direct download
63+
cp "$DEB_POOL/$filename" out/packages/
64+
elif [[ "$filename" == *.rpm ]]; then
65+
GOT_RPM=1
66+
mkdir -p out/rpm
67+
echo " Downloading RPM package"
68+
wget -q -P out/rpm "$download_url"
69+
# Also copy to packages for direct download
70+
cp "out/rpm/$filename" out/packages/
71+
else
72+
# Other files go directly to packages
73+
echo " Downloading to packages directory"
74+
wget -q -P out/packages "$download_url"
75+
fi
76+
done
77+
78+
# Save release metadata
79+
echo "$release" | python3 -c "
80+
import sys, json
81+
data = json.load(sys.stdin)
82+
output = {
83+
'tag_name': data['tag_name'],
84+
'name': data.get('name', data['tag_name']),
85+
'published_at': data['published_at'],
86+
'html_url': data['html_url'],
87+
'assets': [{
88+
'name': asset['name'],
89+
'browser_download_url': asset['browser_download_url'],
90+
'size': asset['size'],
91+
'download_count': asset.get('download_count', 0)
92+
} for asset in data.get('assets', [])]
93+
}
94+
print(json.dumps(output, indent=2))
95+
" > out/packages/release-info.json
96+
97+
echo "Successfully processed packages from $REPO"
98+
else
99+
echo "Error: Could not fetch release information for $REPO"
100+
exit 1
101+
fi
102+
103+
# Build DEB repository if we have DEB packages
104+
if [ -d "$DEB_POOL" ] && [ "$(ls -A $DEB_POOL/*.deb 2>/dev/null)" ]; then
105+
echo "Building APT repository..."
106+
pushd out/deb >/dev/null
107+
108+
mkdir -p "${DEB_DISTS_COMPONENTS}"
109+
110+
echo "Scanning DEB packages and creating Packages file"
111+
dpkg-scanpackages --arch amd64 pool/ > "${DEB_DISTS_COMPONENTS}/Packages"
112+
gzip -k -f "${DEB_DISTS_COMPONENTS}/Packages"
113+
114+
pushd "${DEB_DISTS}" >/dev/null
115+
116+
echo "Creating Release file"
117+
{
118+
echo "Origin: ${ORIGIN}"
119+
echo "Label: DocumentDB"
120+
echo "Suite: ${SUITE}"
121+
echo "Codename: ${SUITE}"
122+
echo "Version: 1.0"
123+
echo "Architectures: amd64"
124+
echo "Components: ${COMPONENTS}"
125+
echo "Description: ${DESCRIPTION}"
126+
echo "Date: $(date -Ru)"
127+
generate_hashes MD5Sum md5sum
128+
generate_hashes SHA1 sha1sum
129+
generate_hashes SHA256 sha256sum
130+
} > Release
131+
132+
# Sign if GPG is available
133+
if [ -n "$GPG_FINGERPRINT" ]; then
134+
echo "Signing Release file with GPG"
135+
gpg --default-key "$GPG_FINGERPRINT" --detach-sign --armor -o Release.gpg Release
136+
gpg --default-key "$GPG_FINGERPRINT" --clearsign -o InRelease Release
137+
else
138+
echo "Warning: GPG_FINGERPRINT not set, skipping package signing"
139+
fi
140+
141+
popd >/dev/null
142+
popd >/dev/null
143+
echo "APT repository built successfully"
144+
fi
145+
146+
# Build RPM repository if we have RPM packages
147+
if [ -d "out/rpm" ] && [ "$(ls -A out/rpm/*.rpm 2>/dev/null)" ]; then
148+
echo "Building YUM repository..."
149+
pushd out/rpm >/dev/null
150+
151+
# Sign RPMs if GPG is available
152+
if [ -n "$GPG_FINGERPRINT" ]; then
153+
echo "Signing RPM packages"
154+
for rpm_file in *.rpm; do
155+
rpm --define "%_signature gpg" --define "%_gpg_name ${GPG_FINGERPRINT}" --addsign "$rpm_file" || echo "Warning: Could not sign $rpm_file"
156+
done
157+
fi
158+
159+
echo "Creating YUM repository metadata"
160+
createrepo_c .
161+
162+
# Sign repository metadata if GPG is available
163+
if [ -n "$GPG_FINGERPRINT" ]; then
164+
echo "Signing repository metadata"
165+
gpg --default-key "$GPG_FINGERPRINT" --detach-sign --armor repodata/repomd.xml
166+
fi
167+
168+
popd >/dev/null
169+
echo "YUM repository built successfully"
170+
fi
171+
172+
173+
echo "Package repository setup complete!"
174+
echo ""
175+
echo "Repository structure:"
176+
ls -lh out/
177+
178+
# Create an index file for the packages
179+
180+
echo "Package download complete!"
181+
ls -lh out/packages/

.github/workflows/nextjs.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# Sample workflow for building and deploying a Next.js site to GitHub Pages
2-
#
3-
# To get started with Next.js see: https://nextjs.org/docs/getting-started
4-
#
5-
name: Deploy Next.js site to Pages
1+
# Workflow for building Next.js site and downloading DocumentDB packages, then deploying to GitHub Pages
2+
name: Deploy Next.js site and DocumentDB packages to Pages
63

74
on:
85
# Runs on pushes targeting the default branch
@@ -31,6 +28,24 @@ jobs:
3128
steps:
3229
- name: Checkout
3330
uses: actions/checkout@v4
31+
- name: Install required packages
32+
run: |
33+
until sudo apt-get update; do sleep 1; done
34+
sudo apt-get install -y createrepo-c dpkg-dev gnupg2 python3
35+
- name: Setup GPG
36+
id: import_gpg
37+
uses: crazy-max/ghaction-import-gpg@v6
38+
with:
39+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
40+
continue-on-error: true
41+
- name: Set GPG fingerprint
42+
run: |
43+
if [ -n "${{ steps.import_gpg.outputs.fingerprint }}" ]; then
44+
echo "GPG_FINGERPRINT=${{ steps.import_gpg.outputs.fingerprint }}" >> $GITHUB_ENV
45+
echo "✓ GPG key loaded: ${{ steps.import_gpg.outputs.fingerprint }}"
46+
else
47+
echo "⚠ No GPG key configured - packages will not be signed"
48+
fi
3449
- name: Detect package manager
3550
id: detect-package-manager
3651
run: |
@@ -75,6 +90,8 @@ jobs:
7590
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
7691
- name: Build with Next.js
7792
run: ${{ steps.detect-package-manager.outputs.runner }} next build
93+
- name: Download DocumentDB packages from latest release
94+
run: .github/scripts/download_packages.sh
7895
- name: Upload artifact
7996
uses: actions/upload-pages-artifact@v3
8097
with:

app/components/Navbar.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export default function Navbar() {
6464
>
6565
Docs
6666
</Link>
67+
<Link
68+
href="/packages"
69+
className="text-gray-300 hover:text-blue-400 transition-colors duration-200 font-medium"
70+
>
71+
Packages
72+
</Link>
6773
<Link
6874
href="/blogs"
6975
className="text-gray-300 hover:text-blue-400 transition-colors duration-200 font-medium"

0 commit comments

Comments
 (0)