-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
307 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.git | ||
dist | ||
docs | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
FROM node:10-alpine AS builder | ||
LABEL maintainer="[email protected]" | ||
ARG BUILD_USER="jenkins" | ||
# Installs latest Chromium package | ||
RUN echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \ | ||
&& echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \ | ||
&& apk add --no-cache \ | ||
chromium@edge \ | ||
harfbuzz@edge \ | ||
nss@edge \ | ||
freetype@edge \ | ||
ttf-freefont@edge \ | ||
git \ | ||
&& rm -rf /var/cache/* \ | ||
&& mkdir /var/cache/apk | ||
ENV CHROME_BIN /usr/bin/chromium-browser | ||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true | ||
RUN adduser -D -u 10000 -h /ci ${BUILD_USER} | ||
RUN chown ${BUILD_USER}: /ci -R | ||
USER ${BUILD_USER} | ||
WORKDIR /ci | ||
LABEL stage=builder | ||
|
||
# Setup dependencies | ||
FROM builder as dependencies | ||
COPY package.json package-lock.json ./ | ||
RUN npm set progress=false \ | ||
&& npm config set depth 0 | ||
RUN npm ci | ||
COPY --chown=10000 . . | ||
ARG CACHEBUST=1 | ||
RUN echo "Rebuild from here (unique number: $CACHEBUST)" | ||
LABEL stage=buildenv | ||
|
||
# Run unit tests | ||
FROM dependencies AS test | ||
ARG linting=false | ||
ARG testing=false | ||
RUN [ "$linting" != true ] || npm run lint | ||
RUN [ "$testing" != true ] || npm run test -- --watch=false --browsers=ChromeHeadlessCI --reporters=junit | ||
LABEL stage=test | ||
|
||
# Build application | ||
FROM dependencies AS build | ||
RUN npm run build -- --progress=false | ||
LABEL stage=build | ||
|
||
# Release to NPM | ||
FROM dependencies AS release | ||
ARG releaseProjectName='gentics-ui-core' | ||
ARG release=false | ||
ARG releaseNext=false | ||
ARG releaseVersion='' | ||
RUN sh ci/release.sh | ||
LABEL stage=release | ||
|
||
# Publish Docs on Github Pages | ||
FROM dependencies AS docs | ||
ARG GIT_BRANCH='' | ||
ARG publishDocs=false | ||
ARG docsVersion='' | ||
RUN sh ci/publishDocs.sh | ||
LABEL stage=docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// The GIT repository for this pipeline lib is defined in the global Jenkins setting | ||
@Library('jenkins-pipeline-library') | ||
import com.gentics.* | ||
|
||
// Make the helpers aware of this jobs environment | ||
JobContext.set(this) | ||
|
||
pipeline { | ||
agent { | ||
kubernetes { | ||
label env.BUILD_TAG | ||
defaultContainer 'build' | ||
yaml """ | ||
apiVersion: v1 | ||
kind: Pod | ||
spec: | ||
nodeSelector: | ||
jenkins_worker: true | ||
volumes: | ||
- name: cache | ||
hostPath: | ||
path: /opt/kubernetes/cache | ||
containers: | ||
- name: build | ||
image: docker:18 | ||
imagePullPolicy: Always | ||
command: | ||
- cat | ||
tty: true | ||
resources: | ||
requests: | ||
cpu: 2 | ||
memory: 4Gi | ||
env: | ||
- name: DOCKER_HOST | ||
value: tcp://127.0.0.1:2375 | ||
volumeMounts: | ||
- mountPath: /root/.npm/_cacache | ||
name: cache | ||
subPath: npm/_cacache | ||
- name: docker | ||
image: docker:18-dind | ||
imagePullPolicy: Always | ||
args: | ||
- '--storage-driver=overlay2' | ||
securityContext: | ||
privileged: true | ||
tty: true | ||
imagePullSecrets: | ||
- name: docker-jenkinsbuilds-apa-it | ||
""" | ||
} | ||
} | ||
|
||
environment { | ||
VERSION_CONSTRAINT = /^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/ | ||
} | ||
|
||
options { | ||
gitLabConnection('git.gentics.com') | ||
gitlabBuilds(builds: ['Jenkins build']) | ||
timestamps() | ||
timeout(time: 1, unit: 'HOURS') | ||
ansiColor('xterm') | ||
} | ||
|
||
parameters { | ||
booleanParam(name: 'linting', defaultValue: false, description: 'Whether to run linting') | ||
booleanParam(name: 'testing', defaultValue: true, description: 'Whether to run unit tests') | ||
string(name: 'releaseVersion', defaultValue: '', description: 'Version must comply with semver, a tag will be created, cannot be the same as in package.json') | ||
booleanParam(name: 'release', defaultValue: false, description: "Whether to run the release steps") | ||
booleanParam(name: 'releaseNext', defaultValue: false, description: "Whether release as an upcoming version") | ||
booleanParam(name: 'publishDocs', defaultValue: false, description: 'Build docs app and uploads to Github Pages') | ||
string(name: 'docsVersion', defaultValue: '', description: 'If empty, its auto-detected, otherwise version of the maintenance documentation') | ||
} | ||
|
||
stages { | ||
stage('Clone Github Pages') { | ||
when { | ||
beforeAgent true | ||
expression { | ||
return params.publishDocs | ||
} | ||
} | ||
|
||
steps { | ||
dir('docs') { | ||
git branch: 'gh-pages', | ||
credentialsId: 'git', | ||
url: env.GIT_URL | ||
} | ||
} | ||
} | ||
|
||
stage('Docker build') { | ||
when { | ||
beforeAgent true | ||
expression { | ||
isValidVersion = params.releaseVersion.trim() =~ env.VERSION_CONSTRAINT || params.releaseVersion == '' | ||
return isValidVersion | ||
} | ||
} | ||
|
||
steps { | ||
sh """docker build -f ci/Dockerfile \ | ||
--build-arg linting=${params.linting} \ | ||
--build-arg testing=${params.testing} \ | ||
--build-arg release=${params.release} \ | ||
--build-arg releaseNext=${params.releaseNext} \ | ||
--build-arg releaseVersion=${params.releaseVersion} \ | ||
--build-arg publishDocs=${params.publishDocs} \ | ||
--build-arg docsVersion=${params.docsVersion} \ | ||
--build-arg GIT_BRANCH=${env.GIT_BRANCH} \ | ||
--build-arg CACHEBUST=\$(date +%s) \ | ||
. | ||
""" | ||
} | ||
} | ||
|
||
stage('Publish Docs to Github Pages') { | ||
when { | ||
expression { | ||
return params.publishDocs | ||
} | ||
} | ||
|
||
steps { | ||
echo "Now it should publish..." | ||
} | ||
} | ||
} | ||
|
||
post { | ||
always { | ||
//updateGitlabCommitCurrentBuildStatus name: 'Jenkins build' | ||
notifyMattermostUsers() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
# This should be before set -o errexit! | ||
MAINTPREFIX="maintenance-v[0-9][\.x0-9]+" | ||
isMaintenanceBranch=$(echo "$GIT_BRANCH" | grep -Eq "$MAINTPREFIX"; echo $?) | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
|
||
if [ "$publishDocs" == true ] | ||
then | ||
PARAMS="" | ||
|
||
if [ -z "$docsVersion" ] && [ ! -z "$GIT_BRANCH" ] && [ $isMaintenanceBranch -eq 0 ] | ||
then | ||
docsVersion=$(echo "$GIT_BRANCH" | cut -d '-' -f 2) | ||
fi | ||
|
||
if [ ! -z "$docsVersion" ] | ||
then | ||
PARAMS="$PARAMS --docsVersion=${docsVersion}" | ||
fi | ||
|
||
echo "Will publishes docs part... (PARAMS: $PARAMS)" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
WORKDIR="$PWD" | ||
|
||
if [ "$release" == true ] | ||
then | ||
if [ ! -z "$releaseVersion" ] | ||
then | ||
cd "/ci/projects/$releaseProjectName/" | ||
npm version "$releaseVersion" | ||
cd "$WORKDIR" | ||
fi | ||
|
||
npm run build -- "$releaseProjectName" | ||
|
||
if [ "$releaseNext" == true ] | ||
then | ||
npm publish --dry-run --tag next "/ci/dist/$releaseProjectName" | ||
else | ||
npm publish --dry-run "/ci/dist/$releaseProjectName" | ||
fi | ||
fi |
Oops, something went wrong.