Skip to content
Snippets Groups Projects
Commit ee9231e5 authored by Christopher Guindon's avatar Christopher Guindon
Browse files

Initial k8s descriptors


Signed-off-by: Christopher Guindon's avatarChristopher Guindon <chris.guindon@eclipse-foundation.org>
parent cffc9139
No related branches found
No related tags found
No related merge requests found
@Library('common-shared') _
pipeline {
agent {
kubernetes {
label 'kubedeploy-agent'
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: kubectl
image: eclipsefdn/kubectl:1.9-alpine
command:
- cat
tty: true
'''
}
}
environment {
APP_NAME = 'marketplace-rest-api'
NAMESPACE = 'foundation-internal-webdev-apps'
IMAGE_NAME = 'eclipsefdn/marketplace-rest-api'
CONTAINER_NAME = 'app'
ENVIRONMENT = sh(
script: """
if [ "${env.BRANCH_NAME}" = "master" ]; then
printf "production"
else
printf "${env.BRANCH_NAME}"
fi
""",
returnStdout: true
)
TAG_NAME = sh(
script: """
GIT_COMMIT_SHORT=\$(git rev-parse --short ${env.GIT_COMMIT})
if [ "${env.ENVIRONMENT}" = "" ]; then
printf \${GIT_COMMIT_SHORT}-${env.BUILD_NUMBER}
else
printf ${env.ENVIRONMENT}-\${GIT_COMMIT_SHORT}-${env.BUILD_NUMBER}
fi
""",
returnStdout: true
)
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
}
triggers {
// build once a week to keep up with parents images updates
cron('H H * * H')
}
stages {
stage('Build docker image') {
agent {
label 'docker-build'
}
steps {
sh '''
./mvnw package
docker build -f src/main/docker/Dockerfile.jvm --no-cache -t ${IMAGE_NAME}:${TAG_NAME} -t ${IMAGE_NAME}:latest .
'''
}
}
stage('Push docker image') {
agent {
label 'docker-build'
}
when {
anyOf {
environment name: 'ENVIRONMENT', value: 'production'
environment name: 'ENVIRONMENT', value: 'staging'
}
}
steps {
withDockerRegistry([credentialsId: '04264967-fea0-40c2-bf60-09af5aeba60f', url: 'https://index.docker.io/v1/']) {
sh '''
docker push ${IMAGE_NAME}:${TAG_NAME}
docker push ${IMAGE_NAME}:latest
'''
}
}
}
stage('Deploy to cluster') {
when {
anyOf {
environment name: 'ENVIRONMENT', value: 'production'
environment name: 'ENVIRONMENT', value: 'staging'
}
}
steps {
container('kubectl') {
withKubeConfig([credentialsId: '1d8095ea-7e9d-4e94-b799-6dadddfdd18a', serverUrl: 'https://console-int.c1-ci.eclipse.org']) {
sh '''
DEPLOYMENT="$(k8s getFirst deployment "${NAMESPACE}" "app=${APP_NAME},environment=${ENVIRONMENT}")"
if [[ $(echo "${DEPLOYMENT}" | jq -r 'length') -eq 0 ]]; then
echo "ERROR: Unable to find a deployment to patch matching 'app=${APP_NAME},environment=${ENVIRONMENT}' in namespace ${NAMESPACE}"
exit 1
else
DEPLOYMENT_NAME="$(echo "${DEPLOYMENT}" | jq -r '.metadata.name')"
kubectl set image "deployment.v1.apps/${DEPLOYMENT_NAME}" -n "${NAMESPACE}" "${CONTAINER_NAME}=${IMAGE_NAME}:${TAG_NAME}" --record=true
if ! kubectl rollout status "deployment.v1.apps/${DEPLOYMENT_NAME}" -n "${NAMESPACE}"; then
# will fail if rollout does not succeed in less than .spec.progressDeadlineSeconds
kubectl rollout undo "deployment.v1.apps/${DEPLOYMENT_NAME}" -n "${NAMESPACE}"
exit 1
fi
fi
'''
}
}
}
}
}
post {
always {
deleteDir() /* clean up workspace */
sendNotifications currentBuild
}
}
}
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: marketplace-rest-api
namespace: webapps
spec:
selector:
matchLabels:
app: marketplace-rest-api
replicas: 2
template:
metadata:
labels:
app: marketplace-rest-api
environment: production
spec:
containers:
- name: app
image: eclipsefdn/marketplace-rest-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
resources:
limits:
cpu: '2'
memory: 2048Mi
requests:
cpu: 200m
memory: 2048Mi
---
apiVersion: "v1"
kind: "Service"
metadata:
name: marketplace-rest-api
namespace: webapps
spec:
ports:
- name: "http"
port: 80
protocol: "TCP"
targetPort: 8080
selector:
app: marketplace-rest-api
environment: production
---
apiVersion: "route.openshift.io/v1"
kind: "Route"
metadata:
name: marketplace-rest-api
namespace: webapps
annotations:
haproxy.router.openshift.io/timeout: 20s
spec:
host: "api.eclipse.org"
path: "/marketplace"
port:
targetPort: "http"
tls:
insecureEdgeTerminationPolicy: "Redirect"
termination: "edge"
to:
kind: "Service"
name: marketplace-rest-api
weight: 100
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: marketplace-rest-api
namespace: webapps
spec:
selector:
matchLabels:
app: marketplace-rest-api
replicas: 2
template:
metadata:
labels:
app: marketplace-rest-api
environment: staging
spec:
containers:
- name: app
image: eclipsefdn/marketplace-rest-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
resources:
limits:
cpu: '2'
memory: 2048Mi
requests:
cpu: 200m
memory: 2048Mi
---
apiVersion: "v1"
kind: "Service"
metadata:
name: marketplace-rest-api
namespace: webapps
spec:
ports:
- name: "http"
port: 80
protocol: "TCP"
targetPort: 8080
selector:
app: marketplace-rest-api
environment: staging
---
apiVersion: "route.openshift.io/v1"
kind: "Route"
metadata:
name: marketplace-rest-api
namespace: webapps
annotations:
haproxy.router.openshift.io/timeout: 20s
spec:
host: "api-staging.eclipse.org"
path: "/marketplace"
port:
targetPort: "http"
tls:
insecureEdgeTerminationPolicy: "Redirect"
termination: "edge"
to:
kind: "Service"
name: marketplace-rest-api
weight: 100
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment