From 053c9c01bf40f1003c5687e19c1f94d20e7459e9 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 14 Aug 2017 11:01:30 +0900 Subject: [PATCH] jenkins --- .gitignore | 2 +- Jenkinsfile | 37 +++++++++++++++++++++++++++++++++++++ glide.yaml | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile diff --git a/.gitignore b/.gitignore index 98d2148..3733e36 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,4 @@ vendor/ glide.lock .DS_Store dist/ -debug \ No newline at end of file +debug diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..3c0d6c4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,37 @@ +#!/usr/bin/env groovy + +// this will start an executor on a Jenkins agent with the docker label +node('docker') { + // Setup variables + // application name will be used in a few places so create a variable and use string interpolation to use it where needed + String applicationName = "overflow_service_websocket" + // a basic build number so that when we build and push to Artifactory we will not overwrite our previous builds + String buildNumber = "0.1.${env.BUILD_NUMBER}" + // Path we will mount the project to for the Docker container + String goPath = "/go/src/git.loafle.net/overflow/${applicationName}" + + // Checkout the code from Github, stages allow Jenkins to visualize the different sections of your build steps in the UI + stage('Checkout from Gitlab') { + // No special needs here, if your projects relys on submodules the checkout step would need to be different + checkout scm + } + + // Start a docker container using the golang:1.8.0-alpine image, mount the current directory to the goPath we specified earlier + stage("Create binaries") { + docker.image("golang:1.8.0-alpine").inside("-v ${pwd()}:${goPath}") { + for (command in binaryBuildCommands) { + // build the Mac x64 binary + sh "cd ${goPath} && GOOS=darwin GOARCH=amd64 go build -o binaries/amd64/${buildNumber}/darwin/${applicationName}-${buildNumber}.darwin.amd64" + // build the Windows x64 binary + sh "cd ${goPath} && GOOS=windows GOARCH=amd64 go build -o binaries/amd64/${buildNumber}/windows/${applicationName}-${buildNumber}.windows.amd64.exe" + // build the Linux x64 binary + sh "cd ${goPath} && GOOS=linux GOARCH=amd64 go build -o binaries/amd64/${buildNumber}/linux/${applicationName}-${buildNumber}.linux.amd64" + } + } + } + + stage("Archive artifacts") { + // Archive the binary files in Jenkins so we can retrieve them later should we need to audit them + archiveArtifacts artifacts: 'binaries/**', fingerprint: true + } +} \ No newline at end of file diff --git a/glide.yaml b/glide.yaml index ee871b8..c7d5e3b 100644 --- a/glide.yaml +++ b/glide.yaml @@ -21,3 +21,5 @@ import: version: ^0.3.0 - package: github.com/valyala/fasthttp version: ^20160617.0.0 +- package: go.uber.org/zap + version: v1.5.0