I have a Google App Engine Java 11 service using the Standard Environment.
I have deployed it specifying in the corresponding app.yaml file manual scaling, setting the number of instances to 1.
Is there a way that I can increase the number of instances for this service without having to upload again all the files in the service?
So I have one instance. Now I want 2 instances. How do I do this?
Have not found a way in either the console or in the gcloud utilities to do this.
Also, just calling gcloud app deploy with the modified app.yaml file creates a broken version of the service.
app.yaml:
service: headergrabber
runtime: java11
instance_class: B8
manual_scaling:
instances: 1
Use REST API to patch the number of instances of your manual scaling app.
Here's the HTTP request:
PATCH https://appengine.googleapis.com/v1/{name=apps/*/services/*/versions/*}
You will have to pass manualScaling.instances field to update to the number of instance you prefer.
Here's an example with curl using a token that should only be used for local testing. I tested it on my side and it works:
curl -X PATCH -H "Content-Type: application/json" \
-d "{ 'manualScaling': { 'instances': 2 } }" \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
https://appengine.googleapis.com/v1/apps/PROJECT-ID/services/SERVICE/versions/VERSION?updateMask=manualScaling.instances
Where:
PROJECT_ID = Project ID
SERVICE = Service Name
VERSION = Version Name
You need to login to your account and set the project if you're using Cloud SDK or you can run the command on Cloud Shell.
An alternative is to use a client library so you can write applications that can update your App Engine instance.
Take note that doing this would require App Engine Admin API enabled on your project. This API provides programmatic access to several of the App Engine administrative operations that are found in the Google Cloud Console.
Related
I'm actually working on the Continuous Delivery pipeline for the UI project made in ReactJs with the use of the Azure Static Web App.
I want to create and deploy the static web app to Azure based on the git repo located in Azure DevOps.
The reason behind this is I see a huge opportunity to create a Pull Request Environment pipeline for the system I work on every day with the usage of static web apps which seem to be a super cheap and fast solution! Then the pipeline would allow testing the Pull Request changes in isolation before releasing to DEV, QA,... Prod environments.
Anyway, straight to the point.
The official Microsoft documentation provides only an example of how to do this for GitHub repo but I cannot find any info on how this can be achieved when using Azure DevOps git repo:
az staticwebapp create \
-n my-first-static-web-app \
-g <RESOURCE_GROUP_NAME> \
-s https://github.com/<YOUR_GITHUB_ACCOUNT_NAME>/my-first-static-web-app \
-l <LOCATION> \
-b main \
--app-artifact-location "build" \
--token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>
I thought that the way the az staticwebapp create works in the provided example should be analogical with the Azure DevOps.
I thought that equivalent of YOUR_GITHUB_PERSONAL_ACCESS_TOKEN in Azure DevOps would be an access token that can be generated:
When I try to run the following code:
az staticwebapp create -l westus2 -n appNameTest1 -g TestPrEnvResourceGroup -s "https://dev.azure.com/myOrganisationName/myProjectName/_git/myRepoName -b "main" --token "generatedTokenValuefwfsdgsgsd"
I'm getting the following exception;
Command group 'staticwebapp' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus Operation returned an invalid status 'Bad Request'
Also, I don't think it can matter but the TestPrEnvResourceGroup is created under the UK West location.
It doesn't tell me much, like if the token or some other parameter is wrong...
Any ideas?
Cheers
Have you tried this way?
You need to generate a deployment token from the Azure Static Web App and have it in the YAML
I tried the same for Angular app and it worked pretty well
azure_static_web_apps_api_token: $(deployment_token)
UPDATE : As per the Github issue , currently this is not supported.
We currently don’t support automatically creating Azure DevOps
pipelines. This is the supported path for using Azure DevOps:
https://learn.microsoft.com/en-us/azure/static-web-apps/publish-devops
You can vote for the feature here
I have deployed my Django Project to Google App Engine and I need to add environment variables.
The docs say to add them to app.yaml but that seems like bad practice because app.yaml should be in your git repository.
Is there any way to add environment variables to App Engine the same way you can add them in Cloud Run > Services > Variables & Secrets ?
Google Secret Manager is available, since this spring:
Enable Secret Manager API
Add the Secret Manager Secret Accessor role to the App Engine SA
Create secretes from the GCP Web UI or programmatically(code examples are from official documentation):
def create_secret(project_id, secret_id):
"""
Create a new secret with the given name. A secret is a logical wrapper
around a collection of secret versions. Secret versions hold the actual
secret material.
"""
# Import the Secret Manager client library.
from google.cloud import secretmanager
# Create the Secret Manager client.
client = secretmanager.SecretManagerServiceClient()
# Build the resource name of the parent project.
parent = client.project_path(project_id)
# Create the secret.
response = client.create_secret(parent, secret_id, {
'replication': {
'automatic': {},
},
})
# Print the new secret name.
print('Created secret: {}'.format(response.name))
Consume the secrets from the app instead of the environment variables:
def access_secret_version(project_id, secret_id, version_id):
"""
Access the payload for the given secret version if one exists. The version
can be a version number as a string (e.g. "5") or an alias (e.g. "latest").
"""
# Import the Secret Manager client library.
from google.cloud import secretmanager
# Create the Secret Manager client.
client = secretmanager.SecretManagerServiceClient()
# Build the resource name of the secret version.
name = client.secret_version_path(project_id, secret_id, version_id)
# Access the secret version.
response = client.access_secret_version(name)
# Print the secret payload.
#
# WARNING: Do not print the secret in a production environment - this
# snippet is showing how to access the secret material.
payload = response.payload.data.decode('UTF-8')
print('Plaintext: {}'.format(payload))
If you are using a continuous deployment process you could rewrite (or created) the app.yaml to include variables relevant to each deployment target within the CD build system.
We rewrite several files as part of our deployment process to App engine using Bitbucket pipelines. Variables can be defined at a workspace level (across multiple repositories), within a repository, and also for each deployment target defined. These variables can be secured so they are not readable.
build: &build
- step:
name: Update configuration for deployment
script:
- find . -type f -name "*.yaml" -exec sed -i "s/\[secret-key-placeholder\]/$SECRET_KEY/g" {} +
Refer to https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/#Deployment-variables
I have a .NET Core 2.2 app using a PostgreSQL DB.
Now I want to deploy it on Google Cloud App Engine Flex and Google Cloud SQL PostgreSQL.
I tried the official way and found this, where I found that you have to use $ gcloud beta app deploy instead of $ gcloud app deploy
My app.yaml configuration file:
env: flex
runtime: aspnetcore
beta_settings:
cloud_sql_instances: "<SQL-NAME>=tcp:<PORT>"
The issue is that I get this error:
Trying to connect to
Host=127.0.0.1;Port=XXX;Username=XXX;Password=XXX;Database=XXX;
Application startup exception: System.Net.Sockets.SocketException
(111): Connection refused
Do I have to include special libraries into .NET Core 2.2 to support Google App Engine?
You don't need to include any special libraries in .NET Core 2.2 rather than those that are already included in the Quckstart that you have shared above, unless of course you are using any additional libraries in your code.
I have tried the quickstart and deployed my .NET GAE app that connects to CloudSQL PostgreSQL database.
Taking a look at your app.yaml configuration file I can see that there is an issue with it. Also based on the error message you are getting I assume that you are having an issue in your appsettings.json file as well.
Based on the quickstart of GitHub that you shared, the configuration when deploying should be:
app.yaml
runtime: aspnetcore
env: flex
beta_settings:
cloud_sql_instances: "[PROJECT_ID]:[INSTANCE_REGION]:[INSTANCE_NAME]=tcp:[TCP_PORT_NUMPER]"
TCP Port number for PostgreSQL: 5432
TCP Port number for MySQL: 3306
To find the Instance connection name which is the part before tcp, you can go to Cloud Console > SQL > [YOU_INSTANCE_NAME] and you can find the entire string under Instance connection name
appsettings.json
{
"CloudSQL" : {
"Database" : "PostgreSQL", // Set to "PostgreSQL" when using a PostgreSQL database.
// [START gae_flex_mysql_settings]
"ConnectionString": "Uid=[USER_ID];Pwd=[PASSWORD];Host=cloudsql;Database=[DATABASE_NAME]"
// [END gae_flex_mysql_settings]
}
}
Database should be PostgreSQL as also specified by the comment
ConnectionString should be filled with your own data that you used to setup the database
The Host part should be cloudsql when you are deploying and 127.0.0.1 when running locally.
127.0.0.1 indicates that the database is running locally and the cloudsql string indicates that it should use the connection string name. Based on the error, I assume that you used the 127.0.0.1 to test locally but then forgot to change it back when you were deploying.
Is it possible to deploy Elasticsearch on App engine flex environment using a docker image.
I have tried the following
My files on the local machine
Folder : elasticsearch
app.yaml
Dockerfile
docker-entrypoint.sh
config folder(containing elasticsearch.yml)file
Contents of app.yaml
runtime: custom
env: flex
Dockerfile and docker-entrypoint.sh copied from https://github.com/GoogleCloudPlatform/elasticsearch-docker/tree/master/5/5.2.0
Modifications to the Dockerfile
replaced EXPOSE 9200 9300 to EXPOSE 8080
Modification to the elasticsearch.yml
cluster.name: "beaconinside-docker-cluster"
path.data: /usr/share/elasticsearch/data
http.host: 0.0.0.0
http.port: 8080
discovery.zen.minimum_master_nodes: 1
I build a container using the docker file on my local machine
docker build -t elasticdemo .
Then, I run the container
docker run -p 8080:8080 elasticdemo
I am able to access elasticsearch on 0.0.0.0:8080
Problem:
I am trying to deploy elasticsearch as an app to Google app engine flex environment
gcloud app deploy app.yaml --version elasticdocker --project myproject
The deployment fails with the following error
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
I was expected elasticsearch to deploy as an app and be available on the deployed url.
Could you please provide pointers/help/suggestions with this approach?
While you can deploy ES to App Engine Flexible environment it's not particularly useful. The VMs hosting GAE Flexible containers are restarted regularly as part of maintenance and whatever data is stored on the local disk will be lost on restart. If you want to use local disk for long term storage, I'd suggest to deploy the GCE VM's (or alternatively use a solution from the GCP Marketplace) or deploy to GKE which supports persistent disks
As for the actual question: you probably don't have a health check handler and therefore App Engine Flexible environment doesn't consider your app healthy after deploying it. The error message is useless, I agree.
From the GAE Flexible docs for building custom images:
"A health check is an HTTP request to the URL /_ah/health. A healthy application should respond with status code 200."
Alternatively you can turn off health checks by adding into app.yaml
enable_health_check: False
The CircleCI appengine documentation suggests using a password to do deployment. How can I use the oauth2 flow instead of using passwords? I don't want to share my Google password.
Do I generate a ~/.appcfg_oauth2_tokens_java file, from token data stored as environment variables in CircleCI? Is there a simpler way?
I solved the issue this way:
deployment:
appengine:
branch: master
commands:
- erb .appcfg_oauth2_tokens_java.json > ~/.appcfg_oauth2_tokens_java # requires ENV in circle ci
- mvn -DskipTests=true appengine:update # tests have already been run
.appcfg_oauth2_tokens_java.json:
{
"credentials": {
"ubuntu": {
"access_token": "<%= ENV["GOOGLE_ACCESS_TOKEN"] %>",
"expiration_time_millis": 1431552739090,
"refresh_token": "<%= ENV["GOOGLE_REFRESH_TOKEN"] %>"
}
}
}
Then in CircleCI, configure the ENV variables for the two tokens. I got the tokens by locally running mvn appengine:update and going through the oAuth2 dance. Note: You may have to remove your existing ~/.appcfg_oauth2_tokens_java file first.
Reading the AppEngine SDK docs, it sounds like that would be a good approach. There is not a built-in way to do that on CircleCI.
If you don't want to use any user-related credential, you can leverage service accounts, like mentioned in this blog post:
Continuous Deployment with Google App Engine and CircleCI
I solved it this way on the latest GAE SDK 1.9.34 for Java.
Assuming you have a Base64 encoded ENV Variable with your JSON key for a service account you've created on the GCloud project:
dependencies:
pre:
- echo $GOOGLE_CLIENT_SECRET | base64 --decode > ${HOME}/client-secret.json
And then in the deployment section:
- $HOME/appengine-java-sdk-$APP_ENGINE_VERSION/bin/appcfg.sh -A $GCLOUD_PROJECT -M $GCLOUD_MODULE -V $BUILD_VERSION --service_account_json_key_file=$HOME/client-secret.json update $WAR_FOLDER
The --service_account_json_key_file doesn't seem to appear as an option when you use appcfg.sh help but it is there, and does work.