Run BaGetter on Google Cloud Platform
This page is a work in progress!
We're open source and accept contributions! Fork us on GitHub.
Before you begin, you should decide which AppEngine region you will use. For best performance, Cloud Storage and Cloud SQL should be located in the same region as your AppEngine deployment.
Google Cloud Storage
Packages can be stored in Google Cloud Storage.
Setup
Follow the instructions in Using Cloud Storage to create a bucket.
Configuration
NOTE: If you plan to use AppEngine, skip this part and follow the AppEngine instructions below.
Set up a service account, create and download a key as JSON file. Set the GOOGLE_APPLICATION_CREDENTIALS
environment variable to the path to the JSON file you downloaded. The file should contain something like this:
{
"type": "service_account",
"project_id": "your_project",
"private_key_id": "6950mvh3690mg3h90jg3986vgm",
"private_key": "-----BEGIN PRIVATE KEY-----\hriv eohgrup4nhg8594nhvpog59p4w5...",
"client_email": "your-service-account@your_project.iam.gserviceaccount.com",
"client_id": "49826518658461496",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-service-account%40your_project.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}
Configure BaGetter to use Google Cloud Storage by updating the appsettings.json
file:
{
...
"Storage": {
"Type": "GoogleCloud",
"BucketName": "your-gcs-bucket"
},
...
}
Or set the Storage__Type
and Storage__BucketName
environment variables in your deployment (i.e. AppEngine project) accordingly.
Google Cloud SQL
- Follow the instructions in Using Cloud SQL to create a (for example) 2nd Gen MySQL 5.7 Google Cloud SQL instance. The default options should work well.
- Create a database named
bagetter
. This can be done through the Google Cloud Console. Useutf8mb4
as the Character set. - Follow Configuring SSL/TLS to create a client certificate. Download the three files it creates.
- Convert the PEM to a PFX by running
openssl pkcs12 -inkey client-key.pem -in client-cert.pem -export -out client.pfx
- One way to obtain OpenSSL on Windows is to install Git Bash.
- Configure BaGetter to use Google Cloud SQL by updating the
appsettings.json
file:
{
...
"Database": {
"Type": "MySql",
"ConnectionString": "Server=YOURIP;User Id=root;Password=***;Database=bagetter;CertificateFile=C:\\Path\\To\\client.pfx;CACertificateFile=C:\\Path\\To\\server-ca.pem;SSL Mode=VerifyCA"
},
...
}
- Create the tables by running
dotnet ef database update --context MySqlContext --project src\BaGetter
Google AppEngine
BaGetter can be hosted in Google AppEngine. See here for a tutorial on how to create a new AppEngine project.
Create a app.yaml
file to publish the Docker container built by the Dockerfile in this repo. In the template
below, make the following replacements:
PROJECT
- your GCP project, as returned bygcloud config get-value project
REGION
-- the GCP region your Google Cloud SQL database is in, e.g.,us-central1
orus-west2
DBINSTANCE
-- the name of your Google Cloud SQL database instanceDBNAME
-- the name of the BaGetter database on that instance (e.g.,bagetter
in the instructions above)PASSWORD
-- the password for the database root userBUCKETNAME
-- the name of the Google Cloud Storage Bucket configured above
runtime: custom
env: flex
# The settings below are to reduce costs during testing and are not necessarily
# appropriate for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/dotnet/configuring-your-app-with-app-yaml
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
beta_settings:
cloud_sql_instances: "PROJECT:REGION:DBINSTANCE"
env_variables:
Database__Type: "MySql"
Database__ConnectionString: "Server=/cloudsql/PROJECT:REGION:DBINSTANCE;User Id=root;Password=PASSWORD;Database=DBNAME;SslMode=None"
Storage__Type: "GoogleCloud"
Storage__BucketName: "BUCKETNAME"
Search__Type: "Database"
ASPNETCORE_URLS: "http://0.0.0.0:8080"
To publish the application, run gcloud app deploy
.