From d589607de7e70f4178e27176d1a6a617171dcca9 Mon Sep 17 00:00:00 2001 From: Joshua Anderson Date: Mon, 25 Jul 2016 13:22:13 -0700 Subject: [PATCH] fix(tests): set owner of files created by containers to the local user --- Jenkinsfile | 24 +++++++++++++++++------- Makefile | 8 ++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 09271426..2148ea1d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,11 +6,20 @@ def getBasePath = { String filepath -> return filepath.substring(0, filename) } +def make = { String target -> + try { + sh "make ${target} fileperms" + } catch(error) { + sh "make fileperms" + false + } +} + def upload_artifacts = { String filepath -> withCredentials([[$class: 'FileBinding', credentialsId: 'e80fd033-dd76-4d96-be79-6c272726fb82', variable: 'GCSKEY']]) { sh "mkdir -p ${getBasePath(filepath)}" sh "cat \"\${GCSKEY}\" > ${filepath}" - sh "make upload-gcs" + make 'upload-gcs' } } @@ -51,9 +60,9 @@ node('linux') { stage 'Checkout Linux' checkout scm stage 'Install Linux' - sh 'make bootstrap' + make 'bootstrap' stage 'Test Linux' - sh 'make test' + make 'test' } } @@ -94,8 +103,9 @@ parallel( env.BUILD_ARCH = "amd64" } - sh 'make bootstrap' - sh "VERSION=${git_commit.take(7)} make build-revision" + make 'bootstrap' + env.VERSION = git_commit.take(7) + make 'build-revision' upload_artifacts(keyfile) } @@ -110,8 +120,8 @@ parallel( checkout scm if (git_branch == "remotes/origin/master") { - sh 'make bootstrap' - sh 'make build-latest' + make 'bootstrap' + make 'build-latest' upload_artifacts(keyfile) } else { diff --git a/Makefile b/Makefile index 16adcb59..b34d4b8a 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,10 @@ GOTEST = go test --cover --race -v GIT_TAG := $(shell git tag -l --contains HEAD) VERSION ?= $(shell git rev-parse --short HEAD) +# UID and GID of local user +UID := $(shell id -u) +GID := $(shell id -g) + define check-static-binary if file $(1) | egrep -q "(statically linked|Mach-O)"; then \ echo -n ""; \ @@ -107,3 +111,7 @@ upload-gcs: ${GSUTIL_CMD} sh -c 'gsutil -mq cp -a public-read -r /upload/* ${GCS_BUCKET}' # This has to run in the container to delete files created by the container ${GSUTIL_CMD} sh -c 'rm -rf /.config/*' + +# Set local user as owner for files +fileperms: + ${DEV_ENV_PREFIX_CGO_ENABLED} ${DEV_ENV_IMAGE} chown -R ${UID}:${GID} .