Compare commits
2 Commits
feature/an
...
feature/de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c53fe05e1 | ||
|
|
fab255d0da |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.idea/*
|
.idea/*
|
||||||
|
target
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
environment {
|
|
||||||
ANSIBLE_SERVER = "157.230.120.252"
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage("copy ansible folder and ec2 access key to ansible-server") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
sshagent(['ansible-server-key']) {
|
|
||||||
echo "copying ansible folder to ansible server"
|
|
||||||
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
|
|
||||||
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
|
|
||||||
|
|
||||||
echo "copying ssh keys for ec2 instances"
|
|
||||||
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
|
||||||
sh 'scp $keyfile root@$ANSIBLE_SERVER:/root/ssh-key.pem'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("execute ansible playbook from the ansible-server") {
|
|
||||||
environment {
|
|
||||||
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
|
||||||
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "executing ansible-playbook"
|
|
||||||
|
|
||||||
def remote = [:]
|
|
||||||
remote.name = "ansible-server"
|
|
||||||
remote.host = ANSIBLE_SERVER
|
|
||||||
remote.allowAnyHosts = true
|
|
||||||
|
|
||||||
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
|
||||||
remote.identityFile = keyfile
|
|
||||||
remote.user = user
|
|
||||||
|
|
||||||
sshCommand remote: remote, command: "ls -l"
|
|
||||||
|
|
||||||
// set AWS credentials
|
|
||||||
sshScript remote: remote, script: "ansible/prepare-server.sh"
|
|
||||||
|
|
||||||
sshCommand remote: remote, command: "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}; export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}; ansible-playbook docker-and-compose.yaml"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
environment {
|
|
||||||
ANSIBLE_SERVER = "157.230.120.252"
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage("copy ansible folder and ec2 access key to ansible-server") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
sshagent(['ansible-server-key']) {
|
|
||||||
echo "copying ansible folder to ansible server"
|
|
||||||
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
|
|
||||||
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
|
|
||||||
|
|
||||||
echo "copying ssh keys for ec2 instances"
|
|
||||||
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
|
||||||
sh 'scp $keyfile root@$ANSIBLE_SERVER:/root/ssh-key.pem'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("execute ansible playbook from the ansible-server") {
|
|
||||||
environment {
|
|
||||||
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
|
||||||
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "executing ansible-playbook"
|
|
||||||
|
|
||||||
def remote = [:]
|
|
||||||
remote.name = "ansible-server"
|
|
||||||
remote.host = ANSIBLE_SERVER
|
|
||||||
remote.allowAnyHosts = true
|
|
||||||
|
|
||||||
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
|
||||||
remote.identityFile = keyfile
|
|
||||||
remote.user = user
|
|
||||||
|
|
||||||
sshCommand remote: remote, command: "ls -l"
|
|
||||||
sshCommand remote: remote, command: "ansible-playbook docker-and-compose.yaml"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
def gv
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
stages {
|
|
||||||
stage("build jar") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn package'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("build image") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "building the docker image..."
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'docker-hub-repo', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
||||||
sh 'docker build -t nanajanashia/demo-app:jma-2.0 .'
|
|
||||||
sh "echo $PASS | docker login -u $USER --password-stdin"
|
|
||||||
sh 'docker push nanajanashia/demo-app:jma-2.0'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("deploy") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo 'deploying the application...'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
[defaults]
|
|
||||||
host_key_checking = False
|
|
||||||
inventory = inventory_aws_ec2.yaml
|
|
||||||
|
|
||||||
interpreter_python = /usr/bin/python3
|
|
||||||
enable_plugins = aws_ec2
|
|
||||||
|
|
||||||
remote_user = ec2-user
|
|
||||||
private_key_file = ~/ssh-key.pem
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Install python3, docker, docker-compose
|
|
||||||
hosts: all
|
|
||||||
become: yes
|
|
||||||
gather_facts: False
|
|
||||||
tasks:
|
|
||||||
- name: Install python3 and docker
|
|
||||||
vars:
|
|
||||||
ansible_python_interpreter: /usr/bin/python
|
|
||||||
yum:
|
|
||||||
name:
|
|
||||||
- python3
|
|
||||||
- docker
|
|
||||||
update_cache: yes
|
|
||||||
state: present
|
|
||||||
- name: Install Docker-compose
|
|
||||||
get_url:
|
|
||||||
url: https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-{{lookup('pipe', 'uname -m')}}
|
|
||||||
dest: /usr/local/bin/docker-compose
|
|
||||||
mode: +x
|
|
||||||
- name: Start docker daemon
|
|
||||||
systemd:
|
|
||||||
name: docker
|
|
||||||
state: started
|
|
||||||
- name: Install docker python module
|
|
||||||
pip:
|
|
||||||
name:
|
|
||||||
- docker
|
|
||||||
- docker-compose
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
plugin: aws_ec2
|
|
||||||
regions:
|
|
||||||
- eu-west-3
|
|
||||||
keyed_groups:
|
|
||||||
- key: tags
|
|
||||||
prefix: tag
|
|
||||||
- key: instance_type
|
|
||||||
prefix: instance_type
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
apt update
|
|
||||||
apt install ansible -y
|
|
||||||
apt install python3-pip -y
|
|
||||||
pip3 install boto3 botocore
|
|
||||||
|
|
||||||
# export AWS_ACCESS_KEY_ID=$1
|
|
||||||
# export AWS_SECRET_ACCESS_KEY=$2
|
|
||||||
|
|
||||||
34
pom.xml
34
pom.xml
@@ -6,36 +6,34 @@
|
|||||||
|
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>java-maven-app</artifactId>
|
<artifactId>java-maven-app</artifactId>
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>2.3.5.RELEASE</version>
|
<version>2.8.2</version>
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
|
||||||
<!-- to handle any Java version mismatch, add the following configuration for maven-compiler-plugin -->
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>3.6.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>nexus-snapshots</id>
|
||||||
|
<url>http://167.99.248.163:8081/repository/maven-snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
11
src/main/resources/static/index.html
Normal file
11
src/main/resources/static/index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>MyApp</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welcome to Java Maven Application</h1>
|
||||||
|
<!-- add image here <img src="" width="" /> -->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user