Upload build to google cloud bucket

This commit is contained in:
Erik Wilson 2019-12-23 12:07:34 -07:00
parent 12c3d74a53
commit ff311b7fce
6 changed files with 80 additions and 7 deletions

View File

@ -9,6 +9,10 @@ platform:
steps:
- name: build
image: rancher/dapper:v0.4.2
secrets: [ gcloud_auth ]
environment:
GCLOUD_AUTH:
from_secret: gcloud_auth
commands:
- dapper ci
volumes:
@ -100,6 +104,10 @@ platform:
steps:
- name: build
image: rancher/dapper:v0.4.2
secrets: [ gcloud_auth ]
environment:
GCLOUD_AUTH:
from_secret: gcloud_auth
commands:
- dapper ci
volumes:
@ -174,6 +182,10 @@ platform:
steps:
- name: build
image: rancher/dapper:v0.4.2
secrets: [ gcloud_auth ]
environment:
GCLOUD_AUTH:
from_secret: gcloud_auth
commands:
- dapper ci
volumes:

View File

@ -1,7 +1,7 @@
FROM golang:1.13.5-alpine3.10
RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget ca-certificates jq linux-headers zlib-dev tar zip squashfs-tools npm coreutils \
python3 py3-pip python3-dev openssl-dev libffi-dev libseccomp libseccomp-dev make libuv-static
python2 python3 py3-pip python3-dev openssl-dev libffi-dev libseccomp libseccomp-dev make libuv-static
RUN pip3 install 'tox==3.6.0'
RUN apk -U --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ add sqlite-dev sqlite-static
RUN mkdir -p /go/src/golang.org/x && \
@ -27,7 +27,7 @@ RUN if [ "$DQLITE" = true ]; then \
ENV GO111MODULE off
ENV DAPPER_RUN_ARGS --privileged -v k3s-cache:/go/src/github.com/rancher/k3s/.cache
ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME SKIP_VALIDATE
ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME SKIP_VALIDATE GCLOUD_AUTH
ENV DAPPER_SOURCE /go/src/github.com/rancher/k3s/
ENV DAPPER_OUTPUT ./bin ./dist ./build/out
ENV DAPPER_DOCKER_SOCKET true

View File

@ -18,12 +18,12 @@ VERSIONFLAGS="
-X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8}
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitVersion=${VERSION}
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitCommit=${LONG_COMMIT}
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitCommit=${COMMIT}
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitTreeState=${TREE_STATE}
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.buildDate=${buildDate}
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitVersion=${VERSION}
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitCommit=${LONG_COMMIT}
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitCommit=${COMMIT}
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitTreeState=${TREE_STATE}
-X ${VENDOR_PREFIX}k8s.io/component-base/version.buildDate=${buildDate}

57
scripts/build-upload Executable file
View File

@ -0,0 +1,57 @@
#!/bin/bash
[ -n "$GCLOUD_AUTH" ] || {
exit 0
}
[ -x "$1" ] || {
echo "First argument should be an executable" >&2
exit 1
}
[ -n "$2" ] || {
echo "Second argument should be a commit hash" >&2
exit 1
}
umask 077
TMPDIR=$(mktemp -d)
cleanup() {
exit_code=$?
trap - EXIT INT
rm -rf ${TMPDIR}
exit ${exit_code}
}
trap cleanup EXIT INT
GCLOUD_JSON=${TMPDIR}/.gcloud.json
[ -z "${GCLOUD_AUTH}" ] || echo "${GCLOUD_AUTH}" >${GCLOUD_JSON}
[ -s "${GCLOUD_JSON}" ] || {
echo "gcloud auth not defined" >&2
exit 1
}
BOTO_CONF=${TMPDIR}/.boto
[ -s "${BOTO_CONF}" ] || cat >${BOTO_CONF} <<END
[Credentials]
gs_service_key_file = ${GCLOUD_JSON}
[Boto]
https_validate_certificates = True
[GSUtil]
content_language = en
default_api_version = 2
default_project_id = rancher-dev
END
BUILD_NAME=$(basename $1)-$2
(cd $(dirname $1) && sha256sum $(basename $1)) >${TMPDIR}/${BUILD_NAME}.sha256sum
cp $1 ${TMPDIR}/${BUILD_NAME}
[ -d "${TMPDIR}/gsutil" ] || curl -sfL https://storage.googleapis.com/pub/gsutil.tar.gz | tar xz -C ${TMPDIR}
HOME=${TMPDIR}
PATH=${PATH}:${HOME}/gsutil
gsutil cp ${TMPDIR}/${BUILD_NAME}* gs://k3s-ci-builds || exit 1
echo "Build uploaded" >&2
echo "https://storage.googleapis.com/k3s-ci-builds/${BUILD_NAME}"

View File

@ -60,3 +60,5 @@ if [ "$DQLITE" = "true" ]; then
DQLITE_TAGS="dqlite"
fi
CGO_ENABLED=0 go build -tags "$DQLITE_TAGS" -ldflags "$LDFLAGS $STATIC" -o ${CMD_NAME} ./cmd/k3s/main.go
./scripts/build-upload ${CMD_NAME} ${COMMIT}

View File

@ -6,8 +6,10 @@ if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
TREE_STATE=dirty
fi
COMMIT=$(git rev-parse --short HEAD)
LONG_COMMIT=$(git rev-parse HEAD)
COMMIT=$(git log -n3 --pretty=format:"%H %ae" | grep -v ' drone@localhost$' | cut -f1 -d\ | head -1)
if [ -z "${COMMIT}" ]; then
COMMIT=$(git rev-parse HEAD)
fi
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)}
@ -34,6 +36,6 @@ VERSION_CNIPLUGINS="v0.7.6-k3s1"
if [[ -n "$GIT_TAG" ]]; then
VERSION=$GIT_TAG
else
VERSION="$(sed -e 's/[-+].*//' <<< "$VERSION_K8S")+$COMMIT$DIRTY"
VERSION="$(sed -e 's/[-+].*//' <<< "$VERSION_K8S")+${COMMIT:0:8}$DIRTY"
fi
VERSION_TAG="$(sed -e 's/+/-/g' <<< "$VERSION")"