Compare commits
6 Commits
jenkins-jo
...
deploy-to-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2a8032539 | ||
|
|
61b3c16c60 | ||
|
|
0a40971e52 | ||
|
|
ba11b6ecc8 | ||
|
|
127fe8818c | ||
|
|
322a9fb1b9 |
31
Jenkinsfile
vendored
Normal file
31
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env groovy
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
stages {
|
||||||
|
stage('build app') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "building the application..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('build image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "building the docker image..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('deploy') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo 'deploying docker image...'
|
||||||
|
withKubeConfig([credentialsId: 'lke-credentials', serverUrl: 'https://79fa9228-1d11-47ec-870b-33106d53122b.eu-central-2.linodelke.net']) {
|
||||||
|
sh 'kubectl create deployment nginx-deployment --image=nginx'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent none
|
|
||||||
stages {
|
|
||||||
stage('build') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "Building the application..."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('test') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "Testing the application..."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('deploy') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "Deploying the application..."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
75
Jenkinsfile-kubernetes/Jenkinsfile
vendored
75
Jenkinsfile-kubernetes/Jenkinsfile
vendored
@@ -1,75 +0,0 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
tools {
|
|
||||||
maven 'Maven'
|
|
||||||
}
|
|
||||||
environment {
|
|
||||||
DOCKER_REPO_SERVER = '664574038682.dkr.ecr.eu-west-3.amazonaws.com'
|
|
||||||
DOCKER_REPO = "${DOCKER_REPO_SERVER}/java-maven-app"
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage('increment version') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo 'incrementing app version...'
|
|
||||||
sh 'mvn build-helper:parse-version versions:set \
|
|
||||||
-DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.minorVersion}.\\\${parsedVersion.nextIncrementalVersion} \
|
|
||||||
versions:commit'
|
|
||||||
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
|
|
||||||
def version = matcher[0][1]
|
|
||||||
env.IMAGE_NAME = "$version-$BUILD_NUMBER"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('build app') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn clean package'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('build image') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "building the docker image..."
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'ecr-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
||||||
sh "docker build -t ${DOCKER_REPO}:${IMAGE_NAME} ."
|
|
||||||
sh "echo $PASS | docker login -u $USER --password-stdin ${DOCKER_REPO_SERVER}"
|
|
||||||
sh "docker push ${DOCKER_REPO}:${IMAGE_NAME}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('deploy') {
|
|
||||||
environment {
|
|
||||||
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
|
||||||
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
|
||||||
APP_NAME = 'java-maven-app'
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo 'deploying docker image...'
|
|
||||||
sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -'
|
|
||||||
sh 'envsubst < kubernetes/service.yaml | kubectl apply -f -'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('commit version update') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitlab-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
||||||
sh 'git config user.email "jenkins@example.com"'
|
|
||||||
sh 'git config user.name "Jenkins"'
|
|
||||||
sh "git remote set-url origin https://${USER}:${PASS}@gitlab.com/nanuchi/java-maven-app.git"
|
|
||||||
sh 'git add .'
|
|
||||||
sh 'git commit -m "ci: version bump"'
|
|
||||||
sh 'git push origin HEAD:jenkins-jobs'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
40
Jenkinsfile-simple-pipeline/Jenkinsfile
vendored
40
Jenkinsfile-simple-pipeline/Jenkinsfile
vendored
@@ -1,40 +0,0 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
def gv
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
tools {
|
|
||||||
maven 'Maven'
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage("init") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv = load "script.groovy"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("build jar") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv.buildJar()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("build image") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv.buildImage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("deploy") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv.deployApp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
def buildJar() {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn package'
|
|
||||||
}
|
|
||||||
|
|
||||||
def buildImage() {
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def deployApp() {
|
|
||||||
echo 'deploying the application...'
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
|
||||||
49
Jenkinsfile-syntax/Jenkinsfile
vendored
49
Jenkinsfile-syntax/Jenkinsfile
vendored
@@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
def gv
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
parameters {
|
|
||||||
choice(name: 'VERSION', choices: ['1.1.0', '1.2.0', '1.3.0'], description: '')
|
|
||||||
booleanParam(name: 'executeTests', defaultValue: true, description: '')
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage("init") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv = load "script.groovy"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("build") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv.buildApp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("test") {
|
|
||||||
when {
|
|
||||||
expression {
|
|
||||||
params.executeTests
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
gv.testApp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("deploy") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
env.ENV = input message: "Select the environment to deploy to", ok: "Done", parameters: [choice(name: 'ONE', choices: ['dev', 'staging', 'prod'], description: '')]
|
|
||||||
|
|
||||||
gv.deployApp()
|
|
||||||
echo "Deploying to ${ENV}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
def buildJar() {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn package'
|
|
||||||
}
|
|
||||||
|
|
||||||
def buildImage() {
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def deployApp() {
|
|
||||||
echo 'deploying the application...'
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
|
||||||
66
Jenkinsfile-version-increment/Jenkinsfile
vendored
66
Jenkinsfile-version-increment/Jenkinsfile
vendored
@@ -1,66 +0,0 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
tools {
|
|
||||||
maven 'Maven'
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage('increment version') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo 'incrementing app version...'
|
|
||||||
sh 'mvn build-helper:parse-version versions:set \
|
|
||||||
-DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.minorVersion}.\\\${parsedVersion.nextIncrementalVersion} \
|
|
||||||
versions:commit'
|
|
||||||
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
|
|
||||||
def version = matcher[0][1]
|
|
||||||
env.IMAGE_NAME = "$version-$BUILD_NUMBER"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('build app') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn clean 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:${IMAGE_NAME} ."
|
|
||||||
sh "echo $PASS | docker login -u $USER --password-stdin"
|
|
||||||
sh "docker push nanajanashia/demo-app:${IMAGE_NAME}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('deploy') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo 'deploying docker image to EC2...'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('commit version update') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitlab-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
||||||
// git config here for the first time run
|
|
||||||
sh 'git config --global user.email "jenkins@example.com"'
|
|
||||||
sh 'git config --global user.name "jenkins"'
|
|
||||||
|
|
||||||
sh "git remote set-url origin https://${USER}:${PASS}@gitlab.com/nanuchi/java-maven-app.git"
|
|
||||||
sh 'git add .'
|
|
||||||
sh 'git commit -m "ci: version bump"'
|
|
||||||
sh 'git push origin HEAD:jenkins-jobs'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
npm --version
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: $APP_NAME
|
|
||||||
labels:
|
|
||||||
app: $APP_NAME
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: $APP_NAME
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: $APP_NAME
|
|
||||||
spec:
|
|
||||||
imagePullSecrets:
|
|
||||||
- name: aws-registry-key
|
|
||||||
containers:
|
|
||||||
- name: $APP_NAME
|
|
||||||
image: $DOCKER_REPO:$IMAGE_NAME
|
|
||||||
imagePullPolicy: Always
|
|
||||||
ports:
|
|
||||||
- containerPort: 8080
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: $APP_NAME
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: $APP_NAME
|
|
||||||
ports:
|
|
||||||
- protocol: TCP
|
|
||||||
port: 80
|
|
||||||
targetPort: 8080
|
|
||||||
13
pom.xml
13
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>java-maven-app</artifactId>
|
<artifactId>java-maven-app</artifactId>
|
||||||
<version>1.1.7</version>
|
<version>1.1.4</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -22,17 +22,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- to handle any Java version mismatch, add the following configuration for maven-compiler-plugin -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
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>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Sat Dec 05 15:54:34 UTC 2020
|
#Sun Nov 29 08:01:35 UTC 2020
|
||||||
version=1.1.7
|
version=1.1.4
|
||||||
groupId=com.example
|
groupId=com.example
|
||||||
artifactId=java-maven-app
|
artifactId=java-maven-app
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Test set: AppTest
|
Test set: AppTest
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.099 sec
|
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.096 sec
|
||||||
|
|||||||
Reference in New Issue
Block a user