Skip to content

Instantly share code, notes, and snippets.

@XavM
Last active December 9, 2020 14:13
Show Gist options
  • Save XavM/2a410ffea3fca1aa2727b200ed43ac5c to your computer and use it in GitHub Desktop.
Save XavM/2a410ffea3fca1aa2727b200ed43ac5c to your computer and use it in GitHub Desktop.
Build and Run dqlite on Alpine Linux

Build and Run dqlite on Alpine Linux

Node 1 (172.17.0.2)

Build

apk add raft-dev dqlite dqlite-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing
apk add sqlite-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
apk add musl-dev go git jq curl
cd /root
git clone https://github.com/canonical/go-dqlite.git
cd /root/go-dqlite
go install -tags libsqlite3 ./cmd/dqlite-demo

Run 1rst node

/root/go/bin/dqlite-demo --api 172.17.0.2:8001 --db 172.17.0.2:9001

Node 2 (172.17.0.3)

Reuse build on a second node (dqlite-demo has been cp to host /$someDir)

docker run -itv /$someDir:/shared alpine /bin/sh
apk add sqlite-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
apk add dqlite-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

Run 2nd node

/shared/dqlite-demo --api 172.17.0.3:8001 --db 172.17.0.3:9001 --join 172.17.0.2:9001

Test

curl -X PUT -d '{"val": 1}' http://172.17.0.2:8001/1
curl http://172.17.0.2:8001/1 # {"val": 1}
curl http://172.17.0.3:8001/1 # {"val": 1}
# Stop node 1 
curl http://172.17.0.3:8001/1 # {"val": 1}
curl -X PUT -d '{"val": 2}' http://172.17.0.3:8001/2
# re Start node 1 
curl http://172.17.0.2:8001/2 # {"val": 2}

dqlite shell client

Build

go install -tags libsqlite3 ./cmd/dqlite

Run

/root/go/bin/dqlite -s 172.17.0.2:9001 demo
  dqlite> .cluster
    2dc171858c3155be|172.17.0.2:9001|voter
    abdfb92ed87f28d7|172.17.0.3:9001|voter
    f5a9b88a043bbc7e|172.17.0.4:9001|voter
  dqlite> .leader
    172.17.0.2:9001  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment