Skip to content

Commit

Permalink
Add .jenkins file for new CI (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Dec 7, 2018
1 parent 8f98289 commit b01b613
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 163 deletions.
128 changes: 0 additions & 128 deletions .circleci/config.yml

This file was deleted.

123 changes: 123 additions & 0 deletions .jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env groovy

pipeline {

agent any

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

stages {
stage('Checkout') {
steps {
checkout scm
}
}

// 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'
}
}

// Run linting on project source code.
stage('Lint') {
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 lint'
}
}

// 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
}
}
when {
// example matches: 1.2.3, 1.2.3-dev
tag pattern: '(0|[1-9]*)\\.(0|[1-9]*)\\.(0|[1-9]*)(-(\\S*))?$', comparator: "REGEXP"
}
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'
}
}

// 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') {
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'
}
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/'
}
}
}
}
17 changes: 14 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
FROM iron/go:dev as builder
# Builder Image
FROM vaporio/golang:1.11 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 make build CGO_ENABLED=0


# Plugin Image
FROM scratch
LABEL maintainer="[email protected]"
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /go/src/github.com/vapor-ware/sandbox-plugin/build/plugin ./plugin
COPY config/plugin/config.yml /etc/synse/plugin/config/config.yml

# Build the device configurations directly into the image. This is not
# generally advised, but is acceptable here since the plugin is merely
# an example for sandboxing and its config is not tied to anything real.
COPY config/device/devices.yml /etc/synse/plugin/config/device/devices.yml
COPY config/plugin/config.yml /etc/synse/plugin/config/config.yml

EXPOSE 5002
ENTRYPOINT ["./plugin"]
Loading

0 comments on commit b01b613

Please sign in to comment.