Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deployment instructions for Google Cloud Run #135

Merged
merged 9 commits into from Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -141,6 +141,7 @@ LogPaste is easy to deploy to cloud services. Here are some places it works well

* [fly.io](docs/deployment/fly.io.md) (recommended)
* [Heroku](docs/deployment/heroku.md)
* [Google Cloud Run](docs/deployment/cloud-run.md)
* [Amazon LightSail](docs/deployment/lightsail.md)

## Further reading
Expand Down
108 changes: 108 additions & 0 deletions docs/deployment/cloud-run.md
@@ -0,0 +1,108 @@
# Deploy LogPaste to Google Cloud Run

TODO: Finish this, still a work in progress.

## Requirements

* gcloud SDK

## Set variables

```bash
GCP_PROJECT="your-gcp-project" # Replace with your GCP project ID
GCS_BUCKET="your-logpaste-bucket" # Replace with your bucket name
GCP_REGION="us-east1" # Replace with your desired GCP region
```

### Authenticate

You need to authenticate gcloud and configure docker to push to Google Container Registry.

```bash
gcloud auth login && \
gcloud auth configure-docker
```

### Specify GCP Project

```bash
gcloud config set project "${GCP_PROJECT}"
```

### Enable services

Your GCP project will need the [Cloud Run API](https://cloud.google.com/run/docs/reference/rest) enabled, so ensure your project enables this API:

```bash
gcloud services enable run.googleapis.com
```

### Create a Google Cloud Storage bucket

If you haven't already created the GCS bucket to provide LogPaste's persistent storage, create it with the command below:

```bash
gsutil mb "gs://${GCS_BUCKET}"
```

## Push to Google Container Registry

Cloud Run can't run Docker images from external image repositories, so next you'll copy the official LogPaste image to Google Container Registry:

```bash
LOGPASTE_VERSION="mtlynch/logpaste:latest" # LogPaste version on DockerHub
LOGPASTE_GCR_TAG="logpaste" # Change to whatever name you prefer
mtlynch marked this conversation as resolved.
Show resolved Hide resolved
LOGPASTE_GCR_URL="gcr.io/${GCP_PROJECT}/${LOGPASTE_GCR_TAG}"
```

```bash
docker pull "${LOGPASTE_VERSION}" && \
docker tag "${LOGPASTE_VERSION}" "${LOGPASTE_GCR_URL}" && \
docker push "${LOGPASTE_GCR_URL}"
```

## Deploy

Finally, it's time to deploy your image to Cloud Run.

```bash
GCR_SERVICE_NAME="logpaste"
gcloud beta run deploy \
"${GCR_SERVICE_NAME}" \
--image "${LOGPASTE_GCR_URL}" \
--set-env-vars "DB_REPLICA_URL=gcs://${GCS_BUCKET}/db" \
--allow-unauthenticated \
--region "${GCP_REGION}" \
--execution-environment gen2 \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that I assumed litestream would work best in second generation, but it might also just work with the default (gen1)

--no-cpu-throttling
```

If the deploy is successful, you'll see a message like the following:

```text
Service [logpaste] revision [logpaste-00002-cos] has been deployed and is serving 100 percent of traffic.
Service URL: https://logpaste-abc123-ue.a.run.app
```

Your LogPaste instance will serve at the URL listed next to "Service URL."

On Cloud Run, you'll notice that LogPaste shuts down a few seconds after each request. This is normal. It's persisting all of its data in Google Cloud Storage, and it will start up again upon the next HTTP request it receives with all the same data.
mtlynch marked this conversation as resolved.
Show resolved Hide resolved

mtlynch marked this conversation as resolved.
Show resolved Hide resolved
Thanks to [Steren Giannini](https://github.com/steren) from the Google Cloud Run team for his help with these instructions.

mtlynch marked this conversation as resolved.
Show resolved Hide resolved
## Set custom domain (optional)

You'll need to [verify ownership](https://cloud.google.com/run/docs/mapping-custom-domains#command-line) first.

```bash
CUSTOM_DOMAIN="logpaste.example.com"
```

```bash
gcloud beta run domain-mappings create \
--service "${GCR_SERVICE_NAME}" \
--domain "${CUSTOM_DOMAIN}" \
--region "${GCP_REGION}"
```

The command will show you a DNS record to add to your DNS. When you add the record, you'll be able to access the Cloud Run instance from your custom domain.