gravity.azure.run

Please note that this deployment type is not yet tested and we might still run into some more mysteries.

Known issues

  • Startup time is high, around 5 minutes until the container is ready, where of you will see nothing in log tails. The logs will appear in batches (at least the CLI tail).
  • All manual at the moment.
  • It works at this time 14.11.2018 15:40, France Central location.


Step-by-step guide

I did all of it on portal.azure.com finally. All steps can be done in Azure CLI 2.0 too but somehow the UI version was better for my try and error approach.

Setup PhaseStepImagesOpen question
Resource Group
  1. For all of this setup, you need a resource group.
    1. There are naming conventions but for now I am happy that I made it and do not care about respecting those 100%.
  2. Create a new Resource group (left panel or search box).
  3. Choose an appropriate region, name it so you know which one it is and press Review + create.
  4. If Validation passed press Create and wait until it's done.
  5. Go to fresh created resource group.

2.

3.

4.

4-5.


Azure Database for MySQL servers

Not a "MySQL server"!

  1. Add new resource to resource group by clicking on Add or Create resources.
  2. Search for Azure Database for MySQL. Select it and press Create.
  3. Make note and save secure of the DB details you enter here.
  4. Go to Configure server and choose a cheap pricing tier since gravity does not need much resources. Press OK to save the config.
  5. Now hit Review + create.
  6. Recheck all the data and, if it's all right, click Create
  7. Wait until your deployment is complete
  8. Go to resource

1.

2.

3-4.

4.

6.

7.

8.


Azure Database for MySQL Firewall Rule
  1. Go to section Settings - Connection security.
  2. Allow access to Azure services - OFF.
  3. Add a new firewall rule:
    1. I recommend to add the correct external ip (your private IP) so the server will be a bit more secure.
    2. if you are a little lazy and don’t know your external private IP(WAN), Azure Portal can determine your external private IP and automatically add it by click on the Add client IP.
  4. Save.
  5. Wait for successfully updated settings.



1-4.

5.


Azure Database for MySQL Server parameters
  1. Go to section Settings - Server parameters.
  2. Start search by parameter name character_set_server
  3. By default, the value is LATIN1, but this is not true for the gravity-app! Сhange the value to UTF8 (This will change the setting globally on the server)
  4. Save parameters and wait for successfully updated server parameters.
  5. Go to main section - Overview
  6. Restart Server
  7. Press Yes and wait until your server will be restarted.
  8. Gravity-app needs a database which is not yet created, we have a plain SQL instance. Use your favorite mysql-client (The screenshot 7,8 shows an example with a Linux terminal), connect to the mysql server and create user and database (guide:Build a Java and MySQL App on VMs and Containers in Azure -> chapter "Configure the Azure MySQL database"). Bellow is an excerpt from medium, to see each step separately, visit the article of Benz:
    • mysql -u gravity@test-gravity -h test-gravity.mysql.database.azure.com -P 3306 -p ENTERYOURPASSWORDHERE
    • mysql> CREATE DATABASE gravity;
    • mysql> CREATE USER 'gravityCRUD' IDENTIFIED BY '123456q.';
    • mysql> GRANT ALL PRIVILEGES ON gravity.* to 'gravityCRUD';
  9. Check encoding setting.Be sure that results are 'utf8' or 'binary'. 'latin1' or other sets should not be there:
    • mysql> USE gravity;
    • mysql> SHOW VARIABLES LIKE 'char%';
    • mysql> exit;
  10. Go to section Settings - Connection strings and copy down the JDBC URL, we will need some parts of it later:
    String url ="jdbc:mysql://test-gravity.mysql.database.azure.com:3306/{your_database}?useSSL=true&requireSSL=false&enabledTLSProtocols=TLSv1.1,TLSv1.2"; myDbConn = DriverManager.getConnection(url, "gravity@test-gravity", {your_password});



1-4.

5-6.

7.

7.

8.

9.


App Service Plan

Now we need an app pricing plan (we do this separately to show it nicely). You could create the plan while creating the app but I chose this way to make it more transparent. The Plan will assign your compute units and thereby your speed.

  1. Add new resource to resource group by clicking on Add.
  2. Search for App Service Plan and select it.
  3. Press Create.
  4. Check selected Resource Group, give a name for your App Service Plan, select the Region.
  5. Go to section Pricing Tier - Change size and select suitable pricing tier
  6. We use a B3 tier (by default this tier is hidden - Click on "See additional options")
  7. Apply changes
  8. Sku and size should be changed, press Review and create, check data one more time and press Create
  9. Wait until it is done.

2.

3.

4-5.

6-7.

8.

9.

9.


App Service
  1. Add new resource to resource group by clicking on Add.
  2. Search for Web App and select it.
  3. Press Create.
  4. Check selected Resource Group, give a name for the app, from Runtime stack select Java 17, select right Region, and choose previously created App Service Plan. (like on screenshot). Press Review and Create.
  5. Now check the data one more time and finally let's Create our web app.
  6. Wait for it to finish.
  7. Go to resource.


2.

3.

4.

5.

6.

6.


Web App Config
  1. Prepare the Web App in section Monitoring - App service logs.
  2. Turn on the Application Logging to the File System mode
  3. Set the Quota to 100 and Retention Period to 3
  4. Save the App Service logs settings
  5. Now we need to prepare more by going to section Settings - Configuration
  6. Add some New application setting
  7. Add all application settings:
    "Name": "JAVA_OPTS", "Value": "-Dserver.port=80"
    "Name": "SPRING_DATASOURCE_PASSWORD", "Value": "123456q."
    "Name": "SPRING_DATASOURCE_URL", "Value": "jdbc:mysql://test-gravity.mysql.database.azure.com:3306/gravity?verifyServerCertificate=true&useSSL=true&requireSSL=true"
    "Name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS", "Value": "3"
    "Name": "SPRING_DATASOURCE_USERNAME", "Value": "gravityCRUD@test-gravity"
  8. After adding, we get a beautiful list of options, now Save the configuraton.
  9. Now we need to determine the ip addresses of our application by going to section Settings - Properties
  10. Copy all ip addresses from fields Outbound IP addresses & Additional Outbound IP Addresses and paste it to Firewall rules of MySQL Server
  11. Press Save.

1-4.

5-6.

7.

8.

9.

10-11.

How does this APPSETTINGS_ thing work that Azure does? Why does spring find them none the less? Has spring been enriched with this configuration option?

Is always on needed?

Upload Executable
  1. Go to main section Overview and Get publish profile.
  2. Open the publish file and get the three credentials:
    • publishUrl="ftp://waws-prod-par-005.ftp.azurewebsites.windows.net/site/wwwroot"
    • userName="test-gravity-app\$test-gravity-app"
    • userPWD="ncidpwum7GFp2CFGWtahyyrix6gwm6mB7DblvgsqLaSxiYwivtetSvCGBilJ"
  3. Open your favorite FTP client (in my case it is FileZilla) and using the three credentials obtained from the publication profile connect to ftp server:
    • value from publishUrl copy to Host field
    • value from userName copy to Username field
    • value from userPWD copy to Password field
  4. Rename our backend to "app.jar"
  5. Upload it to "wwwroot"
  6. Wait until upload complete

1.

2.

3-5.

6.

Does the name of the JAR matter?
Dark magic
  1. Go to main section Overview and Stop the Web App.
  2. Hit Start and prepare to wait at least 10 min (somehow I do not trust the Restart button, it disappointed me several times I had the impression).
  3. Tail the logs with the Azure CLI 2.0 (you might need to login but the az cli team rocks and automated it nicely, see bottom page). Our use the Log Stream of the Web App.

1.



This is absolutely intransparent. I do not get how it works and why the logs are delayed or appearing in batch.

Is the URL hit needed?

Start

Finally, takes around 10 minutes, hit our info URL to check:


Whey does it take so long?


The following commands came in handy while digging (sometimes, after a Web App restart you seem have to retail to "attach" to the correct container):

az webapp log tail --name "test-gravity-app" --resource-group "test-gravity-rg"