Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
fix(Jenkinsfile): Build preview Docker image and Helm chart
Browse files Browse the repository at this point in the history
fix(Jenkinsfile): Enabled Skaffold to build preview Docker image
  • Loading branch information
igdianov committed Feb 4, 2020
1 parent c9fc4a6 commit e48d987
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 37 deletions.
50 changes: 33 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pipeline {
environment {
ORG = 'activiti'
APP_NAME = 'activiti-cloud-audit'
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
RELEASE_BRANCH = "master"
GITHUB_CHARTS_REPO = "https://github.com/Activiti/activiti-cloud-helm-charts.git"
GITHUB_HELM_REPO_URL = "https://activiti.github.io/activiti-cloud-helm-charts/"
}
Expand All @@ -21,40 +23,42 @@ pipeline {
branch 'PR-*'
}
environment {
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
VERSION = maven_project_version().replaceAll("SNAPSHOT","$BRANCH_NAME-$BUILD_NUMBER-SNAPSHOT")
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
}
steps {
container('maven') {
sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
sh "mvn versions:set -DnewVersion=$VERSION"
sh "mvn install"
// sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml'
sh 'export VERSION=$VERSION && skaffold build -f skaffold.yaml'

// skip building docker image for now
// sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
// sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION"


// dir("./charts/$APP_NAME") {
// sh "make build"
// }
dir("./charts/$APP_NAME") {
sh "make preview"
}
}
}
}
stage('Build Release') {
when {
branch 'master'
branch "$RELEASE_BRANCH"
}
environment {
VERSION = jx_release_version()
}
steps {
container('maven') {
// ensure we're not on a detached head
sh "git checkout master"
sh "git checkout $RELEASE_BRANCH"
sh "git config --global credential.helper store"

sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
sh "echo $VERSION > VERSION"
sh "mvn versions:set -DnewVersion=$VERSION"

dir ("./charts/$APP_NAME") {
retry(5) {
Expand All @@ -63,28 +67,28 @@ pipeline {
}
sh 'mvn clean deploy'

sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml'
sh "export VERSION=$VERSION && skaffold build -f skaffold.yaml"

sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION"
}
}
}
stage('Promote to Environments') {
when {
branch 'master'
branch "$RELEASE_BRANCH"
}
steps {
container('maven') {
dir ("./charts/$APP_NAME") {
// sh 'jx step changelog --version v\$(cat ../../VERSION)'
// sh "jx step changelog --version v$VERSION"

// release the helm chart
sh 'make release'
retry(5) {
sh 'make github'
}
// promote through all 'Auto' promotion Environments
// sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION) --no-wait'
// sh "jx promote -b --all-auto --timeout 1h --version $VERSION --no-wait"
sh 'jx step git credentials'
sh 'sleep 10'
retry(2) {
Expand All @@ -110,3 +114,15 @@ pipeline {
}
}
}

def jx_release_version() {
container('maven') {
return sh( script: "echo \$(jx-release-version)", returnStdout: true).trim()
}
}

def maven_project_version() {
container('maven') {
return sh( script: "echo \$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -f pom.xml)", returnStdout: true).trim()
}
}
43 changes: 23 additions & 20 deletions charts/activiti-cloud-audit/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#CHART_REPO := http://jenkins-x-chartmuseum:8080
CHART_REPO := $(or $(CHART_REPO),jenkins-x-chartmuseum:8080)
CURRENT=$(shell pwd)
NAME := activiti-cloud-audit
ORG := $(or $(ORG),activiti)
APP_NAME := $(or $(APP_NAME),$(NAME))
OS := $(shell uname)
RELEASE_VERSION := $(shell cat ../../VERSION)
RELEASE_VERSION := $(or $(VERSION),$(shell cat ../../VERSION))
RELEASE_ARTIFACT := $(or $(RELEASE_ARTIFACT),$(APP_NAME))

GITHUB_CHARTS_REPO := $(or $(GITHUB_CHARTS_REPO),$(shell git config --get remote.origin.url))
Expand All @@ -17,9 +17,18 @@ build: clean
helm repo add activiti-cloud-helm-charts https://activiti.github.io/activiti-cloud-helm-charts/
helm dependency build
helm lint
helm install . --name ${NAME} --debug --dry-run

install: build
dry-run:
helm upgrade ${HELM_RELEASE} . --install --debug --dry-run

$(NAME)-$(RELEASE_VERSION).tgz: build
helm package .

package: $(NAME)-$(RELEASE_VERSION).tgz

preview: version package dry-run release

install: build dry-run
helm install . --name ${NAME}

upgrade: clean build
Expand All @@ -33,10 +42,10 @@ clean:
rm -rf charts
rm -rf ${NAME}*.tgz

release: build
helm package .
# curl -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts
# rm -rf ${NAME}*.tgz%
release: package
curl -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(RELEASE_VERSION).tgz" $(CHART_REPO)/api/charts
rm -rf ${NAME}*.tgz%

push:
for i in {0..20}; do \
cd $(GITHUB_CHARTS_DIR) && \
Expand All @@ -58,18 +67,12 @@ github:
$(MAKE) push
rm -rf $(GITHUB_CHARTS_DIR)

tag:
ifeq ($(OS),Darwin)
sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
sed -i "" -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
else ifeq ($(OS),Linux)
sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)/$(ORG)/$(APP_NAME)|" values.yaml
sed -i -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
else
echo "platfrom $(OS) not supported to release from"
exit -1
endif
version:
sed -i -e "s/version:.*/version: $(VERSION)/" Chart.yaml
sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)/$(ORG)/$(NAME)|" values.yaml
sed -i -e "s/tag: .*/tag: $(VERSION)/" values.yaml

tag: version
git add --all
git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed
git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)"
Expand Down

0 comments on commit e48d987

Please sign in to comment.