Skip to content

Commit

Permalink
update for synse v3
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed May 7, 2020
1 parent 6e0cd95 commit 69a2a21
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 314 deletions.
16 changes: 11 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
*.dll
*.so
*.dylib
build/

# Test binary, build with `go test -c`
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Vendored Dependencies
# Dependency directories
vendor/

# IDE files
.idea
# JetBrains IDE
.idea

# System files
.DS_Store

# Build Artifacts
sandbox-plugin
dist/
58 changes: 58 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# For details, see the GoReleaser documentation at http://goreleaser.com
project_name: sandbox-plugin
before:
hooks:
- go clean -v
- rm -rf dist
builds:
- env:
- CGO_ENABLED=0
ldflags:
- -w
- -X github.com/vapor-ware/sandbox-plugin/vendor/github.com/vapor-ware/synse-sdk/sdk.BuildDate={{ .Date }}
- -X github.com/vapor-ware/sandbox-plugin/vendor/github.com/vapor-ware/synse-sdk/sdk.GitCommit={{ .ShortCommit }}
- -X github.com/vapor-ware/sandbox-plugin/vendor/github.com/vapor-ware/synse-sdk/sdk.GitTag={{ .Tag }}
- -X github.com/vapor-ware/sandbox-plugin/vendor/github.com/vapor-ware/synse-sdk/sdk.GoVersion={{ .Env.GOVERSION }}
- -X github.com/vapor-ware/sandbox-plugin/vendor/github.com/vapor-ware/synse-sdk/sdk.PluginVersion={{ .Version }}
goos:
- linux
- darwin
goarch:
- amd64
archive:
format: tar.gz
checksum:
name_template: 'checksums-{{ .Tag }}.txt'
release:
github:
owner: vapor-ware
name: sandbox-plugin
draft: false
prerelease: auto
name_template: "{{ .Version }}"
dockers:
-
goos: linux
goarch: amd64
binaries:
- sandbox-plugin
image_templates:
- vaporio/sandbox-plugin:{{ .Tag }}
- vaporio/sandbox-plugin:{{ .Major }}
- vaporio/sandbox-plugin:{{ .Major }}.{{ .Minor }}
- vaporio/sandbox-plugin:latest
build_flag_templates:
- "--label=org.label-schema.version={{ .Version }}"
- "--label=org.label-schema.build-date={{ .Date }}"
- "--label=org.label-schema.vcs-ref={{ .ShortCommit }}"
extra_files:
- config/device/devices.yml
- config/plugin/config.yml
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
121 changes: 41 additions & 80 deletions .jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pipeline {

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

stages {
Expand All @@ -15,109 +17,68 @@ 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'
}
}

// 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'
script {
docker.image('vaporio/jenkins-agent-golang:latest').inside('-v $WORKSPACE:$PROJ_PATH') {
// All the deps to build this project are provided by the runtime container
// Skip the configuration management and let the pipeline assets do that for you.
sh 'cd ${PROJ_PATH} && dep ensure'
sh 'cd ${PROJ_PATH} && golint -set_exit_status ./pkg/...'
}
}
}
}

// Verify that the Docker image builds successfully.
stage('Build Image') {
stage('Snapshot Build') {
steps {
sh 'make docker'
}
}
script {
/* This replicates some of what the docker agent would do if this were
running natively in kube. We would version these same params in
the agent config. This is a bit of a phaux pre-dep test to getting
agents running in kube. the containers are acting just like the
host agent would, but in spurts.
// Build artifacts for the GitHub Release.
stage('Build Release Artifacts') {
agent {
docker {
image 'vaporio/golang:1.11'
reuseNode true
Note: the importance of the --group-add docker in the parameters.
Without it, docker in agent is mysteriously permission
locked despite having a GID present in the container.
*/
docker.image('vaporio/jenkins-agent-golang:latest').inside('-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v $WORKSPACE:$PROJ_PATH --group-add docker') {
sh 'cd ${PROJ_PATH} && goreleaser release --snapshot --skip-publish --rm-dist'
}
}
}
}

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'
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'
GITHUB_TOKEN = credentials('vio-bot-gh-token')
}
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/'
script {
docker.image('vaporio/jenkins-agent-golang:latest').inside('-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -e GITHUB_TOKEN=$GITHUB_TOKEN -v $WORKSPACE:$PROJ_PATH --group-add docker') {
withDockerRegistry(registry: [credentialsId: 'vio-docker-hub']) {
sh 'cd ${PROJ_PATH} && goreleaser release --rm-dist'
}
}
}
}
}

}
}
24 changes: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
#
# 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
#
# Final Image
#
FROM scratch

LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="vaporio/sandbox-plugin" \
org.label-schema.vcs-url="https://github.com/vapor-ware/sandbox-plugin" \
org.label-schema.vendor="Vapor IO"

# Plugin Image
FROM scratch
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

# 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
# Copy the executable.
COPY sandbox-plugin ./plugin

EXPOSE 5001
ENTRYPOINT ["./plugin"]
Loading

0 comments on commit 69a2a21

Please sign in to comment.