move to 2.0 (#1562)

This commit is contained in:
Victor Vrantchan 2017-10-12 12:14:03 -04:00 committed by GitHub
parent 4b8645ae72
commit 61866aa680
7 changed files with 129 additions and 225 deletions

43
.circleci/config.yml Normal file
View File

@ -0,0 +1,43 @@
version: 2
jobs:
build-go1.9:
docker:
- image: kolide/fleet-builder:1.9
working_directory: /go/src/github.com/kolide/fleet
steps: &steps
- checkout
- restore_cache:
keys:
- vendor-cache-{{ .Branch }}-{{ checksum "glide.lock" }}
- vendor-cache-{{ .Branch }}
- vendor-cache
- run:
name: "fix node-sass"
command: |
yarn remove node-sass
yarn add node-sass@latest
- run: make deps
- save_cache:
key: vendor-cache-{{ .Branch }}-{{ checksum "glide.lock" }}
paths:
- vendor
- save_cache:
key: vendor-cache-{{ .Branch }}
paths:
- vendor
- save_cache:
key: vendor-cache
paths:
- vendor
- run: make generate
- run: make test
- run: make build
workflows:
version: 2
build:
jobs:
- build-go1.9

View File

@ -1,48 +0,0 @@
machine:
environment:
PROJECT_NAME: kolide-ose-testing
CLUSTER_NAME: cluster-1
CLOUDSDK_COMPUTE_ZONE: us-east1-c
GOOGLE_APPLICATION_CREDENTIALS: ${HOME}/gcloud-service-key.json
pre:
- sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci'
- sudo chmod 0755 /usr/bin/docker
services:
- docker
dependencies:
pre:
- docker info
- docker login -e $DOCKER_HUB_EMAIL -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
- ./tools/ci/setup-build-environment.sh
- ./tools/ci/download-build-deps.sh
cache_directories:
- "vendor"
- "node_modules"
- "~/deps"
# - "/opt/google-cloud-sdk"
override:
# workaround for https://github.com/yarnpkg/yarn/issues/1981
- docker run -v $(pwd):/go/src/github.com/kolide/fleet -v /home/ubuntu/.go_workspace/pkg:/go/pkg --entrypoint /usr/bin/yarn kolide/fleet-builder:1.8 add --force node-sass
- docker run -v $(pwd):/go/src/github.com/kolide/fleet -v /home/ubuntu/.go_workspace/pkg:/go/pkg -v /home/ubuntu/.ssh/id_circleci_github:/tmp/id_rsa kolide/fleet-builder:1.8 --deps
test:
override:
- docker run -d --name redis redis
- docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=toor -e MYSQL_DATABASE=kolide -e MYSQL_USER=kolide -e MYSQL_PASSWORD=kolide mysql:5.7
- docker run --link redis:redis --link mysql:mysql -e MYSQL_TEST=true -e REDIS_TEST=true -v $(pwd):/go/src/github.com/kolide/fleet -v /home/ubuntu/.go_workspace/pkg:/go/pkg kolide/fleet-builder:1.8 --build
- ./tools/ci/verify-dependencies-docs.sh
- docker stop $(docker ps -a -q)
deployment:
development:
branch: /.*/
commands:
- make docker-build-circle
- ./tools/ci/deploy-k8s-testing.sh
release:
tag: /.*/
commands:
- make docker-build-release

View File

@ -1,29 +0,0 @@
FROM golang:1.8-alpine
MAINTAINER Kolide Developers <engineering@kolide.co>
RUN apk add --update \
git \
nodejs \
bash \
alpine-sdk \
musl-dev \
openssl \
openssh-client
RUN go get -u -v github.com/Masterminds/glide
RUN echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories && \
apk add --no-cache yarn
# git must be explicitly instructed to follow redirects for compatibility with
# gopkg.in
RUN git config --global http.https://gopkg.in.followRedirects true
COPY rootfs /
VOLUME /go/src/github.com/kolide/fleet
WORKDIR /go/src/github.com/kolide/fleet
EXPOSE 8080
ENTRYPOINT ["/builder.sh"]

View File

@ -1,101 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail
usage() {
base="$(basename "$0")"
cat <<EOUSAGE
Usage: ${base} [args]
-C,--ci : Replicate full Circle CI run
-D,--deps : Build dependencies
-B,--build : Build a release
-T,--test : Run 'make test'
make [option] : Run any fleet Makefile command
EOUSAGE
}
if [ $# -eq 0 ]; then
usage
fi
# Flag parsing
while [[ $# -gt 0 ]]; do
opt="$1"
case "${opt}" in
-C|--ci)
ci=1
shift
;;
-B|--build)
build=1
shift
;;
-D|--deps)
deps=1
shift
;;
-T|--tests)
tests=1
shift
;;
make)
make $2
shift
;;
*)
echo "Error: Unknown option: ${opt}"
usage
exit 1
;;
esac
done
function ci_run {
echo 'running full circle ci test suite'
echo "make deps"
make deps
echo "make generate"
make generate
echo "make test"
make test
echo "make build"
make build
}
deps=${deps:-0}
if [ ${deps} -eq 1 ]; then
# Copy SSH key
mkdir -p /root/.ssh -m 0700
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==
' >> ~/.ssh/known_hosts
cp /tmp/id_rsa /root/.ssh/id_rsa
chmod 0600 /root/.ssh/id_rsa
make deps
make generate
GOGC=off go install
exit 0
fi
build=${build:-0}
if [ ${build} -eq 1 ]; then
make test
make build
exit 0
fi
tests=${tests:-0}
if [ ${tests} -eq 1 ]; then
make test
exit 0
fi
ci=${ci:-0}
if [ ${ci} -eq 1 ]; then
ci_run
exit 0
fi

View File

@ -0,0 +1,86 @@
FROM golang:1.9-alpine
MAINTAINER Kolide Developers <engineering@kolide.co>
ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 8.7.0
RUN addgroup -g 1000 node \
&& adduser -u 1000 -G node -s /bin/sh -D node \
&& apk add --no-cache \
libstdc++ \
&& apk add --no-cache --virtual .build-deps \
binutils-gold \
curl \
g++ \
gcc \
gnupg \
libgcc \
linux-headers \
make \
python \
# gpg keys listed at https://github.com/nodejs/node#release-team
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
56730D5401028683275BD23C23EFEFE93C4CFFFE \
; do \
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \
done \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.xz" \
&& curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xf "node-v$NODE_VERSION.tar.xz" \
&& cd "node-v$NODE_VERSION" \
&& ./configure \
&& make -j$(getconf _NPROCESSORS_ONLN) \
&& make install \
&& apk del .build-deps \
&& cd .. \
&& rm -Rf "node-v$NODE_VERSION" \
&& rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
ENV YARN_VERSION 1.2.0
RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
&& for key in \
6A010C5166006599AA17F08146C2130DFD2497F5 \
; do \
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \
done \
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& mkdir -p /opt/yarn \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/yarn --strip-components=1 \
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn \
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& apk del .build-deps-yarn
RUN apk add --update \
git \
alpine-sdk \
openssl \
openssh-client
RUN go get -u -v github.com/Masterminds/glide
# git must be explicitly instructed to follow redirects for compatibility with
# gopkg.in
RUN git config --global http.https://gopkg.in.followRedirects true
VOLUME /go/src/github.com/kolide/fleet
WORKDIR /go/src/github.com/kolide/fleet
EXPOSE 8080

View File

@ -1,18 +0,0 @@
.PHONY: build fleet-builder push
GO_VERSION = 1.8
all: clean build
build: fleet-builder
fleet-builder:
# copy node-sass artifacts into rootfs
cd $(GO_VERSION) && \
docker build -t kolide/fleet-builder:$(GO_VERSION) .
push:
docker push kolide/fleet-builder:$(GO_VERSION)
clean:
rm -rf build

View File

@ -1,29 +0,0 @@
Usage
```
Usage: builder.sh [args]
-T,--tests : Go run tests then exit
-C,--ci : Replicate full circle CI run
-B,--build : Build a release
```
### Caching pkg folder
If you're repeatedly testing the build on a development machine, it makes sense to mount the `$GOPATH/pkg` along with your source.
```
docker run --rm -it -v (pwd):/go/src/github.com/kolide/fleet -v $GOPATH/pkg:/go/pkg fleet-builder -T
```
The first time the container runs, `go install` will compile all the dependencies under `$GOPATH/pkg/linux_amd64/...` making future test runs faster.
### Build a binary
Using the `-B,--build` flag will first run the CI build and then create a linux build in `./build/`.
This option is intended to be used followed by `docker build` to build a new release.
# Building the builder
use `make` to create a new container and then `make push` to push the builder to Docker Hub
The Makefile first compiles `node-sass` bindings to work on alpine linux and then builds the `fleet-builder` container with the compiled bindings.
Separating the two steps keeps the build container small, but increases the difficulty of building it.