HanG321 Blog

LikeCoin WordPress Plugin

原本諗住加個WordPress Plugin 呃吓like coin,等將來可以用黎派like。點知原來個website係會俾人登出嚟 😛

咁唯有整番個website靚仔小小啦。

呢個site 係GCP free tier (每個月$0.x egress only,  爽啊),原本個Base image 係 Debian 8,上個月discontinue support, 所以要更新到 Debian 9. 今次就試下由Apache轉去Nginx,睇下Performance 會唔會有改善。技術文下次再寫。

更新完 Compute Engine VM, WordPress, Themes, Plugin … etc, 奇怪個主頁顯示唔到LikeCoin Widget, 最後發現原來係個Theme Home Page setting 嘅問題,唔係page又唔係post type。然後就去睇下個widget 其實係 iframe, 咁我自己加返條Link就會出到。

https://button.like.co/in/embed/<YOUR_USERNAME>/button?referrer=https%3A%2F%2F<YOUR_DOMAINNAME>

Provision the Qwiklabs environment

Task 1:

+-----------------+-----------------------------------+
|      FIELD      |               VALUE               |
+-----------------+-----------------------------------+
| Billing Image   | billing-staging-api:0.1           |
| Billing Service | public-billing-service            |
| Authentication  | unauthenticated                   |
| Code            | pet-theory/lab07/unit-api-billing |
+-----------------+-----------------------------------+

 

cd ~/<CODE>
gcloud builds submit \
--tag gcr.io/$GOOGLE_CLOUD_PROJECT/<BILLING_IMAGE>

 

gcloud run deploy <SERVICE> \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/<BILLING_IMAGE> \
--<AUTHENTICATED>

 

Task 2:

+----------------+-------------------------------------------+
|     FIELD      |                   VALUE                   |
+----------------+-------------------------------------------+
| Image Name     | frontend-staging:0.1                      |
| Service Name   | frontend-staging-service                  |
| Authentication | unauthenticated                           |
| Code           | pet-theory/lab07/staging-frontend-billing |
+----------------+-------------------------------------------+

 

Task 3:

+----------------+--------------------------------------+
|     FIELD      |                VALUE                 |
+----------------+--------------------------------------+
| Image Name     | billing-staging-api:0.2              |
| Service Name   | private-billing-service              |
| Authentication | authenticated                        |
| Code           | pet-theory/lab07/staging-api-billing |
+----------------+--------------------------------------+

 

cd ~/<CODE>
gcloud beta run services delete public-billing-service

 

BILLING_SERVICE=private-billing-service
BILLING_URL=$(gcloud run services describe $BILLING_SERVICE \
  --format "value(status.URL)")
curl -X get -H "Authorization: Bearer $(gcloud auth print-identity-token)" $BILLING_URL

 

Task 4:

+-----------------+---------------------------+
|      FIELD      |           VALUE           |
+-----------------+---------------------------+
| Service Account | billing-service-sa        |
| Display Name    | Billing Service Cloud Run |
+-----------------+---------------------------+

 

gcloud iam service-accounts create <SERVICE_ACOUNT> --display-name "<DISPLAY_NAME>"

 

Task 5:

+-----------------+-----------------------------------+
|      FIELD      |               VALUE               |
+-----------------+-----------------------------------+
| Image Name      | billing-prod-api:0.1              |
| Service Name    | billing-prod-service              |
| Authentication  | authenticated                     |
| Code            | pet-theory/lab07/prod-api-billing |
| Service Account | billing-service-sa                |
+-----------------+-----------------------------------+

 

cd ~/<CODE>
## similar to task 3 build and deploy command above

 

gcloud run services add-iam-policy-binding <SERVICE_NAME> \
  --member=serviceAccount:<SERVICE_ACCOUNT>@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com \
  --role=roles/run.invoker

 

PROD_BILLING_SERVICE=private-billing-servicePROD_BILLING_URL=$(gcloud run services \
    describe $PROD_BILLING_SERVICE \
    --format "value(status.URL)")
curl -X get -H "Authorization: Bearer \
    $(gcloud auth print-identity-token)" \
    $PROD_BILLING_URL

 

Task 6:

+-----------------+-----------------------------------+
|      FIELD      |               VALUE               |
+-----------------+-----------------------------------+
| Service Account | frontend-service-sa               |
| Display Name    | Billing Service Cloud Run Invoker |
+-----------------+-----------------------------------+

 

Task 7:

+-----------------+----------------------------------------+
|      FIELD      |                 VALUE                  |
+-----------------+----------------------------------------+
| Image Name      | frontend-prod:0.1                      |
| Service Name    | frontend-prod-service                  |
| Authentication  | unauthenticated                        |
| Code            | pet-theory/lab07/prod-frontend-billing |
| Service Account | frontend-service-sa                    |
+-----------------+----------------------------------------+

 

cd ~/<CODE>
## similar to task 5 build and deploy command above

 

gcloud run services add-iam-policy-binding <SERVICE_NAME> \
  --member=serviceAccount:<SERVICE_ACCOUNT>@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com \
  --role=roles/run.invoker

 

Congratulations

This blog post is recording my journey on proof of concept development on ionic 4 capacitor & PWA development in December 2018, just note down some obstacles I faced or founding in the journey, and this is not a tutorial.

Although Progressive Web Apps (PWA) are installable without app store, as of today business requirement may still need the distribute channel via app store. With ionic (UI) and Cordova framework, one single code base can serve native apps and web apps together.

ionic 4

Capacitor or Stencil

Capacitor is still in Release Candidate in Dec 2018, and 1.0 production in 2019. Integrate with Angular. Cross platform: iOS, android, Web, Electron (win & macOS)

Stencil: web component (similar to ploymer), reusable, independent (angular, react, vue)

selected Capacitor as per requirement.

Toolings: Intellij Idea (as subscribed), or Visual Studio Code (free)

Installation

follow the official documentation.  run $ ng build  to create /www folder

Creation on iOS & android projects is smooth and easy. ionic team really did a great job there. However, PWA isn’t that user-friendly. npm install @ionic/pwa-elements only adding UI component.

PWA services worker

angular-worker: basic usage, npm install -g @angular/cli ; ng add @angular/pwa  ngsw-config.json.
workbox: advance usage. pre-caching, background sync …etc

very difficult to setup, due to angular builder. Need to manually add “glob”: “workbox-<Component>.<dev|prod>.js” to angular.json . See https://golb.hplar.ch/2018/06/workbox-serviceworker-in-angular-project.html for more details

Development

$ ionic server –> live reload on source folder, so PWA doesn’t work as pre-caching & routing info in /www (build) folder, not src/service-worker.js

edit package.json, add “dist”: “ng build && workbox injectManifest”  Then run $ npm run dist  to build.  Then run $ npx cap serve 

alternatively, http-server can be used, that will use /www file. e.g. http-server www -c-1 -o -a -S localhost -p 8200

HTTPS: PWA works on localhost, 192.168.x.x . Others need HTTPS. It won’t work on non-SSL, took some time to find out, as office wifi is not Class C network. Yet it runs okay at home.

 

 

 

1234...30...

 

Exit mobile version