Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
chore(litestream): add docker builds for litestream
Browse files Browse the repository at this point in the history
Litestream will be better at snapshotting our sqlite database to s3. The service is currently struggling as the DB gets larger
  • Loading branch information
dtfiedler committed May 7, 2024
1 parent 2e66fd7 commit ba20500
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/litestream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Node.js CI

# TODO: change to only in main and for litestream changes
on: [push]
jobs:
push:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
checks: write
packages: write
steps:
- uses: actions/checkout@v4
# Build and push container image to GCR (only on main branch)
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push container image to GitHub Container Registry
uses: docker/build-push-action@v4
with:
push: true
tags: |
ghcr.io/ar-io/arns-litestream:latest
ghcr.io/ar-io/arns-litestream:${{ github.sha }}
20 changes: 20 additions & 0 deletions litestream/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Start with a standard Ubuntu base image
FROM ubuntu:20.04 as builder

# Install curl and other necessary tools
RUN apt-get update && apt-get install -y curl

# Download and install ytt
RUN curl -L https://github.com/vmware-tanzu/carvel-ytt/releases/download/v0.44.1/ytt-linux-amd64 > /usr/local/bin/ytt \
&& chmod 755 /usr/local/bin/ytt

FROM litestream/litestream:latest

COPY --from=builder /usr/local/bin/ytt /usr/local/bin/ytt

COPY litestream.template.yaml .
COPY docker-entrypoint.sh .

RUN chmod 755 /docker-entrypoint.sh

ENTRYPOINT [ "./docker-entrypoint.sh" ]
7 changes: 7 additions & 0 deletions litestream/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
set -e

# Update env vars
ytt --data-values-env TVAL -f /litestream.template.yaml > /litestream.yml

/usr/local/bin/litestream replicate -config /litestream.yml
9 changes: 9 additions & 0 deletions litestream/litestream.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#@ load("@ytt:data", "data")

dbs:
- path: #@ data.values.LOCAL_DB_PATH + "/state.db"
replicas:
- url: #@ data.values.S3_BUCKET_PATH
- path: #@ data.values.LOCAL_DB_PATH + "/contract.db"
replicas:
- url: #@ data.values.S3_BUCKET_PATH

0 comments on commit ba20500

Please sign in to comment.