Skip to content

Commit

Permalink
Merge pull request #3 from garystafford/h2
Browse files Browse the repository at this point in the history
Merge H2 Feature Branch Changes to Master
  • Loading branch information
garystafford authored Apr 27, 2018
2 parents 53b76c1 + 4866380 commit ea303e5
Show file tree
Hide file tree
Showing 24 changed files with 326 additions and 151 deletions.
1 change: 0 additions & 1 deletion .idea/modules/spring-postgresql-demo_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 59 additions & 59 deletions Jenkins/ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,67 @@
def PROJECT_NAME = "spring-postgresql-demo"

pipeline {
agent any
tools {
gradle 'gradle'
}
stages {
stage('Checkout GitHub') {
steps {
git changelog: true, poll: true,
branch: 'h2',
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Build') {
steps {
sh 'gradle wrapper'
sh './gradlew clean build -x test'
}
}
stage('Unit Test') {
steps {
withEnv(['SPRING_DATASOURCE_URL=jdbc:h2:file:~/elections']) {
sh './gradlew cleanTest test'
}
junit '**/build/test-results/test/*.xml'
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('Local SonarQube') {
sh "./gradlew sonarqube -Dsonar.projectName=${PROJECT_NAME}"
agent any
tools {
gradle 'gradle'
}
}
}
stage('Archive Artifact') {
steps {
archiveArtifacts 'build/libs/*.jar'
}
}
stage('Publish Artifact') {
steps {
withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) {
dir('build/libs/') {
sh "git init \
&& git config user.name \"jenkins-ci\" \
&& git config user.email \"jenkins-ci@jenkins-ci.com\" \
&& git add *.jar \
stages {
stage('Checkout GitHub') {
steps {
git changelog: true, poll: true,
branch: 'master',
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Build') {
steps {
sh 'gradle wrapper'
sh './gradlew clean build -x test'
}
}
stage('Unit Test') { // unit test against h2
steps {
withEnv(['SPRING_DATASOURCE_URL=jdbc:h2:file:~/elections']) {
sh './gradlew cleanTest test'
}
junit '**/build/test-results/test/*.xml'
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonarqube') {
sh "./gradlew sonarqube -Dsonar.projectName=${PROJECT_NAME}"
}
}
}
stage('Archive Artifact') { // option 1 to build Dockerfile in next pipeline
steps {
archiveArtifacts 'build/libs/*.jar'
}
}
stage('Publish Artifact') { // option 2 to build Dockerfile in next pipeline
steps {
withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) {
dir('build/libs/') {
sh "git init \
&& git config user.name \"jenkins-ci\" \
&& git config user.email \"jenkins-ci@jenkins-ci.com\" \
&& git add *.jar \
&& git commit -m \"Publish build artifact\" \
&& git push --force --quiet --progress \
&& git push --force --quiet --progress \
\"https://x-access-token:${GIT_TOKEN}@github.com/garystafford/${PROJECT_NAME}.git\" \
master:build-artifacts-gke"
}
master:build-artifacts-gke"
}
}
}
}
}
post {
success {
slackSend(color: '#008000', message: "SUCCESS: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
failure {
slackSend(color: '#FF0000', message: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
}
}
}
}
post {
success {
slackSend(color: '#008000', message: "SUCCESS: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
failure {
slackSend(color: '#FF0000', message: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
}
}
67 changes: 35 additions & 32 deletions Jenkins/docker/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,43 @@

def DOCKER_HUB_ACCOUNT = "garystafford"
def PROJECT_NAME = "spring-postgresql-demo"
// def IMAGE_TAG = "2.1.0"

pipeline {
agent any
parameters {
string defaultValue: 'latest',
description: 'Tag applied to new Docker Image',
name: 'IMAGE_TAG', trim: true
}
stages {
stage('Checkout GitHub') {
steps {
git changelog: true, poll: true,
branch: 'h2',
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Build Image') {
steps {
copyArtifacts filter: 'build/libs/*.jar', fingerprintArtifacts: true,
flatten: true, projectName: 'election-ci', selector: lastSuccessful(),
target: 'docker/'
withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB',
usernameVariable: 'DOCKER_HUB_USERNAME',
passwordVariable: 'DOCKER_HUB_PASSWORD')]) {
sh "docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD}"
agent any
parameters {
string defaultValue: 'latest',
description: 'Tag applied to new Docker Image',
name: 'IMAGE_TAG', trim: true
}
dir('docker') {
// sh 'ls -al'
sh 'docker version'
sh "docker build --file Dockerfile_Jenkins --no-cache --tag ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG} ."
sh "docker push ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG}"
stages {
stage('Checkout GitHub') {
steps {
git changelog: true, poll: false,
branch: 'master',
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Build Image') { // uses option 1 from ci job to build Dockerfile
steps {
copyArtifacts filter: 'build/libs/*.jar', fingerprintArtifacts: true,
flatten: true, projectName: 'election-ci', selector: lastSuccessful(),
target: 'docker/'
withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB',
usernameVariable: 'DOCKER_HUB_USERNAME',
passwordVariable: 'DOCKER_HUB_PASSWORD')]) {
sh "docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD}"
}
dir('docker') {
sh "docker build --file Dockerfile_Jenkins --no-cache --tag ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG} ."
}
}
}
stage('Push Image') {
steps {
dir('docker') {
sh "docker push ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG}"
}
}
}
}
}
}
}
}
57 changes: 29 additions & 28 deletions Jenkins/integration/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@
def PROJECT_NAME = "spring-postgresql-demo"

pipeline {
agent any
stages {
stage('Checkout SCM') {
steps {
git changelog: true, poll: false,
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Smoke Tests') {
steps {
dir('postman') {
nodejs('nodejs') {
sh 'sh newman-smoke-tests-minikube.sh'
}
junit '**/newman/*.xml'
agent any
stages {
stage('Checkout SCM') {
steps {
git changelog: true, poll: false,
branch: 'master',
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Smoke Tests') {
steps {
dir('postman') {
nodejs('nodejs') {
sh 'sh newman-smoke-tests-minikube.sh'
}
junit '**/newman/*.xml'
}
}
}
stage('Integration Tests') {
steps {
dir('postman') {
nodejs('nodejs') {
sh 'sh newman-integration-tests-minikube.sh'
}
junit '**/newman/*.xml'
}
}
}
}
}
}
stage('Integration Tests') {
steps {
dir('postman') {
nodejs('nodejs') {
sh 'sh newman-integration-tests-minikube.sh'
}
junit '**/newman/*.xml'
}
}
}
}
}
59 changes: 59 additions & 0 deletions Jenkins/k8s-demo-deploy/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!groovy

def PROJECT_NAME = "spring-postgresql-demo"

pipeline {
agent any
stages {
stage('Checkout GitHub') {
steps {
git changelog: true, poll: false,
branch: 'master',
url: "https://github.com/garystafford/${PROJECT_NAME}"
}
}
stage('Get Cluster Creds') {
steps {
dir('kubernetes') {
sh 'sh ./part1b-get-cluster-creds.sh'
}
}
}
stage('Build Environments') { // dev, test, uat
steps {
dir('kubernetes') {
sh 'sh ./part2-create-environments.sh'
}
}
}
stage('Deploy Postgres to dev') { // doesn't work with istio!
steps {
dir('kubernetes') {
sh 'sh ./deploy-postgres-gke-dev.sh'
}
}
}
stage('Deploy Election v1 to dev') {
environment { // get cluster ip ranges for deploy script
IP_RANGES = sh(returnStdout: true,
script: 'sh ./kubernetes/get-cluster-ip-ranges.sh')
}
steps {
dir('kubernetes') {
sh 'env | sort'
sh 'sh ./part3a-deploy-v1-dev.sh'
}
}
}
stage('Smoke Test') { // assumes 'api.dev.voter-demo.com' reachable
steps {
dir('postman') {
nodejs('nodejs') {
sh 'sh newman-smoke-tests-minikube.sh'
}
junit '**/newman/*.xml'
}
}
}
}
}
9 changes: 0 additions & 9 deletions docker/docker-build-push-v1.0.0.sh

This file was deleted.

6 changes: 6 additions & 0 deletions docker/docker-build-push-v1.1.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# docker login --username <username> --password <password>

docker build --no-cache -t garystafford/spring-postgresql-demo:1.1.0 .
docker push garystafford/spring-postgresql-demo:1.1.0
6 changes: 5 additions & 1 deletion kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Kubernetes Installation
# Kubernetes Installation Notes

## Amazon RDS

Expand All @@ -15,3 +15,7 @@ aws rds delete-db-instance \
--db-instance-identifier elections-dev \
--skip-final-snapshot
```

```bash
kubectl -n dev run curl --image=radial/busyboxplus:curl -i --tty
```
12 changes: 12 additions & 0 deletions kubernetes/deploy-postgres-gke-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# deploy postgres within cluster vs. external postgres (i.e. AWS)

# set -x

# postgresql in a pod
kubectl apply -f ./postgres-local/postgres-deployment.yaml -n dev

kubectl apply -f ./postgres-local/postgres-service.yaml -n dev

kubectl get pods -n dev
4 changes: 2 additions & 2 deletions kubernetes/deployments/election-deployment-v1-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ spec:
spec:
containers:
- name: election-v1
image: garystafford/spring-postgresql-demo:1.0.0
image: garystafford/spring-postgresql-demo:1.1.0
env:
- name: SPRING_PROFILES_ACTIVE
value: dev
- name: SPRING_DATASOURCE_HIKARI_MAXIMUM-POOL-SIZE
value: 2
value: '2'
- name: SPRING_DATASOURCE_URL
valueFrom:
secretKeyRef:
Expand Down
Loading

0 comments on commit ea303e5

Please sign in to comment.