This project automates the deployment of a Nexus VM on Azure using Terraform, builds a Java web application, and facilitates deployment using Docker and Kubernetes. It also integrates CI/CD pipelines with GitHub Actions for streamlined image building and pushing to Nexus.
- Azure Subscription: Ensure you have access to an Azure account.
- Terraform: Install Terraform CLI (Download Terraform).
- Docker: Install Docker (Install Docker).
- Minikube (or a Kubernetes cluster): Install Minikube (Install Minikube).
- Java & Maven: Install Java Development Kit (JDK) and Maven.
-
Add your Azure subscription ID to
terraform/subscription.txt:4b0000b-cxxx-40000-bxxxx-b8xxxxxx6a
-
Configure
terraform/terraform.tfvarswith the following:subscription_id="4b0000b-cxxx-40000-bxxxx-b8xxxxxx6a" location="East US" tenant_id="6fxxxxxf-2xxx-4xxxx-8xxd-1fxxxxxxxxx6" vmuser="<VM_USERNAME>" # Your VM SSH username
Run the provided script to build the Azure infrastructure:
cd terraform/
./build.shOnce completed, you’ll receive the public IP of the Nexus VM:
vm_public_ip = "13.82.212.227"- SSH into the Nexus VM using the public IP and the username configured in
terraform.tfvars:
The Script will do this step for you and echo the admin password in the console.
ssh <VM_USERNAME>@13.82.212.227- Retrieve the Nexus password for initial login.
Navigate to Nexus using the Public IP of the Nexus VM and the port 13.82.212.227:8081
Sign in using the username admin and the password (that will be shown in your terminal).
Create a repository for your docker image, make sure it is docker-hosted
Navigate to the app directory and package the Java web app:
cd app/
mvn packageRun the packaged .jar file:
java -jar target/demo-0.0.1-SNAPSHOT.jarAccess the application at http://localhost:8080.
cd app/
docker build -t javawebapp-img .docker run --name javaapp-container -p 8080:8080 javawebapp-img:latestAccess the application at http://localhost:8080.
- Log in to Nexus.
- Navigate to Settings > Repositories.
- Select the repository or create a new one (e.g.,
docker-hosted). - Enable HTTP Port (e.g.,
8082) and Docker V1 API.
Edit the daemon.json file on your system to include the Nexus registry:
{
"insecure-registries": ["13.82.212.227:8082"]
}Restart Docker:
sudo systemctl restart dockerStart Minikube or your local Kubernetes cluster:
minikube startCreate a namespace for the application:
kubectl create ns javawebapp-namespaceApply the Kubernetes manifests:
kubectl apply -n javawebapp-namespace -f k8s- Navigate to Settings > Secrets and Variables > Actions in your GitHub repository.
- Add the following secrets:
NEXUS_REGISTRY(e.g.,13.82.212.227:8082)NEXUS_USERNAME(e.g.,admin)NEXUS_PASSWORD(e.g.,<your-nexus-password>)
Commit your changes to the repository. This triggers the GitHub Actions workflow to:
- Build the Docker image.
- Push the image to the Nexus registry.
Deploy Monitoring stack using Helm
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stackUsing k9s Navigate to svc and at the service kube-prometheus-stack-grafana press shift+f to port forward locally at http://localhost:3000
Username: admin
Password: prom-operatorDeploy ArgoCD using Helm
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm install argo argo/argo-cdPort forward to localhost
kubectl port-forward service/argo-argocd-server -n default 8080:443-
Navigate to Applications:
- After adding your repository, go to the Applications section from the left sidebar.
-
Create a New Application:
- Click the New App button.
-
Application Configuration:
- Application Name: Provide a name for your application, e.g.,
my-app. - Project: Select
defaultunless you've set up a custom project. - Sync Policy: Set to manual or automatic depending on your needs.
- Repository URL: Choose the repository you added earlier.
- Path: Specify the path to the directory where your Kubernetes manifests or Helm chart are located, e.g.,
k8s/. - Cluster: Choose the cluster where you want to deploy the application (usually the in-cluster Kubernetes context).
- Namespace: Enter the Kubernetes namespace where the application should be deployed, e.g.,
default.
- Application Name: Provide a name for your application, e.g.,
-
Sync Options:
- You can enable auto-sync to automatically deploy changes from the repository to the cluster.
- Optionally, enable self-heal and prune resources.
-
Create the Application:
- Once all the fields are configured, click Create to create the application.
- After the application is created, you will be redirected to the application dashboard.
- If you've set up auto-sync, ArgoCD will automatically deploy the application based on the configurations in the repository.
- If manual sync is enabled:
- Click on the Sync button to manually trigger the deployment.
- Monitor the sync status and logs to ensure the application is deployed correctly.
To destroy the whole terraform environment that was created for the Nexus VM just run the following script:
./destroy.sh
This should destroy the environment and make sure nothing is left on the Azure cloud.
- Security: Enable HTTPS on Nexus for secure communication.
- Customizations: Modify
terraform.tfvarsand Kubernetes manifests (k8s) to fit your needs.




