Many of us who has experience of deploying application back-end in Google Cloud Platform, are familiar with these screens.
During deployment with Eclipse, if there is any network issue, the deployment never got completed. Now in this moment, there are 2 way you can get rid of it. One is forcefully stop/cancel the deployment. And the other one is by closing eclipse. After this, if you try to deploy the same application, it throws one of the above error. Sometimes if more than one developer try to deploy the same application at the same time, the issue may arise. The Google Cloud SDK generates an error dialog saying- “…user can undo the transaction with ‘appcfg rollback‘”.
So, what is appcfg?
It’s a tool for deploying application manually in Google Cloud. The tool is included with the original App Engine SDK. As per the instructions provided by Google- https://cloud.google.com/appengine/docs/standard/java/tools/uploadinganapp, to deploy your app to App Engine, you run Maven (recommended) or the appcfg command from within the root directory of your application.
To deploy your app, run the appcfg command with the update action and the directory path of your WAR file, for example:
./appengine-java-sdk/bin/appcfg.sh [options] update [WAR_LOCATION]
Now lets talk again about the the issue and Rollback. Google Cloud Platform documentation for appcfg.sh command line arguments (https://cloud.google.com/appengine/docs/standard/java/tools/appcfg-arguments), says the below things about appcfg:
appcfg.sh should ideally be run using Java 7 (also known as 1.7). This command is used for a variety of application management tasks including deploying your app and updating datastore indexes. The appcfg tool is included with the App Engine SDK, which you can download and install at App Engine Java SDK.
usage: AppCfg [options] <action> [<app-dir>] [<argument>]
<app-dir> must be the directory that contains your WAR file.
And for Rollback, there is 1 line dedicated to it:
rollback: Rollback an in-progress update.
So during the actual time of Rollback we followed all the necessary steps specified for an rollback of the previous deployment. None worked for us. Even we searched Internet and found nowhere there is a proven solution which worked for us. After long experimenting with it in Linux system, we finally succeeded. The process clicked for us is as below:
1. Open the .bashrc file from your ‘home’ directory. We are using ‘Gedit’ instead of command line editor.
sudo gedit .bashrc
2. Add The line at the end of the file and updates PATH for the Google Cloud SDK.
3. Also add this line to enables bash completion for gcloud.
4. Now save the .bashrc file. You can restart your system, if require.
5. Go to your App Engine SDK’s bin folder.
6. Make appcfg.sh and run_java.sh executable.
sudo chmod +x appcfg.sh
sudo chmod +x run_java.sh
7. Now run the below command. Look at the last parameter after rollback. It is the directory path of your application’s ‘war’ folder.
./appcfg.sh –oauth2 –passin rollback /home/debasish/Works/MyProject/Developments/Back-End/My_Back-end_Production/my-backend/war
After this a browser window with Google consent screen will appear and it’ll ask for your Google account credentials. Once you provide them and validate, BINGO! The rollback will start.
Happy rollback. Happy deployment 🙂