Skip to content

Commit

Permalink
Build BemiDB binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Nov 6, 2024
1 parent 2ebc9d2 commit 726f485
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.env
/benchmark/tpch-kit
/benchmark/data/*.tbl
/build
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

### v0.1.0 - 2024-10-06

- Create initial version
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG PLATFORM
ARG GOOS
ARG GOARCH

FROM --platform=$PLATFORM golang:1.23

WORKDIR /app

COPY src/go.mod src/go.sum ./
RUN go mod download

COPY src/ .
RUN CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH go build -o /app/bemidb
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ install:
up:
devbox run --env-file .env "cd src && go run ."

.PHONY: build
build:
devbox run "go build -C src -o ../bemidb"
rm -rf build/bemidb-* && \
devbox run "go build -C src -o ../build/bemidb-darwin-arm64" && \
./scripts/build.sh

sync:
devbox run --env-file .env "cd src && go run . sync"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ and allows running complex queries using the Postgres-compatible analytical quer
Install BemiDB:

```sh
curl -sSL https://api.bemidb.com/install.sh | bash
curl -sSL https://raw.githubusercontent.com/BemiHQ/BemiDB/refs/heads/main/scripts/install.sh | bash
```

Sync data from a Postgres database:
Expand Down
Empty file added build/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

platforms=("linux/amd64" "linux/arm64")

for platform in "${platforms[@]}"
do
os="${platform%/*}"
arch="${platform#*/}"
echo "Building bemidb for $os/$arch"

docker buildx build \
--build-arg PLATFORM=$platform \
--build-arg GOOS=$os \
--build-arg GOARCH="$arch" \
-t bemidb-build:$os-$arch .

docker create --name temp-container bemidb-build:$os-$arch
docker cp temp-container:/app/bemidb ./build/bemidb-$os-$arch
docker rm temp-container
done
32 changes: 32 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

VERSION="0.1.0"

# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

# Map architecture to Go naming convention
case $ARCH in
x86_64|amd64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac

# Set the download URL and binary name
BINARY_NAME="bemidb-${OS}-${ARCH}"
DOWNLOAD_URL="https://github.com/BemiHQ/BemiDB/releases/download/v$VERSION/$BINARY_NAME"

# Download the binary
echo "Downloading $DOWNLOAD_URL..."
curl -L "$DOWNLOAD_URL" -o ./bemidb

# Make the binary executable
chmod +x ./bemidb
5 changes: 5 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package main

import (
"flag"
"fmt"
)

const VERSION = "0.1.0"

func main() {
flag.Parse()
config := LoadConfig()
Expand All @@ -20,6 +23,8 @@ func main() {
start(config)
case "sync":
syncFromPg(config)
case "version":
fmt.Println("BemiDB version:", VERSION)
default:
panic("Unknown command: " + command)
}
Expand Down

0 comments on commit 726f485

Please sign in to comment.