Skip to content

Commit

Permalink
Merge pull request #7 from vapor-ware/mhink-device
Browse files Browse the repository at this point in the history
Updates for synse v3 / golang / jenkins.
  • Loading branch information
MatthewHink committed Apr 28, 2020
2 parents b01b613 + 6d64f21 commit 5977e93
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 392 deletions.
127 changes: 37 additions & 90 deletions .jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

pipeline {

agent any
agent {
label 'golang-alpha'
}

environment {
PROJ_PATH = '/go/src/github.com/vapor-ware/sandbox-plugin'
IMAGE_NAME = 'vaporio/sandbox-plugin'
}

stages {
Expand All @@ -15,109 +17,54 @@ pipeline {
}
}

// This stage is done first in order to get the vendored dependencies
// if they do not already exist. This should improve the build time of
// all subsequent stages which require the vendored dependencies to
// exist (e.g. testing, building)
stage('Vendor Dependencies') {
agent {
docker {
image 'vaporio/golang:1.11'
reuseNode true
}
}
steps {
// Set up the project in the docker container. The project must be
// on the GOPATH (/go) in order to correctly vendor dependencies and
// build the project artifacts.
sh 'mkdir -p ${PROJ_PATH} && cp -r ${WORKSPACE}/* ${PROJ_PATH}'

// The pipeline's 'dir()' directive is broken when run inside a docker
// container, so we need to 'cd' into the project directory prior to
// running the required commands.
sh 'cd ${PROJ_PATH} && make dep'

// Copy the vendor directory back down to the WORKSPACE, since it is
// volume mounted. This way all subsequent stages will have the
// project already vendored.
sh 'mkdir -p ${WORKSPACE}/vendor'
sh 'cp -r ${PROJ_PATH}/vendor/* ${WORKSPACE}/vendor'
}
}
stage('Checks') {
parallel {

// Run linting on project source code.
stage('Lint') {
agent {
docker {
image 'vaporio/golang:1.11'
reuseNode true
stage('Lint') {
steps {
container('golang') {
sh 'make lint'
}
}
}
}
steps {
// Set up the project in the docker container. The project must be
// on the GOPATH (/go) in order to correctly vendor dependencies and
// build the project artifacts.
sh 'mkdir -p ${PROJ_PATH} && cp -r ${WORKSPACE}/* ${PROJ_PATH}'

// The pipeline's 'dir()' directive is broken when run inside a docker
// container, so we need to 'cd' into the project directory prior to
// running the required commands.
sh 'cd ${PROJ_PATH} && make lint'
}
}
// Verify that the Docker image builds successfully.
stage('Build Image') {
steps {
container('golang') {
sh 'make docker'
}
}
}

// Verify that the Docker image builds successfully.
stage('Build Image') {
steps {
sh 'make docker'
}
}

// Build artifacts for the GitHub Release.
stage('Build Release Artifacts') {
agent {
docker {
image 'vaporio/golang:1.11'
reuseNode true
}
}
stage('Publish Latest') {
when {
// example matches: 1.2.3, 1.2.3-dev
tag pattern: '(0|[1-9]*)\\.(0|[1-9]*)\\.(0|[1-9]*)(-(\\S*))?$', comparator: "REGEXP"
branch 'master'
}
steps {
// Set up the project in the docker container. The project must be
// on the GOPATH (/go) in order to correctly vendor dependencies and
// build the project artifacts.
sh 'mkdir -p ${PROJ_PATH} && cp -r ${WORKSPACE}/* ${PROJ_PATH}'

// Build the project artifacts
sh 'mkdir -p ${WORKSPACE}/build'
sh 'make ci-build'
container('golang') {
withDockerRegistry(registry: [credentialsId: 'vio-docker-hub']) {
sh 'docker push ${IMAGE_NAME}:latest'
}
}
}
}

// Generate a new release draft on GitHub for a tag matching a version string
// pattern. The release will include an auto-generated changelog and build
// artifacts.
stage('Draft GitHub Release') {
stage('Tagged Release') {
when {
// example matches: 1.2.3, 1.2.3-dev
tag pattern: '(0|[1-9]*)\\.(0|[1-9]*)\\.(0|[1-9]*)(-(\\S*))?$', comparator: "REGEXP"
}
environment {
GITHUB_USER = 'vapor-ware'
GITHUB_TOKEN = credentials('1de2c61b-4188-478b-bc65-42b0df860163')
GITHUB_REPONAME = 'sandbox-plugin'
branch 'master'
}
steps {
// Auto-generate a changelog for the release
sh './bin/ci/generate_changelog.sh'

// Create the release
sh 'docker pull edaniszewski/ghr'
sh 'docker run --rm -v ${WORKSPACE}:/repo edaniszewski/ghr -u ${GITHUB_USER} -r ${GITHUB_REPONAME} -t ${GITHUB_TOKEN} -b "$(cat ./CHANGELOG.md)" -replace -draft ${TAG_NAME} build/'
container('golang') {
withDockerRegistry(registry: [credentialsId: 'vio-docker-hub']) {
sh 'goreleaser release --debug --rm-dist'
}
}
}
}
}
}

} // end stages
} // end pipeline
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Builder Image
FROM vaporio/golang:1.11 as builder
FROM vaporio/golang:1.13 as builder
WORKDIR /go/src/github.com/vapor-ware/sandbox-plugin
COPY . .

# If the vendored dependencies are not present in the docker build context,
# we'll need to do the vendoring prior to building the binary.
RUN if [ ! -d "vendor" ]; then make dep; fi
RUN go mod download
RUN make build CGO_ENABLED=0


Expand Down
209 changes: 0 additions & 209 deletions Gopkg.lock

This file was deleted.

Loading

0 comments on commit 5977e93

Please sign in to comment.