Is it necessary to update firebase when you re-deploy a web app in cloud run, can you control what's removed from cache during re-deployment? - firebase-hosting

After deploying a web app with firebase + cloud run the firebase configurations usually don't change much.
Question 1
Is it advisable to update the cloud run container without doing a
re-deployment on firebase ?
What's the advisable way to update firebase with cloud run let's say don't want to lose cache already on firebase. According to firebase a re-deployment of the web app clears all CDN cache.
Question 2
Here is my situation
I have a web app hosted on cloud run + firebase whenever I do a re-deployment I want whatever is cached from my API's from CDN not to be cleared. The rest can be cleared.
Is there a way to control what's cleared from cache during
re-deployments ?
Here is my configurations
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ {
"source": "**",
"run": {
"serviceId": "my-site",
"region": "some-region"
}
} ],
"headers": [{
"source" : "**",
"headers" : [
{
"key" : "Cache-Control",
"value" : "max-age=31536000"
}
]
}]
}
}

Is it advisable to update the cloud run container without doing a re-deployment on firebase ?
Whenever you update the Cloud Run container, the changes will not be updated to the Firebase, if you want the changes to be updated to the Firebase hosting then you should consider deploying to the Firebase firebase deploy --only hosting.
Is there a way to control what's cleared from cache during
re-deployments ?
According to the doc
Any requested static content is automatically cached on the CDN. If
you redeploy your site's content, Firebase Hosting automatically
clears all your cached static content across the CDN until the next
request.
If you have dynamic content that you'll edit through an admin UI, for example. Be aware that the CDN cache will keep stale cache of that content until it expires.
For example: CDN caches /blog/some-post with s-maxage of 1 day. Even if you change the content of your post dynamically, the CDN will keep the CDN for 1 full day, until it expires and it gets requested again.

Related

Unable to make modifications to amplifyconfiguration.dart

Background
I have created a new flutter project and initialised amplify using amplify init then added an api using amplify add api
What am I trying to do?
I am trying to change my REST API from an authorizationType of AWS_IAM to API_KEY and I am following the instructions as described here: Amplify Flutter REST API
I manually change the amplifyconfiguration.dart file to change the authorizationType from AWS_IAM to API_KEY and specify my apiKey with the API key I setup via the AWS Console. I then execute a amplify push to push my changes to the cloud.
From
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"testrestapi": {
"endpointType": "REST",
"endpoint": "https://xxxxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev",
"region": "ap-southeast-2",
"authorizationType": "AWS_IAM"
}
}
}
}"
To
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"testrestapi": {
"endpointType": "REST",
"endpoint": "https://xxxxxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev",
"region": "ap-southeast-2",
"authorizationType": "API_KEY",
"apiKey":"<MY KEY>"
}
}
}
},"
Whats the problem?
After executing a amplify push command, the amplifyconfiguration.dart file reverts back to its original values.
Steps to reproduce
Create a new flutter project using flutter create
Initialise amplify via the amplify init command
Add an API via the amplify add api command
Open the project in an editor (eg Visual Studio Code), open amplifyconfiguration.dart and change the REST API details. Hit save.
Execute amplify push. The amplifyconfiguration.dart file will revert back to its original state.
How can I make changes to amplifyconfiguration.dart and make the changes persist? Alternatively how can I change my REST API fom the CLI as above? I have tried amplify update api but it does not allow me to change the authorizationType. The documentation states that I can make changes to the file manually but any changes dont seem to persist.
Any help would be greatly appreciated.
It's very easy, in the amplify console, go to the data tab and under the title (Data modeling) there is a gear symbol and a text that says: GraphQL API settings. Click and you can change the Default authorization mode option for the one you need. Then you update your project that you are working on.

How do I create additional buckets in Firebase Cloud Storage Emulator

I am trying to create additional storage buckets in the new Firebase Cloud Storage Emulator. I see no option in the EmulatorUI and have found no resources online. Is this even possible?
You can create buckets in the Firebase emulator by following these steps:
1 Setup deploy targets for storage.
firebase target:apply storage default myproject.appspot.com
firebase target:apply storage other other.appspot.com
2 Configure the firebase.json file
Change the storage section to an array that looks like this:
{
"storage": [
{
"target": "default",
"rules": "storage.default.rules"
},
{
"target": "other",
"rules": "storage.other.rules"
}
]
}
Note that the bucket won't be created on the emulator suite until you write something to it. Also you need to change your project to the blaze plan to configure multiple buckets on the firebase console.
This URL has more details on the configuration:
https://firebase.google.com/docs/cli/targets#set-up-deploy-target-storage-database
This documentation page also has information on how to handle multiple buckets with the sdk:
https://firebase.google.com/docs/storage/web/start#use_multiple_storage_buckets

Display images stored on Firebase Storage from Flutter Web [duplicate]

This question already has answers here:
Firebase Storage and Access-Control-Allow-Origin
(5 answers)
Closed 1 year ago.
I am unable to retrieve images stored on Firebase storage on Flutter Web.
Accompanied by:
Access to XMLHttpRequest at <firebase-storage-photo-url> has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
According to Google Cloud Docs
Cross Origin Resource Sharing (CORS) allows interactions between resources from different origins, something that is normally prohibited in order to prevent malicious behavior.
Following the firebase docs, here is how to solve this:
Download gsutil, a Google Cloud CLI, instructions on how to install can be found here.
Create cors.json file with the following content:
[
{
"origin": ["*"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
Now use the CLI to deploy cors.json rules using this command:
gsutil cors set cors.json gs://<your-cloud-storage-bucket>
You can find the path for your Firebase storage bucket in Firebase console under Storage feature.

How to change credentials for a given service in Cloud Foundry

I would like to know how (and if it's possible) to change the URI credentials from a service in Cloud Foundry. More specifically, mLab service (free plan) from Pivotal Cloud Foundry.
Background
I created and pushed a nodejs app to Pivotal Cloud Foundry.
This app is bound to a mLab service using free plan.
When the mLab service was created using Pivotal website, it created a database with an user and password automatically.
Opening app settings inside Pivotal website, I can see the following environment variables. Please notice the mongo uri inside credentials and name inside mLab.
{
"staging_env_json": {},
"running_env_json": {},
"system_env_json": {
"VCAP_SERVICES": {
"mlab": [
{
"label": "mlab",
"provider": null,
"plan": "sandbox",
"name": "users",
"instance_name": "users",
"binding_name": null,
"credentials": {
"uri": "mongodb://CloudFoundry_someusergenerated:apasswordgeneratedautomatically#somehost.mlab.com:someport/CloudFoundry_database_name"
}
}
]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
"cf_api": "https://donotuseapi.run.pivotal.io",
"application_name": "website",
"application_uris": [
"xxx.cfapps.io"
],
"name": "website",
"space_name": "space1",
"uris": [
"xxx.cfapps.io"
]
}
}
}
The connection with the database works fine with this default user and password. In order to get the mongodb uri from the environment variables, I am using npm package cfenv
const appEnv = require('cfenv').getAppEnv();
const env = process.env;
keys = {
mongodb: {
dbURI: appEnv.getServiceURL(env.MONGO_SERVICE_NAME)
}
};
In my manifest.yaml file I have this MONGO_SERVICE_NAME specified accordingly with the service name inside the environment variables.
---
applications:
- name: website
memory: 128M
disk_quota: 256M
random-route: true
buildpack: nodejs_buildpack
health-check-type: port
env:
MONGO_SERVICE_NAME: 'users'
Again, the db connection works fine.
===
Then I opened mLab website for this particular database and created a new database user.
Now I want to update the credentials.uri from VCAP_SERVICES (environment variables) for this particular service to use the new user and password.
As far as I coould see, cf update-service CLI command is not meant by that so I am wondering if this is a limitation from Cloud Foundry, Pivotal or mLab. I could bet that this limitation is due to the fact I am using Pivotal trial account and mLab free plan, however my question still the same if I upgrade plans.
Thanks,
As a user, it's not possible for you to change VCAP_SERVICES entries that are generated by a service brokers. These are fixed and not possible to change.
If you cf create-service'd a service, then it was created by a service broker and you get exactly what the service provider gives you. As was mentioned in the comments, depending on the service broker you may be able to pass arguments to the broker with cf create-service -c. Check the documentation of your service provider to see if there is an option to influence the credentials generated in the way that you would like.
If your service provider does not provide options to do what you want, you can create a service key instead of binding your service to an app. This will give you a set of credentials to your service that will last for the duration of the service key. The service key credentials are not automatically passed into an app, but you can feed them into your app in a variety of ways.
You can pass them in through environment variables.
You can create a user provided service (cf cups).
You can pass them through in application config or through a config server.
With all of these options, you are passing the credentials through to the app so you could in theory adjust or alter them before they get to your app.
Hope that helps!

SAP Cloud Platform : Basic Authentication showing when accessing service in WEB IDE app. Why?

I'm using a the same destination on a number of apps, which are connecting fine.
Created a new app (using the same SAP WEB IDE template).
The Service is retrieved fine when selecting New/OData service from the project menu, proving my Destination credentials are fine.
Now, when I run the app. I'm getting a basic authentication window. Cancelling this means I can't connect to the metadata of the service and therefore can't retrieve any data.
https://webidetesting0837185-s0015641139trial.dispatcher.hanatrial.ondemand.com/SAPUI5-ABAP-SFI/sap/opu/odata/sap/ZSV_SURVEY_SRV/$metadata?sap-language=EN 401 (Unauthorized)
My username and password is not being accepted even though it's correct.
Any ideas?
If you User/Password is not accepted I think you missing some configuration in the backend, check the logs like ST22 or SLG1 for authorization issues. Also check if your destinations in Cloud Connector work properly.
To solve this in generell not using basic authentication, you need to work with SAP CP's destination service. Retrieving from onPremise or via AppToAppSSO as Type/Mode of the destination OR work with API Service on SAP CP. For first way change (destination service) reference in your SAPUI5 instead of relative paths in neo-app.json like this:
{
"routes": [
{
"path": "/destinations/SFSF_ODATA_PROXY",
"target": {
"type": "destination",
"name": "sap_hcmcloud_core_odata"
},
"description": "SFSF Proxy OData"
}
],
"cacheControl": [
{
"directive": "public",
"maxAge": 0
}
]
}
Make sure you enter the credentials for your backend (and not for your CP account for example). You can also try and maintain the credentials in the destination itself by setting AuthenticationType as BasicAuthentication.
I have already solved this issue with change Authentication as Basic Authentication