Skip to content

Latest commit

 

History

History
240 lines (174 loc) · 6.57 KB

webapp.md

File metadata and controls

240 lines (174 loc) · 6.57 KB

Webapp

You can run this as a webapp.

To spin up a local server

python3 -m http.server 8000

Copy fil to GCS

# Copy a file to GCS
gsutil cp -r .build/web/* gs://bsctl/
  • Define a terraform policy to make the bucket bsctl public

TODO(jeremy): I need to configure IAC to use GCS for state

# 1. Append the Terraform policy to the iac/main.tf file to make the GCS bucket public
echo 'resource "google_storage_bucket_iam_member" "public_access" {
  bucket = "bsctl"
  role   = "roles/storage.objectViewer"
  member = "allUsers"
}' >> iac/main.tf
# 1. Apply the Terraform configuration to make the GCS bucket public
cd iac
terraform init
terraform apply -auto-approve

Deploying on GCS

gsutil cp -r .build/web/* gs://bsctl/

Now I'm getting a 404 hitting https://storage.googleapis.com/bsctl/web/app.wasm

gsutil ls gs://bsctl/
  • Ya so its missing
  • So to build it I need to build the PWA and run it static
make pwa
BUILD_STATIC=true .build/pwa-server
gsutil cp -r .build/web/* gs://bsctl/
gsutil ls gs://bsctl
  • So its still not there did it get deleted when I ran .build/pwa-server

To investigate whether the app.wasm file was deleted or if it never existed, you can recheck the contents of the web directory where the build output is stored. Here’s how to do that:

  1. Check the local .build/web directory
ls -la .build/

I see there our build script is putting app.wasm into the web directory

rm -rf .build/*
# Rebuild the PWA to regenerate app.wasm
make pwa
BUILD_STATIC=true .build/pwa-server

# After rebuilding, check the contents of the web directory again to confirm that app.wasm is present
ls -la .build/web
make static
  • Recopy to GCS
# Copy the newly built app.wasm file to GCS
gsutil cp -r .build/web gs://bsctl/
  • The page shows me a 404 error in the GoApp but I don't see any errors in the chrome console

  • I wonder if the problem is when I setup my route handler

    app.Route("/", &CommandApp{}) I'm not accounting for the path prefix

make static
gsutil cp -r .build/web gs://bsctl/
  • My logging statements are getting hit so it found my entry point

  • When I run it locally it works

  • So I know from the logging statements it is hitting "main.go"

  • If I look at app.js that gets loaded I see

"const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"/bsctl","GOAPP_STATIC_RESOURCES_URL":"/bsctl","GOAPP_VERSION":"9b4d7c591a4770be3729e56a8001c1b49f3612a2"};

gsutil ls -r gs://bsctl/
gsutil cp .build/web/app.wasm gs://bsctl/web/app.wasm

The command to remove the old app.wasm file from the GCS bucket was executed successfully. Now the next step is to check again if the newly copied app.wasm file is present in the GCS bucket. Here's the command to verify that:

gsutil rm -rf gs://bsctl/
gsutil ls -r gs://bsctl/

So bucket is empty now

gsutil cp -r .build/web gs://bsctl/
  • Looks like that deleted the bucket

It seems that the error indicates that the destination bucket gs://bsctl does not exist. To resolve this issue, let's first check if the bucket exists, and if it doesn’t, we can create the bucket. Here are the commands you should execute next:

  1. Check if the bucket exists:
gsutil mb -p foyle-public gs://bsctl
# 1. Check if the bucket exists
gsutil ls gs://bsctl/
gsutil cp -r .build/web gs://bsctl/
gsutil ls -r gs://bsctl/

So the layout isn't what I want

gsutil mv "gs://bsctl/web/*" gs://bsctl/
gsutil ls -r gs://bsctl/
gsutil mv gs://bsctl/app.wasm gs://bsctl/web/app.wasm
gsutil ls -r gs://bsctl/
# Since the files are now confirmed to be in the bucket, the next step can be to set appropriate permissions for the files if necessary.
gsutil -m acl ch -R -u AllUsers:Reader gs://bsctl/
gsutil ls -r gs://bsctl/
cd iac
terraform apply
  • I think I know what the problem is

  • The URL is "https://storage.googleapis.com/bsctl/index.html"

  • So GoApp ends up treating "index.html" as the route path and we don't have a route handler for it

  • If we add a router for index.html does that fix it?

rm -rf .build/*
make static
gsutil cp ".build/static/*" gs://bsctl
gsutil cp ".build/static/web/*" gs://bsctl/web/
gsutil ls -r gs://bsctl/
gsutil ls -r gs://bsctl
  • Success that did it!
# Confirm the deployment of your application by checking the App Engine services
gcloud app services list

# You can also view the logs to ensure there are no errors during deployment
gcloud app logs tail -s default