Browse Source

add pipeline

tags/0.0.1
Vladimir Smagin 4 weeks ago
parent
commit
0192a0e10e
3 changed files with 72 additions and 0 deletions
  1. +51
    -0
      Jenkinsfile
  2. +12
    -0
      build/package/build.sh
  3. +9
    -0
      build/package/control

+ 51
- 0
Jenkinsfile View File

@@ -0,0 +1,51 @@
node {
checkout scm

def registry = "registry.blindage.org"
def tag = env.TAG_NAME
def image
def repository = "compare-pg"
def image_name = "${repository}:${tag}"

stage("Tests") {
sh "docker run --rm -v jenkins_jenkins-data:/var/jenkins_home golang:1.14 /bin/sh -c 'cd ${WORKSPACE} && CGO_ENABLED=0 go test -mod vendor -v ./...'"
}

stage("Build binary") {
sh "docker run --rm -v jenkins_jenkins-data:/var/jenkins_home golang:1.14 /bin/sh -c 'cd ${WORKSPACE} && CGO_ENABLED=0 go build -mod vendor -ldflags \"-w -s\"'"
}

stage("Build image") {
try {
sh "docker build -t ${image_name} ."
image = docker.image(image_name)
} catch (Exception e) {
error("Failed to build image")
}
}

stage("Build deb package") {
sh "./build/package/build.sh"
archiveArtifacts "compare-pg-${tag}.deb"
sh "mv *.deb /var/packages/"
}

stage("Push Image") {
try {

docker.withRegistry("https://${registry}", "registry") {
image.push()
}

} catch(Exception e) {
error("Failed to push image")
} finally {
sh "docker rmi ${registry}/${image_name} || true"
}
}

stage("Deploy") {
echo "No deploy"
}

}

+ 12
- 0
build/package/build.sh View File

@@ -0,0 +1,12 @@
#!/bin/bash
VERSION=${TAG_NAME}
mkdir -p ./build/package/debian/usr/bin
mkdir -p ./build/package/debian/DEBIAN/
mv ./compare-pg ./build/package/debian/usr/bin/
DSIZE=$(du -hs ./build/package/debian/usr/bin|awk '{ print $1 }')
echo "Making deb config"
cp ./build/package/control ./build/package/debian/DEBIAN/control
sed -i "s/VERSION/${VERSION}/g" ./build/package/debian/DEBIAN/control
sed -i "s/DSIZE/${DSIZE}/g" ./build/package/debian/DEBIAN/control
echo "Building deb package"
dpkg-deb --build ./build/package/debian ./compare-pg-${VERSION}.deb

+ 9
- 0
build/package/control View File

@@ -0,0 +1,9 @@
Package: compare-pg
Version: VERSION
Installed-Size: DSIZE
Section: devel
Priority: optional
Architecture: amd64
Maintainer: Vladimir Smagin <21h@blindage.org>
Homepage: https://git.blindage.org/21h/compare-pg
Description: Compare records count in replicated postgresql tables

Loading…
Cancel
Save