dimanche 3 mars 2019

Deploy a fullstack app in the cloud using GCP - part 3

Step 3 - Move the backend to the cloud

Now that your backend is running locally and consumes your online MongoDB instance, it's time to move your app to GCP.

Create a google account with billing activated

No stress ! You need a credit card to activate the billing, but google gives a 300$ credit for free, and you have 1 year to consume it.
If you do only tests, not production, it's free for 1 year. 

  • Click on the "Activate" Button on the top-right corner, and follow the assistant. You need to enter your card number, but you won't be charged without giving your authorization.

Create a project for the backend

  • In the nav bar, click "Select a project', and 'New project' in the popup
  • Then enter the name of yout project in the text box.
  • I recommand to modify the ID of the project, because the ID will be part of the URL. It will make your URL smarter.
  • To do this, click "Modify" button
  • Wait for the project to be created
  • Go to your new project (nav bar "Select project")
  • Activate appengine. On the right side, click "App Engine"
  • Click "Create an application", and select your region.
  • Then select :
  • Language : Java
  • Environment : Standard 

Note :

It is a way to create the project directly from the gcloud command (without using the GCP console). Unfortunatly, when I try this, there are network issues with the MongoDB. If anybody has any clue about that, please leave a comment !

Install the gcloud SDK

  • Click the "Download SDK" button and follow the instructions.

For the first time (you never deployed the app, and never created the configuration)

  • Create a new gcloud configuration for the back 
gcloud config configurations create back
  • If you are behind a corporate proxy 
gcloud config set proxy/address [address_of_your_proxy]
gcloud config set proxy/port [port_of_youor_proxy]
gcloud config set proxy/type http
  • Then 
gcloud components install app-engine-java
    $ gcloud init
    • Choose 1 - Re-initialize configuration
    • Then choose your google account (or login with a new account)
    • Select the project you created at the previous step
    • The project name will be part of the URL, select an appropriate name

    Or, if the configuration "back" already exists

    gcloud config configurations activate back

    Deploy the application

    • Just do the following command :
    ./mvnw -DskipTests appengine:deploy
    • At the end, the public URL of your app is displayed :
    [INFO] GCLOUD: Deployed service [default] to [https://xxx_yourappname.appspot.com]

    Test the app online

    • As in local, you can use Postman to test.
    • If you are behing a proxy, do not forget to adjust the postman settings.
    • Take your local testsuite, change the URL from http://localhost:8080 by https://xxx_yourappname.appspot.com, as displayed by the Maven build (previous step).
    • Great, now your backend is up and running in the cloud. Next step : build the frontend locally !

    Aucun commentaire:

    Enregistrer un commentaire