Skip to content

Build and Upload DB Binaries to R2 #26

Build and Upload DB Binaries to R2

Build and Upload DB Binaries to R2 #26

name: Build and Upload DB Binaries to R2
on:
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
max-parallel: 3
fail-fast: false
matrix:
include:
# MongoDB
- database: mongodb
db_version: 8.0.12
os: macos-latest
platform: macos
arch: arm64
ext: tar.gz
- database: mongodb
db_version: 8.0.12
os: macos-latest
platform: macos
arch: x86_64
ext: tar.gz
- database: mongodb
db_version: 8.0.12
os: ubuntu-latest
platform: linux
arch: x86_64
ext: tar.gz
# PostgreSQL
- database: postgresql
db_version: 17.6
os: macos-latest
platform: macos
arch: arm64
ext: tar.gz
- database: postgresql
db_version: 17.6
os: macos-latest
platform: macos
arch: x86_64
ext: tar.gz
- database: postgresql
db_version: 17.6
os: ubuntu-latest
platform: linux
arch: x86_64
ext: tar.gz
# Redis
- database: redis
db_version: 7.2.5
os: macos-latest
platform: macos
arch: arm64
ext: tar.gz
- database: redis
db_version: 7.2.5
os: macos-latest
platform: macos
arch: x86_64
ext: tar.gz
- database: redis
db_version: 7.2.5
os: ubuntu-latest
platform: linux
arch: x86_64
ext: tar.gz
environment: production
env:
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
R2_BUCKET: ${{ secrets.R2_BUCKET }}
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set environment variables
shell: bash
run: |
echo "DATABASE=${{ matrix.database }}" >> $GITHUB_ENV
echo "DB_VERSION=${{ matrix.db_version }}" >> $GITHUB_ENV
echo "DB_MAJOR_VERSION=$(echo '${{ matrix.db_version }}' | cut -d. -f1)" >> $GITHUB_ENV
echo "ARCH_CLEAN=$(echo '${{ matrix.arch }}' | sed 's/^_//')" >> $GITHUB_ENV
- name: Install dependencies and fetch binaries
shell: bash
run: |
mkdir -p ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}
case "$DATABASE" in
redis)
if [[ "$RUNNER_OS" == "macOS" ]]; then
curl -LO https://download.redis.io/releases/redis-${DB_VERSION}.tar.gz
tar -xzf redis-${DB_VERSION}.tar.gz
make -C redis-${DB_VERSION}
cp redis-${DB_VERSION}/src/redis-server ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
else
sudo apt update && sudo apt install redis-server -y
cp $(which redis-server) ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
fi
;;
mongodb)
if [[ "$RUNNER_OS" == "macOS" ]]; then
curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-${ARCH_CLEAN}-${DB_VERSION}.tgz
tar -xzf mongodb-macos-${ARCH_CLEAN}-${DB_VERSION}.tgz
cp ./mongodb-*/bin/* ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
curl -LO https://downloads.mongodb.com/compass/mongosh-2.5.6-darwin-arm64.zip
unzip mongosh-2.5.6-darwin-arm64.zip
cp ./mongosh-2.5.6-darwin-arm64/bin/mongosh ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
else
curl -LO https://downloads.mongodb.com/compass/mongosh-2.5.6-darwin-x64.zip
unzip mongosh-2.5.6-darwin-x64.zip
cp ./mongosh-2.5.6-darwin-x64/bin/mongosh ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
fi
else
curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-${DB_VERSION}.tgz
tar -xzf mongodb-linux-x86_64-ubuntu2204-${DB_VERSION}.tgz
cp ./mongodb-*/bin/* ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
curl -LO https://downloads.mongodb.com/compass/mongosh-2.5.6-linux-x64.tgz
tar -xzf mongosh-2.5.6-linux-x64.tgz
cp ./mongosh-2.5.6-linux-x64/bin/mongosh ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
fi
;;
postgresql)
if [[ "$RUNNER_OS" == "macOS" ]]; then
curl -LO https://get.enterprisedb.com/postgresql/postgresql-${DB_VERSION}-1-osx-${ARCH_CLEAN}.tar.gz
tar -xzf postgresql-${DB_VERSION}-1-osx-${ARCH_CLEAN}.tar.gz
cp ./pgsql/bin/* ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
else
sudo apt update && sudo apt install postgresql-${DB_MAJOR_VERSION} -y || sudo apt install postgresql -y
cp /usr/lib/postgresql/${DB_MAJOR_VERSION}/bin/* ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/ || cp /usr/lib/postgresql/*/bin/* ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}/
fi
;;
esac
- name: Archive binaries into platform-specific package
shell: bash
run: |
mkdir -p ./packages/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}
tar -czf ./packages/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }}.tar.gz -C ./raw/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/${{ matrix.arch }} .
- name: Upload to R2 with aws-cli
shell: bash
run: |
set -euo pipefail
pip install awscli --break-system-packages
if [[ -z "$R2_ENDPOINT" ]]; then
echo "R2_ENDPOINT is empty. Skipping upload."
exit 1
fi
export AWS_ACCESS_KEY_ID="$R2_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="$R2_SECRET_ACCESS_KEY"
export AWS_DEFAULT_REGION="auto"
aws s3 cp \
./packages/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/ \
s3://$R2_BUCKET/${DATABASE}/${DB_MAJOR_VERSION}/${{ matrix.platform }}/ \
--recursive \
--endpoint-url "$R2_ENDPOINT"