Skip to content

Commit

Permalink
Add litestream to R2
Browse files Browse the repository at this point in the history
  • Loading branch information
aleda145 committed Aug 5, 2022
1 parent 2ead137 commit 54cca80
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
8 changes: 4 additions & 4 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ COPY ./pocketbase ./pocketbase
RUN go build -o /pocketbase pocketbase/main.go
#checkov:skip=CKV_DOCKER_4: Ensure that COPY is used instead of ADD in Dockerfiles
# Because we want to add from a remote URL, and there is no reason not to trust benbjohnson
# ADD https://github.com/benbjohnson/litestream/releases/download/v0.3.8/litestream-v0.3.8-linux-amd64-static.tar.gz /tmp/litestream.tar.gz
# RUN tar -C /usr/local/bin -xzf /tmp/litestream.tar.gz
ADD https://github.com/benbjohnson/litestream/releases/download/v0.3.9/litestream-v0.3.9-linux-amd64.tar.gz /tmp/litestream.tar.gz
RUN tar -C /usr/local/bin -xzf /tmp/litestream.tar.gz

# deploy
FROM debian:buster-slim
Expand All @@ -24,8 +24,8 @@ RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -
WORKDIR /app

COPY --from=builder /pocketbase /pocketbase
# COPY --from=builder /usr/local/bin/litestream /usr/local/bin/litestream
# COPY litestream.yml /etc/litestream.yml
COPY --from=builder /usr/local/bin/litestream /usr/local/bin/litestream
COPY litestream.yml /etc/litestream.yml

COPY run.sh .

Expand Down
8 changes: 8 additions & 0 deletions backend/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docker run -it --publish 8090:8090 \
-e R2_BUCKET="${R2_BUCKET}" \
-e R2_ACCESS_KEY="${R2_ACCESS_KEY}" \
-e R2_SECRET_KEY="${R2_SECRET_KEY}" \
-e R2_DATA_PATH="${R2_DATA_PATH}" \
-e R2_LOGS_PATH="${R2_LOGS_PATH}" \
-e R2_URL="${R2_URL}" \
pocketbase:latest --rm
17 changes: 17 additions & 0 deletions backend/litestream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dbs:
- path: /pb_data/data.db
replicas:
- type: s3
endpoint: ${R2_URL}
path: ${R2_DATA_PATH}
bucket: ${R2_BUCKET}
access-key-id: ${R2_ACCESS_KEY}
secret-access-key: ${R2_SECRET_KEY}
- path: /pb_data/logs.db
replicas:
- type: s3
endpoint: ${R2_URL}
path: ${R2_LOGS_PATH}
bucket: ${R2_BUCKET}
access-key-id: ${R2_ACCESS_KEY}
secret-access-key: ${R2_SECRET_KEY}
15 changes: 8 additions & 7 deletions backend/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
echo "Check diskspace on VM"
df -h

# echo "litestream version"
# litestream version
echo "litestream version"
litestream version

# # Docker entry point for image will decode the base64 secret and put it into the GOOGLE_APPLICATION_CREDENTIALS PATH that has been specified
# # this has to be done before litestream starts!
Expand All @@ -17,9 +17,10 @@ df -h
# echo "set gcp key"
# echo "$GCP_KEY" | base64 -d > "$GOOGLE_APPLICATION_CREDENTIALS"

# echo "Restore db if exists"
# litestream restore -if-replica-exists /app/production.db
echo "Restore db if exists"
litestream restore -if-replica-exists /pb_data/data.db
litestream restore -if-replica-exists /pb_data/logs.db
echo "Restored successfully"

# echo "replicate!"
# exec litestream replicate -exec "/api"
/pocketbase serve --http 0.0.0.0:8090
echo "replicate!"
exec litestream replicate -exec "/pocketbase serve --http 0.0.0.0:8090"

0 comments on commit 54cca80

Please sign in to comment.