GithubHelp home page GithubHelp logo

steren / litestream-cloud-run-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benbjohnson/litestream-docker-example

28.0 1.0 2.0 26 KB

An example of using Litestream within Cloud Run

License: Apache License 2.0

Shell 10.96% Go 49.27% Dockerfile 39.77%

litestream-cloud-run-example's Introduction

Litestream & Cloud Run example

Important: Litestream currently does not work well on automatically scaled platforms like Cloud Run because it expects a maximum of one instance.

This repository provides an example of running a Go application in the same container as Litestream by using the built-in subprocess execution. This allows developers to release their SQLite-based application and provide replication in a single container.

Usage

Prerequisites

  • Create a Google Cloud project, write down its project ID.
  • Create a Cloud Storage bucket in a single region, for example us-central1, and write down the bucket name.

Build & deploy the sample to Cloud Run

Clone this repository and navigate to the cloned location.

Then build and deploy the application with the following command:

gcloud beta run deploy litestream-example \
  --source .  \
  --set-env-vars REPLICA_URL=gcs://BUCKET_NAME/database \
  --max-instances 1 \
  --execution-environment gen2 \
  --no-cpu-throttling \
  --allow-unauthenticated \
  --region REGION \
  --project PROJECT_ID

Replace:

  • BUCKET_NAME with your Cloud Storage bucket name
  • REGION with the same region where you created the bucket, for example us-central1
  • PROJECT_ID with your Google Cloud project ID.

When the deployment completes, open the .run.app URL of the Cloud Run service.

The command has built the source code into a container using Cloud Build then deployed it to Cloud Run.

The command:

  • sets the REPLICA_URL environment variable to point at the Cloud Storage URL (note that Livestream expects gcs:// instead of gs://, this will change in the next Litestream release)
  • forces a maximum of one instance because Litestream isn't compatible with multiple servers
  • uses the Cloud Run second generation execution environment for better performance
  • asks for the CPU to always be allocated (evenoutside of requests processing)
  • makes the service publicly accessible by allowing unauthenticated invocations

Additional security

Containers deployed to Cloud Run run with an identity, by default, it is the "Default Compute Service Account", which has read/write access to all Cloud Storage buckets in the same project as well as a lot of other permissions on resources in the same project. For additional security, it is recommended to create a dedicated Servie Account with read/write permission on the Cloud Storage bucket and then use this service account as the identity of the Cloud Run service. Read more here

litestream-cloud-run-example's People

Contributors

benbjohnson avatar steren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.