Learn to deploy a Java Spring app to Azure App Service and set up a CI/CD workflow using GitHub Actions
GitHub Actions gives you the flexibility to build an automated software development lifecycle workflow. You can write individual tasks ("Actions") and combine them to create a custom workflow. Workflows are configurable automated processes that you can set up in your repository to build, test, package, release, or deploy any project on GitHub.
With GitHub Actions you can build end-to-end continuous integration (CI) and continuous deployment (CD) capabilities directly in your repository.
You will need a GitHub account. If you do not have one, you can sign up for free here
Microsoft Azure Account: You will need a valid and active Azure account for this lab. If you do not have one, you can sign up for a free trial.
Fork this repo and open the sample app code in VS Code to get started.
Create an Azure App ServiceCreate a Wildfly based web app hosted in Azure by following the guidance in this article: https://github.com/Azure-Samples/app-service-wildfly
Set up CI/CD workflow with GitHub ActionsWe'll use GitHub actions to automate our deployment workflow for this web app.
Navigate to the sample CI/CD workflow file workflow.yml
in your GitHub repo under .github/workflows/
folder path
Modify the values of the environment variables based on your Azure app:
env: AZURE_WEBAPP_NAME: your-app-name # set this to your application's name AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root JAVA_VERSION: '1.8' # set this to the Java version to use AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # set GH repo secret with the publish profile of the web app
In the portal, Overview page, click on "Get publish profile". A publish profile is a kind of deployment credential, useful when you don't own the Azure subscription. Open the downloaded settings file in VS Code and copy the contents of the file.
We will now add the publish profile as a secret associated with this repo. On the GitHub repository, click on the "Settings" tab.
Go to "Secrets". Create a new secret called "AZURE_WEBAPP_PUBLISH_PROFILE" and paste the contents from the settings file.
Once you're done editing the workflow by configuring the required environment variables, click on "Start commit". Committing the file will trigger the workflow.
You can go back to the Actions tab, click on your workflow, and see that the workflow is queued or being deployed. Wait for the job to complete successfully.
Browse your app by pasting the URL of your Azure web app: https://AZURE_WEBAPP_NAME.azurewebsites.net
Make any changes by editing the app contents and commit the changes. Browse to the Actions tab in GitHub to view the live logs of your Action workflow which got triggered with the push of the commit.
Once the workflow successfully completes execution, browse back to your website to visualise the new changes you introduced!
Do you remember the good old Java Petstore ? It was a sample application created by Sun for its Java BluePrints program. The Java Petstore was designed to illustrate how J2EE (and then Java EE) could be used to develop an eCommerce web application. Yes, the point of the Petstore is to sell pets online. The Petstore had a huge momentum and we started to see plenty of Petstore-like applications flourish. The idea was to build an application with a certain technology. Let's face it, the J2EE version was far too complex using plenty of (today outdated) design patterns. When I wrote my Java EE 5 book back in 2006, I decided to write a Petstore-like application but much simpler. But again, it's out-dated today.
What you have here is another Petstore-like application but using Java EE 7 and all its goodies (CDI, EJB Lite, REST interface). It is based on the Petstore I developed for my Java EE 5 book (sorry, it's written in French). I've updated it based on my Java EE 6 book, and now I'm updating it again so it uses some new features of Java EE 7 described on my Java EE 7 book. The goals of this sample is to :
If you want to use a different web interface, external frameworks, add some sexy alternative JVM language... feel free to fork the code. But the goal of this EE 7 Petstore is to remain simple and to stick to Java EE 7.
The only external framework used are Arquillian, Twitter Bootstrap and PrimeFaces. Arquillian is used for integration testing. Using Maven profile, you can test services, injection, persistence... against different application servers. Twitter Bootstrap and PrimeFaces bring a bit of beauty to the web interface.
Being Maven centric, you can compile and package it without tests using mvn clean compile -Dmaven.test.skip=true
, mvn clean package -Dmaven.test.skip=true
or mvn clean install -Dmaven.test.skip=true
. Once you have your war file, you can deploy it.
Launching tests under WildFly is straight forward. You only have to launch WidlFly and execute the tests using the Maven profile :
mvn clean test -Parquillian-wildfly-remote
Or if you prefer the managed mode :
mvn clean test -Parquillian-wildfly-managed
Once deployed go to the following URL and start buying some pets: http://localhost:8080/applicationPetstore.
The admin REST interface allows you to create/update/remove items in the catalog, orders or customers. You can run the following curl commands :
curl -X GET http://localhost:8080/applicationPetstore/rest/categories
curl -X GET http://localhost:8080/applicationPetstore/rest/products
curl -X GET http://localhost:8080/applicationPetstore/rest/items
curl -X GET http://localhost:8080/applicationPetstore/rest/countries
curl -X GET http://localhost:8080/applicationPetstore/rest/customers
You can also get a JSON representation as follow :
curl -X GET -H "accept: application/json" http://localhost:8080/applicationPetstore/rest/items
Check the Swagger contract on : http://localhost:8080/applicationPetstore/swagger.json
The persistence.xml
defines a persistence unit called applicationPetstorePU
that uses the default JBoss database :
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
By default, the application uses the in-memory H2 database. If you log into the WildFly Admin Console, go to http://localhost:9990/console/App.html#profile/datasources;name=ExampleDS and you will see the H2 Driver as well as the Connection URL pointing at the in-memory H2 database jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
If instead a H2 in-memory database you want to use PostgreSQL, you need to do the following steps.
Install the PostgreSQL driver into WildflyThis good article explains you how.
$WILDFLY_HOME/modules/system/layers/base/
and create the folder org/postgresql/main
postgresql-42.1.4.jar
) to the new folder $WILDFLY_HOME/modules/system/layers/base/org/postgresql/main
$WILDFLY_HOME/modules/system/layers/base/org/postgresql/main/module.xml
with the following content:<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.1.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
WILDFLY_HOME/bin $ ./jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql, driver-class-name=org.postgresql.Driver)
{"outcome" => "success"}
Modify the default Datasource
In the Wildfly Admin Console check the default datasource ExampleDS. As you can see, it points to an in-memory H2 database. Make the following changes so it points at Postgres:
jdbc:postgresql://localhost:5432/postgres
postgres
and no passwordOnce Postgres is up and running, you can hit the button Test Connection
. It should be ok.
The easiest is to use the Docker file to start Postgres
$ docker-compose -f src/main/docker/postgresql.yml up -d
Test this application on CloudBees
Third Party Tools & Frameworks
When, like me, you have no web designer skills at all and your web pages look ugly, you use Twitter Bootstrap ;o)
I use:
Arquillian for the integration tests.
Some people who worked on this project :
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
antonio goncalves
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4