mvn package
mvn jetty:run
To run in a different port
mvn jetty:run -Djetty.port=<your port>
set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n
mvn jetty:run
- Build a docker image using
Dockerfile
:docker build -t calculator .
- Run docker image locally
docker run --rm -p 8080:8080 calculator
- Then you can access the web app at http://localhost:8080 in browser
Rename the .war
file in target
folder to ROOT.war
and upload it to your Azure Web App through Git or FTP.
- Create a Container Registry on Azure
- Push your local image to ACR:
docker login -u <client id> -p <client secret> <your ACR server> docker tag calculator <your ACR server>/calculator docker push <your ACR server>/calculator
- Create a Web App in Linux on Azure
- In Docker Container settings of Web App, fill in image name, server URL, username and password of your ACR.
- Save the changes and you'll be able to access the web app in a few seconds.
- Create an Azure Container Service using Kubernetes as orchestrator.
- Install kubectl and connect to ACS using kubectl (refer to this doc).
- Create a secret for private container registry
kubectl create secret docker-registry <secret name> \ --docker-server=<your ACR server> \ --docker-username=<client id> \ --docker-password=<client secret> \ --docker-email=<your email>
- Build docker image and push to ACR (same as step 2 in previous section).
- Update
image
andimagePullSecrets
property indeployment.yaml
with image and secret name you just created. - Create a deployment in Kubernetes:
kubectl create -f deployment.yaml
- Create a service in Kubernetes:
kubectl create -f service.yaml
- Open Kubernetes to verify the deployment result:
Open http://localhost:8001/ui, go to Services, check calculator service to get external endpoint. Open external endpoint to access the web app.
kubectl proxy
General setup:
-
Go to Settings -> Integration & services, click Add service, choose Jenkins (GitHub plugin), fill in Jenkins hook url with
http://<your jenkins server>/github-webhook/
-
Make sure your Jenkins has the following components installed:
- JDK
- Maven
- Docker
And the following plugins installed:
- Azure credentials
- Docker pipeline
- Credentials binding
- Azure app service
- SSH agent
-
Open Jenkins, go to Credentials, add a new Microsoft Azure Service Principal using the credential information you just created.
-
If you want to deploy to Kubernetes, install
kubectl
and connect to ACS on your Jenkins instance (please be noted you have to do this usingjenkins
account).
You can always use Azure CLI to deploy web app to Azure using a Jenkins pipeline, here're a few samples:
- Azure Web App using FTP approach
- Azure Web App using container approach.
- ACS using Kubernetes.
With Azure app service plugin, you can deploy to Azure web app more easily.
- Create a freestyle project
- Add a build step to invoke
clean package
maven goals. - Add a post-build action 'Publish an Azure Web App', select appropriate credential, resource group name and web app name.
- To publish through FTP, select "Publish Files", fill in the
.war
file to deploy, source directory (target
) and target directory (webapps
). (If you need to deplo to ROOT, you need to add a step yourself to rename your war file toROOT.war
.) - To publish through container, select "Publish via Docker", fill in Dockerfile path, docker registry URL and registry credentials (you need to create a username/password credential first). (Docker image name is read from your web app configuration, you need to fill it in when creating a new web app or explicitly specify it in docker image in advanced properties.)
Please refer to the sample pipeline of FTP approach and container approach.