How to deploy to GCP cloud run == 1. [create a project](https://console.cloud.google.com/cloud-resource-manager?_ga=2.138452854.41327207.1591101760-1779772054.1591101760) 2. [install google sdk](https://cloud.google.com/sdk/docs/quickstart-windows) 3. [init sdk](https://cloud.google.com/sdk/docs/quickstart-windows#initialize_the_sdk) 4. [enable cloud run api](https://console.cloud.google.com/apis/library/run.googleapis.com?q=cloud%20run&id=68655bb7-6644-4f0c-9535-34e945d41173&project=serious-case-291704) 5. [enable cloud build api](https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com?q=cloud%20build&id=9472915e-c82c-4bef-8a6a-34c81e5aebcc&project=serious-case-291704) 6. set premission in IAM for *projectId@cloudbuild.gserviceaccount.com*![](https://i.imgur.com/VrVKO6N.png) ## C# [Ref](https://cloud.google.com/run/docs/quickstarts/build-and-deploy#c) 1. in your project directory, create [Dockerfile](https://cloud.google.com/run/docs/quickstarts/build-and-deploy#containerizing) 2. create `.dockerignore` ``` **/obj/ **/bin/ ``` 3. if your directory dont have `.gitignore`, copy `.dockerignore` and rename it to `.gcloudignore` 4. in `Program.cs`, set up `PORT environment variable` ``` c# public static IHostBuilder CreateHostBuilder(string[] args) { string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; string url = String.Concat("http://0.0.0.0:", port); return Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>().UseUrls(url); }); } ``` 6. open google skd, go to your project directory 7. type `gcloud builds submit --tag gcr.io/{projec id in GCP}/{project name}` to publish the application to docker image 8. if success, then type `gcloud run deploy --image gcr.io/{projec id in GCP}/{project name} --platform managed` to deploy and run 9. go to [container registry](https://cloud.google.com/container-registry) see if your app has been deployed 10. go to [cloud run console](https://cloud.google.com/run) to check if the app is running 11. click on your app, you will see the app url is there ## Vue js 1. `npm run build` your project 2. open google sdk and `cd` to `your project/dist` 3. create `Dockerfile` ``` FROM nginx:alpine COPY . /usr/share/nginx/html ``` 4. type `gcloud builds submit --tag gcr.io/{projec id in GCP}/{project name}` to publish the application to docker image 5. go to [container registry](https://cloud.google.com/container-registry) see if your app has been deployed 6. go to [cloud run console](https://cloud.google.com/run) and select your app 7. click `create service` 8. type service name, then click next 9. select your image 10. click `進階設定`, change **General** -> 容器通訊埠 from *8080* to **80** 11. click create and wait