- Open the console https://console.cloud.google.com
- If you haven't already, setup your Cloud billing account
- From the drop down at the top of the screen, create new project for your client, e.g.
my-client - Make a note of the
Project numberon the project Home screen (Craft refers to this as theProject ID) - In the sidebar go to APIs & Services > Credentials, click the
+ Create credentialsbutton and choose theService Accounttype
- Set account name to
craft-cmsor similar - Set role to
Owner - Save
- Click on the newly created service account email to edit it, then click the
Keystab and clickAdd key>Create new keyand select theJSONformat - The key will automatically download to your computer as a text file. Save this and the service account email shown on screen (e.g.
[email protected]) in a safe place. - Go to
Storagein the sidebar and create a new bucket in the project with a logical name, e.g.my-client-assets. Choose a multi-region close to your client's users and use theStandardstorage class. Set bucket access toFine grained(per object) NOTUniform(per bucket). Craft will only work with the per-object permissions model. - On the permissions tab for the new bucket, click
Addfor each of the following:- type
allUsersand choose theStorage Object Viewerrole. Click 'Yes' to the pop-up warning you that this will make your bucket public. - type in the service account email that you created earlier e.g.
[email protected]and add roleStorage Admin(underCloud Storage>Storage Admin).
- type
-
Click the button at the top right of the screen
Activate Cloud Shell -
Create CORS config file with these commands (replacing with your desired config and bucket name):
echo ' [{"origin": ["*"],"responseHeader": ["Content-Type"],"method": ["GET", "HEAD"],"maxAgeSeconds": 3600}]' > cors-config.json gsutil cors set cors-config.json gs://my-client-assets -
Verify that the CORS config was applied correctly:
gsutil cors get gs://my-client-assets
You should consider creating additonal buckets for your different environments (e.g. staging) so that they do not access the production bucket directly. At least one bucket should also be created for backups. While the multi-regional bucket type is highly available by design and unlikely to lose your data, it is still possible that a bucket could become corrupted by user error, or due to a bug with Craft's use of the Cloud Storage API.
You can use Google Cloud Storage Transfer facility to syncronize these additional buckets with your production bucket, and optionally schedule transfers so that they occur automatically. Scheduled automated transfers are currently limited to being run daily, but these can be 'chained' (backup the previous day's backup, and so on) to give you rolling snapshots of each day going back 7 days or more.
Alternatively, you can trigger a rsync between two buckets with the gsutil command line tool. When triggered by a CRON you can implement a custom backup strategy. For example, to make mybucket2 (destination) identical to mybucket1 (source):
gsutil rsync -d -r gs://mybucket1 gs://mybucket2
- Install the Google Cloud Storage plugin
- Go to
Settings > Assetsand click theNew Volumebutton - Choose the
Google Cloud Storagevolume type, enter theProject IDyou saved earlier and paste in the contents of yourService Account Keyin theContents of the access key filefield. - Select the bucket you created earlier (and note that you can switch between the synchronized buckets in your account at any time - thus for your staging environment select the staging bucket, for example).
- If you want to have multiple volumes that use the same bucket (recommended), set a subfolder path. You can create this subfolder manually in the Google Cloud Storage interface.