Skip to content

Dev uat #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker-Java-kubernetes-project
Deploying Java Applications with Docker and Kubernetes
Deploying Java Application with Docker and Kubernetes

Credit: https://github.com/danielbryantuk/oreilly-docker-java-shopping/
5 changes: 5 additions & 0 deletions inventory/k8-inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[MAVEN]
192.168.0.112 ansible_user=jits ansible_ssh_pass=redhat

[localhost]
192.168.0.112
40 changes: 40 additions & 0 deletions jenkinsfiles/deployk8
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
properties([
parameters([
string(defaultValue: 'dev-uat', name: 'BRANCH'),
string(defaultValue: 'master', name: 'comp'),
string(defaultValue: 'master', name: 'mvn'),
string(defaultValue: 'service', name: 'action')
])
])

node {
cleanWs()

echo "The workspace directory is ${env.WORKSPACE}"

stage('Git Checkout') {
git branch: "${params.BRANCH}", credentialsId: 'myjenkins', url: 'git@github.com:pjitss/docker-Java-kubernetes-project.git'
}



stage('SonarQube Analysis') {
withCredentials([string(credentialsId: 'mysonar2', variable: 'SONAR_TOKEN')]) {
withSonarQubeEnv('mysonar') {
sh """
mvn clean verify sonar:sonar \
-Dsonar.projectKey=mysonar2 \
-Dsonar.host.url=http://192.168.0.190:9000 \
-Dsonar.login=$SONAR_TOKEN
"""
}
}
}

stage('Execute Ansible Playbooks on Kubernetes Master') {
ansiblePlaybook(
playbook: "playbooks/k8deploy-main.yml",
extras: "-i inventory/k8-inventory -e target_host=${comp} -e mvn=${mvn}"
)
}
}
190 changes: 190 additions & 0 deletions others/settings.xml_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">

<!-- Licensed to the Apache Software Foundation (ASF) under one... [additional license information] ... -->

<!-- This is the configuration file for Maven... [additional introductory comments] ... -->

<!-- localRepository
| The path to the local repository maven will use to store artifacts.
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->

<!-- interactiveMode
| This will determine whether maven prompts you when it needs input.
| Default: true
<interactiveMode>true</interactiveMode>
-->

<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| Default: false
<offline>false</offline>
-->

<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins...
| [additional pluginGroups information]
-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>

<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network...
| [additional proxies information]
-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>

<!-- servers
| This is a list of authentication profiles...
| [additional servers information]
-->
<servers>
<!-- Existing server configurations -->
<!-- server
| Specifies the authentication information to use when connecting to a particular server...
| [additional server configuration information]
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->

<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->

<!-- Nexus server configurations -->
<server>
<id>nexus-releases</id>
<username>jitsnexus</username>
<password>{9VYKv8N4arIHArUuHxu7j/gKBkgIyAt663MEHi5EDPY=}</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>jitsnexus</username>
<password>{9VYKv8N4arIHArUuHxu7j/gKBkgIyAt663MEHi5EDPY=}</password>
</server>
</servers>

<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories...
| [additional mirrors information]
-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository...
| [additional mirror configuration information]
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
</mirrors>

<!-- profiles
| This is a list of profiles which can be activated in a variety of ways...
| [additional profiles information]
-->
<profiles>
<!-- Existing profiles configuration -->
<!-- profile
| Specifies a set of introductions to the build process...
| [additional profile configuration information]
|
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->

<!-- Nexus Repository Profile -->
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://192.168.0.190:8081/repository/maven-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://192.168.0.190:8081/repository/maven-snapshots/</url>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>false</enabled></releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://102.168.0.190:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<!-- activeProfiles
| List of profiles that are active for all builds.
| [additional activeProfiles information]
-->
<activeProfiles>
<!-- Existing active profile configurations -->
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>

<!-- Activating Nexus profile -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
72 changes: 72 additions & 0 deletions playbooks/k8deploy-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
- hosts: "{{ target_host }}"
gather_facts: false
#become: yes
#become_method: sudo
#become_user: jits
tasks:

- name: Ensure jenkins owns the workspace directory
file:
path: "/var/lib/jenkins/workspace/cicd-k8/shopfrontss"
state: directory
owner: jenkins
group: jenkins
recurse: yes
become: yes
when: mvn == "prm"

- name: execute mvn command for shopfront
shell: /opt/maven/apache-maven-3.8.8/bin/mvn clean deploy
#register: shop_output
args:
chdir: "{{ lookup('env', 'WORKSPACE') }}/shopfront"
when: mvn == "shop" or mvn == "allapps"
become: yes

- name: execute mvn command for productcatalogue
command: /opt/maven/apache-maven-3.8.8/bin/mvn clean deploy
#register: product_output
args:
chdir: "{{ lookup('env', 'WORKSPACE') }}/productcatalogue"
when: mvn == "product" or mvn == "allapps"
become: yes

- name: execute mvn command for stockmanager
command: /opt/maven/apache-maven-3.8.8/bin/mvn clean deploy
#register: stock_output
args:
chdir: "{{ lookup('env', 'WORKSPACE') }}/stockmanager"
when: mvn == "stock" or mvn == "allapps"
become: yes

#- name: Print all mvn outputs
# debug:
# msg: |
# Shopfront output: {{ shop_output.stdout | default('Not executed') }}
# Product Catalogue output: {{ product_output.stdout | default('Not executed') }}
# Stock Manager output: {{ stock_output.stdout | default('Not executed') }}

- name: Build and Push Docker image for shopfront
docker_image:
name: "jitss/shopfront:1.1"
build:
path: "{{ lookup('env', 'WORKSPACE') }}/shopfront"
push: yes
when: mvn == "docker"

- name: Build and Push Docker image for productcatalogue
docker_image:
name: "jitss/productcatalogue:1.1"
build:
path: "{{ lookup('env', 'WORKSPACE') }}/productcatalogue"
push: yes
when: mvn == "docker"

- name: Build and Push Docker image for stockmanager
docker_image:
name: "jitss/productcatalogue:1.1"
build:
path: "{{ lookup('env', 'WORKSPACE') }}/stockmanager"
push: yes
when: mvn == "docker"

17 changes: 15 additions & 2 deletions productcatalogue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
<!-- Add more dependencies as needed -->
</dependencies>


<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -76,4 +76,17 @@
</plugin>
</plugins>
</build>
</project>

<!-- DistributionManagement for Nexus -->
<distributionManagement>
<repository>
<id>nexus-releases</id> <!-- Match this with the ID in your settings.xml -->
<url>http://192.168.0.190:8081/repository/maven-releases/</url> <!-- Replace with your Nexus release repository URL -->
</repository>
<snapshotRepository>
<id>nexus-snapshots</id> <!-- Match this with the ID in your settings.xml -->
<url>http://192.168.0.190:8081/repository/maven-snapshots/</url> <!-- Replace with your Nexus snapshot repository URL -->
</snapshotRepository>
</distributionManagement>

</project>
Loading