Skip to content

Commit 87ec276

Browse files
committed
first commit with dockerfile and build files
1 parent e127da3 commit 87ec276

File tree

6 files changed

+243
-0
lines changed

6 files changed

+243
-0
lines changed

.make-release-support

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2015 Xebia Nederland B.V.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
function hasChanges() {
18+
test -n "$(git status -s .)"
19+
}
20+
21+
function getRelease() {
22+
awk -F= '/^release=/{print $2}' .release
23+
}
24+
25+
function getBaseTag() {
26+
sed -n -e "s/^release=\(.*\)$(getRelease)\$/\1/p" .release
27+
}
28+
29+
function getTag() {
30+
if [ -z "$1" ] ; then
31+
awk -F= '/^release/{print $2}' .release
32+
else
33+
echo "$(getBaseTag)$1"
34+
fi
35+
}
36+
37+
function setRelease() {
38+
if [ -n "$1" ] ; then
39+
sed -i.x -e "s/^release=.*/release=$(getTag $1)/" .release
40+
sed -i.x -e "s/^release=.*/release=$1/g" .release
41+
rm -f .release.x
42+
runPreTagCommand "$1"
43+
else
44+
echo "ERROR: missing release version parameter " >&2
45+
return 1
46+
fi
47+
}
48+
49+
function runPreTagCommand() {
50+
if [ -n "$1" ] ; then
51+
COMMAND=$(sed -n -e "s/@@RELEASE@@/$1/g" -e 's/^pre_tag_command=\(.*\)/\1/p' .release)
52+
if [ -n "$COMMAND" ] ; then
53+
if ! OUTPUT=$(bash -c "$COMMAND" 2>&1) ; then echo $OUTPUT >&2 && exit 1 ; fi
54+
fi
55+
else
56+
echo "ERROR: missing release version parameter " >&2
57+
return 1
58+
fi
59+
}
60+
61+
function tagExists() {
62+
tag=${1:-$(getTag)}
63+
test -n "$tag" && test -n "$(git tag | grep "^$tag\$")"
64+
}
65+
66+
function differsFromRelease() {
67+
tag=$(getTag)
68+
! tagExists $tag || test -n "$(git diff --shortstat -r $tag .)"
69+
}
70+
71+
function getVersion() {
72+
result=$(getRelease)
73+
74+
if differsFromRelease; then
75+
result="$result-$(git log -n 1 --format=%h .)"
76+
fi
77+
78+
if hasChanges ; then
79+
result="$result-dirty"
80+
fi
81+
echo $result
82+
}
83+
84+
function nextPatchLevel() {
85+
version=${1:-$(getRelease)}
86+
gittag=$(git describe --abbrev=0 --tags) || gittag=-1;
87+
if [ "$version" = "$gittag" ]
88+
then
89+
primary_version=$(echo $version | cut -d- -f1)
90+
major_and_minor=$(echo $version | cut -d- -f2 | cut -d. -f1,2)
91+
patch=$(echo $version | cut -d- -f2 | cut -d. -f3)
92+
version=$(printf "%s-%s.%d" $primary_version $major_and_minor $(($patch + 1)))
93+
else
94+
primary_version=$(echo $version | cut -d- -f1)
95+
major_and_minor=$(echo $version | cut -d- -f2 | cut -d. -f1,2)
96+
patch=$(echo $version | cut -d- -f2 | cut -d. -f3)
97+
version=$(printf "%s-%s.%d" $primary_version $major_and_minor $(($patch)))
98+
fi
99+
echo $version
100+
}
101+
102+
function nextMinorLevel() {
103+
version=${1:-$(getRelease)}
104+
primary_version=$(echo $version | cut -d- -f1)
105+
major=$(echo $version | cut -d- -f2 | cut -d. -f1);
106+
minor=$(echo $version | cut -d- -f2 | cut -d. -f2)
107+
version=$(printf "%s-%d.%d.0" $primary_version $major $(($minor + 1))) ;
108+
echo $version
109+
}
110+
111+
function nextMajorLevel() {
112+
version=${1:-$(getRelease)}
113+
primary_version=$(echo $version | cut -d- -f1)
114+
major=$(echo $version | cut -d- -f2 | cut -d. -f1);
115+
version=$(printf "%s-%d.0.0" $primary_version $(($major + 1)))
116+
echo $version
117+
}
118+
function checkIfStatusChanged(){
119+
if [[ `git status --porcelain` ]]; then
120+
git add .
121+
git commit -m "bumped to version $1" ;
122+
git push
123+
fi
124+
}

.release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
release=9-0.0.1

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM debian:stretch-slim
2+
LABEL maintainer="Stakater Team"
3+
LABEL Description="Stakater base docker image atop Debian 9 Stretch"
4+
5+
ARG DEBIAN_FRONTEND=noninteractive

Jenkinsfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env groovy
2+
@Library('github.com/stakater/fabric8-pipeline-library@master') _
3+
4+
pushDockerImageFromMakefile {
5+
dockerRegistryURL = "docker.io"
6+
}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include Makefile.mk

Makefile.mk

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#
2+
# Copyright 2015 Xebia Nederland B.V.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
# If you set the environment variables with same name as variables then they will be used otherwise default
18+
# values will be used.
19+
REGISTRY_HOST ?= docker.io
20+
USERNAME ?= stakater
21+
NAME ?= base-debian
22+
23+
RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support
24+
IMAGE=$(REGISTRY_HOST)/$(USERNAME)/$(NAME)
25+
26+
VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion)
27+
# TAG=$(shell . $(RELEASE_SUPPORT) ; getVersion)
28+
29+
SHELL=/bin/bash
30+
31+
.PHONY: pre-build docker-build post-build build release patch-release minor-release major-release tag check-status check-release showver \
32+
push pre-push do-push post-push
33+
34+
build: pre-build docker-build post-build
35+
36+
pre-build:
37+
38+
post-build:
39+
40+
pre-push:
41+
42+
post-push:
43+
44+
docker-build: .release
45+
docker build $(DOCKER_BUILD_ARGS) -t $(IMAGE):$(VERSION) . --network=host
46+
@DOCKER_MAJOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f1) ; \
47+
DOCKER_MINOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f2) ; \
48+
if [ $$DOCKER_MAJOR -eq 1 ] && [ $$DOCKER_MINOR -lt 10 ] ; then \
49+
echo docker tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\
50+
docker tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\
51+
else \
52+
echo docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ;\
53+
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ; \
54+
fi
55+
56+
.release:
57+
@echo "release=0.0.0" > .release
58+
@echo INFO: .release created
59+
@cat .release
60+
61+
release: check-status check-release build push
62+
63+
push: pre-push do-push post-push
64+
65+
do-push:
66+
docker push $(IMAGE):$(VERSION)
67+
docker push $(IMAGE):latest
68+
69+
snapshot: build push
70+
71+
showver: .release
72+
@. $(RELEASE_SUPPORT); getVersion
73+
74+
tag-patch-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel)
75+
tag-patch-release: .release tag
76+
77+
tag-minor-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel)
78+
tag-minor-release: .release tag
79+
80+
tag-major-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel)
81+
tag-major-release: .release tag
82+
83+
patch-release: tag-patch-release release
84+
@echo $(VERSION)
85+
86+
minor-release: tag-minor-release release
87+
@echo $(VERSION)
88+
89+
major-release: tag-major-release release
90+
@echo $(VERSION)
91+
92+
tag: TAG=$(shell . $(RELEASE_SUPPORT) ; getVersion)
93+
tag: check-status
94+
@. $(RELEASE_SUPPORT) ; ! tagExists $(VERSION) || (echo "ERROR: tag $(VERSION) for version $(VERSION) already tagged in git" >&2 && exit 1) ;
95+
@. $(RELEASE_SUPPORT) ; setRelease $(VERSION)
96+
@. $(RELEASE_SUPPORT) ; checkIfStatusChanged $(VERSION)
97+
git tag $(VERSION)
98+
git push --tags
99+
# @ if [ -n "$(shell git remote -v)" ] ; then git push --tags ; else echo 'no remote to push tags to' ; fi
100+
101+
check-status:
102+
@. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2 && exit 1) ;
103+
104+
check-release: .release
105+
@. $(RELEASE_SUPPORT) ; tagExists $(VERSION) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ;
106+
@. $(RELEASE_SUPPORT) ; ! differsFromRelease $(VERSION) || (echo "ERROR: current directory differs from tagged $(VERSION). make [minor,major,patch]-release." ; exit 1)

0 commit comments

Comments
 (0)