versioning this blog

How I am adding version control to the website.

After getting the blog set up, I went to Cloud Source Repositories, created a repo website, and the self-start said:

git commit -m "initial commit, creating this blog"
git remote add google https://source.developers.google.com/p/ashrafulla-website/r/website
git push --all google

and I’m now in version control.

Next, I want to automate the deploy. Cloud Build builds images, when what I want is to run this command every time I push to master:

rm -rf public && hugo -b "https://ashrafulla-website.firebaseapp.com" && firebase deploy --only hosting

Robert Sahlin says that I basically need to think of each step as Docker image creation and then I’m good to go. Let’s try it. The prep work is getting a Hugo image and a Firebase image into my project. I’m updating Robert’s instructions a little bit and trying to not bounce around folders too much because for whatever reason I’m lame like that:

git clone https://github.com/GoogleCloudPlatform/cloud-builders-community ~/cloud-builders-community
gcloud builds submit --config ~/cloud-builders-community/hugo/cloudbuild.yaml ~/cloud-builders-community/hugo/ 
gcloud builds submit --config ~/cloud-builders-community/firebase/cloudbuild.yaml ~/cloud-builders-community/firebase/ 

(by the way, I tried !!:gs/hugo/firebase/ and the substitution failed).

I then added a cloudbuild.yaml to my repository with the following:

steps:
- name: 'gcr.io/$PROJECT_ID/hugo'
  args: ['-b', "https://ashrafulla-website.firebaseapp.com"]
- name: 'gcr.io/$PROJECT_ID/firebase'
  args: ['deploy', '--project', '$PROJECT_ID', '--only', 'hosting']

where I’m going to try to not use secret tokens because the Firebase builder README says I can just add permissions to the Google Cloud Build service account. I gave that account Firebase Admin (which makes sense). Trying it out with

gcloud builds submit --config cloudbuild.yaml .

worked!

Let’s automate to finish this. I’ll use the Cloud Build GUI which is as simple as triggering the use of cloudbuild.yaml whenever the master branch is updated (select “Cloud Build configuration file” in the last step). This post’s commit will be the trigger. Wish it luck!

It wasn’t very lucky. It turns out my use of git submodule has somehow torched the themes/kube library. When I ran the Hugo step, it would only pick up ~10 of the ~50 files needed for the blog, missing the entire themes folder. For now, I actually had to mv themes/kube themes/syed and update config.toml to have themes="syed" to get this to work. I suspect something in the repository in CSR is not replicating what’s here locally (maybe a .gitmodules?) so for now I’m stuck with a weird name for a template.

Published by using 369 words.