Skip to content

Commit d075160

Browse files
committed
Included jenkins pipeline (#2)
1 parent bea48ba commit d075160

File tree

2 files changed

+88
-15
lines changed

2 files changed

+88
-15
lines changed

Jenkinsfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
@Library(['tekton-library']) _
2+
3+
4+
pipeline {
5+
agent {
6+
node {
7+
label env.TEKTON_LABEL
8+
customWorkspace env.TEKTON_WS
9+
}
10+
}
11+
12+
stages {
13+
stage("Build") {
14+
steps {
15+
runMake("build");
16+
}
17+
}
18+
19+
20+
stage("Publish") {
21+
when {
22+
expression {
23+
return shouldPublish();
24+
}
25+
}
26+
steps {
27+
runMake("push");
28+
}
29+
}
30+
}
31+
32+
post {
33+
always {
34+
cleanWs();
35+
}
36+
}
37+
}
38+
39+
def runMake(task) {
40+
runShellBasedCommand("'docker login --username \\\$DOCKER_USERNAME --password \\\$DOCKER_PASSWORD harbor-dev.matera.com && TAGS=\\\"bindata sqlite sqlite_unlock_notify\\\" GITHUB_REF_NAME=\\\"${env.BRANCH_NAME}\\\" make ${task}'")
41+
}
42+
43+
def runShellBasedCommand(command) {
44+
tekton withTestContainers: command,
45+
image: "harbor-dev.matera.com/ci-cd/go-toolkit:1.0.0",
46+
commandPrefix: "bash -c",
47+
environmentSecret: "cicd-secret"
48+
}
49+
50+
51+
def shouldPublish() {
52+
if (env.BRANCH_NAME == 'master') {
53+
return true;
54+
} else {
55+
return isTag();
56+
}
57+
}
58+
59+
60+
def isTag() {
61+
def tag = sh(returnStdout: true, script: "git tag --contains | head -1").trim();
62+
return tag != "";
63+
}

Makefile

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
3939

4040
DOCKER_IMAGE ?= harbor-dev.matera.com/ci-cd/gitea
41-
DOCKER_TAG ?= latest-rootless
42-
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
4341

4442
ifeq ($(HAS_GO), yes)
4543
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
@@ -87,23 +85,28 @@ ifneq ($(GITHUB_REF_TYPE),branch)
8785
VERSION ?= $(subst v,,$(GITHUB_REF_NAME))
8886
GITEA_VERSION ?= $(VERSION)
8987
else
90-
ifneq ($(GITHUB_REF_NAME),)
91-
VERSION ?= $(subst release/v,,$(GITHUB_REF_NAME))-nightly
92-
else
93-
VERSION ?= main
94-
endif
95-
96-
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
97-
ifneq ($(STORED_VERSION),)
98-
GITEA_VERSION ?= $(STORED_VERSION)
99-
else
100-
GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
88+
ifeq ($(GITHUB_REF_NAME),master)
89+
VERSION = latest
90+
GITEA_VERSION = latest
91+
else
92+
ifneq ($(GITHUB_REF_NAME),)
93+
VERSION ?= $(subst release/v,,$(GITHUB_REF_NAME))-nightly
94+
else
95+
VERSION ?= master
96+
endif
97+
98+
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
99+
ifneq ($(STORED_VERSION),)
100+
GITEA_VERSION ?= $(STORED_VERSION)
101+
else
102+
GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/^v//')
103+
endif
101104
endif
102105
endif
103106

104107
# if version = "main" then update version to "nightly"
105-
ifeq ($(VERSION),main)
106-
VERSION := main-nightly
108+
ifeq ($(VERSION),master)
109+
VERSION := latest
107110
endif
108111

109112
LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
@@ -183,6 +186,9 @@ TEST_MSSQL_DBNAME ?= gitea
183186
TEST_MSSQL_USERNAME ?= sa
184187
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
185188

189+
DOCKER_TAG ?= $(GITEA_VERSION)-rootless
190+
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
191+
186192
.PHONY: all
187193
all: build
188194

@@ -975,6 +981,10 @@ docker:
975981
docker build -t $(DOCKER_REF) -f Dockerfile.rootless .
976982
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
977983

984+
.PHONY: push
985+
push: docker
986+
docker push $(DOCKER_REF)
987+
978988
# This endif closes the if at the top of the file
979989
endif
980990

0 commit comments

Comments
 (0)