'How to deploy just the code in Google Cloud Platform
In my work, i've to update a certain part of a project, that's its made in Next.js and deployed in Google Cloud Platform, i have done my work successfully but now i don't now how to trigger a re-deploy on GCP because the code doesn't have a app.yaml
or a CI/CD implementation, and I don't know how the code was uploaded to GCP without either of these two ways
So I was wondering if there is a way to update the code, without deploying the GCP client with the app.yaml
file and CI/CD. To upload the code, since I will not have to make any more changes
Solution 1:[1]
I think you are just running the script using npm run start / node index.js / python3 main.py etc. If you are really using Google Cloud Platform and its servers, you would need a configuration file - app.yaml file/Dockerfile/ cloudbuild.yaml
For App Engine, you must first create the app.yaml file for the default service of your app before you can create and deploy app.yaml files for additional services. To deploy your application's service, run the following command from the directory where the app.yaml file of your service is located:
gcloud app deploy
By default, the gcloud app deploy command deploys only the app.yaml file in your current directory. Whenever you run this command, App Engine generates a unique ID for the version that you deploy, deploys the version to the Cloud project you configured the gcloud CLI to use, and routes all traffic to the new version. The new version becomes the default version.
If you are using Cloud Build for the deployment, build your Docker image using a build config file: use a Cloudbuild.yaml file/cloudbuild.json file
For a pre-built Docker image:
- In the same directory that contains your application source code, create a file named cloudbuild.yaml or cloudbuild.json.
- In the build config file:
Add a name field and specify the pre-built Docker image. The pre-built image is stored in the Container Registry at gcr.io/cloud-builders/docker. In the example config file below, the name field specifies that the pre-build Docker image is used by Cloud Build to execute the task indicated by the args field.
- Start the build using the build config file:
gcloud builds submit --region=REGION --config CONFIG_FILE_PATH
SOURCE_DIRECTORY
To build Docker image:
Cloud Build allows you to build a Docker image using just a Dockerfile. You don't require a separate build config file. To build using a Dockerfile, run the following command from the directory containing your source code and the Dockerfile:
gcloud builds submit --region=REGION --tag gcr.io/PROJECT_ID/IMAGE_NAME
So if you are not doing the above, I would like to know how you are deploying the app without config files. And coming to your question, yes you can redeploy the app, by :
- Just running the same command you used to originally deploy the app:
$
gcloud app deploy
This will replace the currently running instances with the new app. Add--no-promote
if you want to deploy without routing service to the latest version deployed. - Creating a Cloud Build trigger which automatically starts a build whenever you make any changes to your source code. You can configure the trigger to build your code on any changes to the source repository or only changes that match certain criteria.
Solution 2:[2]
You should be able to retrieve your app.yaml
configuration file from the Google Cloud Console, Click on the View
under Config
from the App Engine -> Versions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Priyashree Bhadra |
Solution 2 | Gourav B |