Commit b9635fa0 authored by Christopher Guindon's avatar Christopher Guindon
Browse files
parent 91898d96
ARG NGINX_IMAGE_TAG=stable-alpine-for-hugo
FROM debian:10-slim AS builder
ARG HUGO_VERSION=0.76.5
ARG NODE_VERSION=10.15.0
RUN apt-get update && apt-get install -y \
build-essential \
ca-certificates \
curl \
git \
--no-install-recommends
RUN curl -L -o /tmp/node.tar.xz "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" \
&& mkdir -p /usr/local/lib/nodejs \
&& tar -xJf /tmp/node.tar.xz -C /usr/local/lib/nodejs \
&& ln -s /usr/local/lib/nodejs/node-v${NODE_VERSION}-linux-x64/bin/node /usr/bin/node \
&& ln -s /usr/local/lib/nodejs/node-v${NODE_VERSION}-linux-x64/bin/npm /usr/bin/npm \
&& ln -s /usr/local/lib/nodejs/node-v${NODE_VERSION}-linux-x64/bin/npx /usr/bin/npx
RUN curl -L -o /tmp/hugo.deb "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.deb" \
&& dpkg -i /tmp/hugo.deb
WORKDIR /workdir
COPY . /workdir/
RUN echo -n "Node.js version " && node --version \
&& echo -n "npm version " && npm --version \
&& hugo version
RUN npm --unsafe-perm ci \
&& hugo
FROM eclipsefdn/nginx:${NGINX_IMAGE_TAG}
COPY --from=builder /workdir/public/ /usr/share/nginx/html/
@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
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: '10.15.3', 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 = 'openmdm.org'
NAMESPACE = 'foundation-internal-webdev-apps'
IMAGE_NAME = 'eclipsefdn/openmdm.org'
CONTAINER_NAME = 'nginx'
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
)
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="${hugo_version}" --build-arg NODE_VERSION="${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: '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 "${resource}" | jq -r 'length') -eq 0 ]]; then
echo "ERROR: Unable to find a deployment to patch matching '${selector}' 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
}
}
}
apiVersion: apps/v1
kind: Deployment
metadata:
name: openmdm.org
namespace: foundation-internal-webdev-apps
spec:
selector:
matchLabels:
app: openmdm.org
environment: production
replicas: 2
template:
metadata:
labels:
app: openmdm.org
environment: production
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: speed
operator: NotIn
values:
- fast
weight: 1
containers:
- name: nginx
image: eclipsefdn/openmdm.org
ports:
- containerPort: 8080
resources:
limits:
cpu: '2'
memory: 512Mi
requests:
cpu: 200m
memory: 256Mi
---
apiVersion: "v1"
kind: "Service"
metadata:
name: openmdm-org
namespace: foundation-internal-webdev-apps
spec:
ports:
- name: "http"
port: 80
protocol: "TCP"
targetPort: 8080
selector:
app: openmdm.org
environment: production
---
apiVersion: "route.openshift.io/v1"
kind: "Route"
metadata:
name: openmdm.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: "openmdm.org"
path: "/"
port:
targetPort: "http"
tls:
insecureEdgeTerminationPolicy: "Redirect"
termination: "edge"
to:
kind: "Service"
name: openmdm-org
weight: 100
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: staging.openmdm.org
namespace: foundation-internal-webdev-apps
spec:
selector:
matchLabels:
app: openmdm.org
environment: staging
replicas: 1
template:
metadata:
labels:
app: openmdm.org
environment: staging
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: speed
operator: NotIn
values:
- fast
weight: 1
containers:
- name: nginx
image: eclipsefdn/openmdm.org
ports:
- containerPort: 8080
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 200m
memory: 64Mi
---
apiVersion: "v1"
kind: "Service"
metadata:
name: lts-staging-eclipse-org
namespace: foundation-internal-webdev-apps
spec:
ports:
- name: "http"
port: 80
protocol: "TCP"
targetPort: 8080
selector:
app: openmdm.org
environment: staging
---
apiVersion: "route.openshift.io/v1"
kind: "Route"
metadata:
name: staging.openmdm.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: "staging.openmdm.org"
path: "/"
port:
targetPort: "http"
tls:
insecureEdgeTerminationPolicy: "Redirect"
termination: "edge"
to:
kind: "Service"
name: staging-openmdm-org
weight: 100
\ No newline at end of file
[build]
publish = "public"
command = "npm run build_netlify && hugo --gc --minify -b https://eclipsefdn-openmdm.netlify.com"
command = "npm run build_netlify && hugo --gc --minify"
[context.production.environment]
HUGO_VERSION = "0.76.5"
......@@ -28,3 +28,8 @@ HUGO_VERSION = "0.76.5"
[context.next.environment]
HUGO_ENABLEGITINFO = "true"
[[redirects]]
from = "https://community.openmdm.org"
to = "/"
status = 302
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment