Skip to content
Snippets Groups Projects
Commit 1d76f84c authored by Mikaël Barbero's avatar Mikaël Barbero :dagger:
Browse files

Simplified CI

parent f73e1d8e
No related branches found
No related tags found
No related merge requests found
@Library('common-shared') _
pipeline {
agent {
kubernetes {
label 'kubedeploy-agent-' + env.JOB_NAME.replaceAll("/", "-")
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: kubectl
image: eclipsefdn/kubectl:1.18-alpine
command:
- cat
tty: true
resources:
limits:
cpu: 1
memory: 1Gi
- name: jnlp
resources:
limits:
cpu: 1
memory: 1Gi
'''
}
}
parameters {
string(name: 'hugo_version', defaultValue: '0.76.5', description: 'The Hugo version that will be used to build the website. Must match versions speficied on https://github.com/gohugoio/hugo/releases.')
string(name: 'node_version', defaultValue: '14.16.0', description: 'The Node.js version that will be used to build the website. Must match versions specified on https://nodejs.org/en/download/releases/. It is adivsed to stick to LTS versions.')
}
environment {
APP_NAME = 'asciidoc-wg.eclipse.org'
NAMESPACE = 'foundation-internal-webdev-apps'
IMAGE_NAME = 'eclipsefdn/asciidoc-wg.eclipse.org'
CONTAINER_NAME = 'nginx'
ENVIRONMENT = sh(
script: """
if [ "${env.BRANCH_NAME}" = "main" ]; 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
)
BASE_NGINX_IMAGE_TAG = sh(
script: """
if [ "${env.ENVIRONMENT}" = "production" ]; then
printf "stable-alpine-for-hugo"
else
printf "stable-alpine-for-staging"
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 '''
docker build --pull --build-arg NGINX_IMAGE_TAG="${BASE_NGINX_IMAGE_TAG}" --build-arg HUGO_VERSION="'''+params.hugo_version+'''" --build-arg NODE_VERSION="'''+params.node_version+'''" -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: '6ad93d41-e6fc-4462-b6bc-297e360784fd', serverUrl: 'https://api.okd-c1.eclipse.org:6443']) {
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
}
}
}
hugoWebsitePipeline appname: 'asciidoc-wg.eclipse.org'
local deployment = import "../../releng/hugo-websites/kube-deployment.jsonnet";
deployment.newProductionDeploymentWithStaging(
"asciidoc-wg.eclipse.org", "asciidoc-wg-staging.eclipse.org"
)
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: asciidoc-wg.eclipse.org
namespace: foundation-internal-webdev-apps
labels:
app: asciidoc-wg.eclipse.org
environment: production
spec:
selector:
matchLabels:
app: asciidoc-wg.eclipse.org
environment: production
replicas: 2
template:
metadata:
labels:
app: asciidoc-wg.eclipse.org
environment: production
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: speed
operator: NotIn
values:
- fast
weight: 1
containers:
- name: nginx
image: eclipsefdn/asciidoc-wg.eclipse.org
ports:
- containerPort: 8080
resources:
limits:
cpu: '2'
memory: 512Mi
requests:
cpu: 200m
memory: 256Mi
---
apiVersion: "v1"
kind: "Service"
metadata:
name: asciidoc-wg-eclipse-org
namespace: foundation-internal-webdev-apps
spec:
ports:
- name: "http"
port: 80
protocol: "TCP"
targetPort: 8080
selector:
app: asciidoc-wg.eclipse.org
environment: production
---
apiVersion: "route.openshift.io/v1"
kind: "Route"
metadata:
name: asciidoc-wg.eclipse.org
namespace: foundation-internal-webdev-apps
annotations:
haproxy.router.openshift.io/timeout: 20s
haproxy.router.openshift.io/disable_cookies: "true"
haproxy.router.openshift.io/balance: roundrobin
spec:
host: "asciidoc-wg.eclipse.org"
path: "/"
port:
targetPort: "http"
tls:
insecureEdgeTerminationPolicy: "Redirect"
termination: "edge"
to:
kind: "Service"
name: asciidoc-wg-eclipse-org
weight: 100
apiVersion: apps/v1
kind: Deployment
metadata:
name: asciidoc-wg-staging.eclipse.org
namespace: foundation-internal-webdev-apps
labels:
app: asciidoc-wg.eclipse.org
environment: staging
spec:
selector:
matchLabels:
app: asciidoc-wg.eclipse.org
environment: staging
replicas: 1
template:
metadata:
labels:
app: asciidoc-wg.eclipse.org
environment: staging
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: speed
operator: NotIn
values:
- fast
weight: 1
containers:
- name: nginx
image: eclipsefdn/asciidoc-wg.eclipse.org
ports:
- containerPort: 8080
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 200m
memory: 64Mi
---
apiVersion: "v1"
kind: "Service"
metadata:
name: asciidoc-wg-eclipse-org
namespace: foundation-internal-webdev-apps
spec:
ports:
- name: "http"
port: 80
protocol: "TCP"
targetPort: 8080
selector:
app: asciidoc-wg.eclipse.org
environment: staging
---
apiVersion: "route.openshift.io/v1"
kind: "Route"
metadata:
name: asciidoc-wg-staging.eclipse.org
namespace: foundation-internal-webdev-apps
annotations:
haproxy.router.openshift.io/timeout: 20s
haproxy.router.openshift.io/disable_cookies: "true"
haproxy.router.openshift.io/balance: roundrobin
spec:
host: "asciidoc-wg-staging.eclipse.org"
path: "/"
port:
targetPort: "http"
tls:
insecureEdgeTerminationPolicy: "Redirect"
termination: "edge"
to:
kind: "Service"
name: asciidoc-wg-eclipse-org
weight: 100
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