From d63047cea34c7302c9956e126507284968214645 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 6 Feb 2018 23:45:09 -0800 Subject: [PATCH] Add a CircleCI configuration for building container images. --- .circleci/config.yml | 70 +++++++++++++++++++++++++++++++++++++++ .circleci/config.yml.tmpl | 46 +++++++++++++++++++++++++ .circleci/gen-config.go | 19 +++++++++++ .gitignore | 1 + Makefile | 21 +++++++++--- Makefile.inc | 64 +++++++++++++++++++++++++++++++++++ cmd/pixiecore/Dockerfile | 4 +++ 7 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .circleci/config.yml.tmpl create mode 100644 .circleci/gen-config.go create mode 100644 Makefile.inc create mode 100644 cmd/pixiecore/Dockerfile diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..f5e8c41 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,70 @@ +# -*- mode: yaml -*- + +version: 2 +jobs: + test-1.8: + working_directory: /go/src/go.universe.tf/netboot + docker: + - image: circleci/golang:1.8 + steps: + - checkout + - run: make ci-prepare + - run: make build + - run: make test + - run: make lint + test-1.9: + working_directory: /go/src/go.universe.tf/netboot + docker: + - image: circleci/golang:1.9 + steps: + - checkout + - run: make ci-prepare + - run: make build + - run: make test + - run: make lint + test-1.10beta2: + working_directory: /go/src/go.universe.tf/netboot + docker: + - image: circleci/golang:1.10beta2 + steps: + - checkout + - run: make ci-prepare + - run: make build + - run: make test + - run: make lint + deploy: + working_directory: /go/src/go.universe.tf/metallb + docker: + - image: circleci/golang:1.9 + steps: + - checkout + - setup_remote_docker + - run: echo $CIRCLE_BRANCH + - run: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + - run: make ci-prepare + - run: ci-push-images TAG=${CIRCLE_BRANCH:-${CIRCLE_TAG}} +workflows: + version: 2 + test-and-deploy: + jobs: + - test-1.8: + filters: + tags: + only: /.*/ + - test-1.9: + filters: + tags: + only: /.*/ + - test-1.10beta2: + filters: + tags: + only: /.*/ + - deploy: + filters: + branches: + ignore: /pull\/.*/ + tags: + only: /.*/ + requires: + - test-1.8 + - test-1.9 diff --git a/.circleci/config.yml.tmpl b/.circleci/config.yml.tmpl new file mode 100644 index 0000000..b023af7 --- /dev/null +++ b/.circleci/config.yml.tmpl @@ -0,0 +1,46 @@ +# -*- mode: yaml -*- + +version: 2 +jobs: +{{- range .GoVersions }} + test-{{.}}: + working_directory: /go/src/go.universe.tf/netboot + docker: + - image: circleci/golang:{{.}} + steps: + - checkout + - run: make ci-prepare + - run: make build + - run: make test + - run: make lint +{{- end }} + deploy: + working_directory: /go/src/go.universe.tf/metallb + docker: + - image: circleci/golang:1.9 + steps: + - checkout + - setup_remote_docker + - run: echo $CIRCLE_BRANCH + - run: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + - run: make ci-prepare + - run: ci-push-images TAG=${CIRCLE_BRANCH:-${CIRCLE_TAG}} +workflows: + version: 2 + test-and-deploy: + jobs: +{{- range .GoVersions }} + - test-{{.}}: + filters: + tags: + only: /.*/ +{{- end }} + - deploy: + filters: + branches: + ignore: /pull\/.*/ + tags: + only: /.*/ + requires: + - test-1.8 + - test-1.9 diff --git a/.circleci/gen-config.go b/.circleci/gen-config.go new file mode 100644 index 0000000..5ab8ba4 --- /dev/null +++ b/.circleci/gen-config.go @@ -0,0 +1,19 @@ +package main + +import ( + "html/template" + "os" + + "github.com/golang/glog" +) + +func main() { + tmpl := template.Must(template.ParseFiles("config.yml.tmpl")) + v := map[string][]string{ + "GoVersions": []string{"1.8", "1.9", "1.10beta2"}, + "Arch": []string{"amd64", "arm", "arm64", "ppc64le", "s390x"}, + } + if err := tmpl.Execute(os.Stdout, v); err != nil { + glog.Fatalf("Error executing template: %s", err) + } +} diff --git a/.gitignore b/.gitignore index a548cf3..624993d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dhcp4/dhcp4.test pcap/pcap.test pixiecore/pixiecore.test vendor/ +build/ diff --git a/Makefile b/Makefile index d0947ff..ea0efca 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,6 @@ endif all: $(error Please request a specific thing, there is no default target) -.PHONY: ci-config -ci-config: - (cd .circleci && go run gen-config.go >config.yml) - .PHONY: ci-prepare ci-prepare: $(GOCMD) get -u github.com/golang/dep/cmd/dep @@ -23,7 +19,7 @@ build: $(GOCMD) install -v ./cmd/pixiecore .PHONY: test -test: build +test: $(GOCMD) test ./... $(GOCMD) test -race ./... @@ -33,6 +29,21 @@ lint: gometalinter --install golint gometalinter --deadline=1m --disable-all --enable=gofmt --enable=golint --enable=vet --enable=deadcode --enable=structcheck --enable=unconvert --vendor ./... +REGISTRY=pixiecore +TAG=dev +.PHONY: ci-push-images +ci-push-images: + make -f Makefile.inc push GOARCH=amd64 TAG=$(TAG)-amd64 BINARY=pixiecore REGISTRY=$(REGISTRY) + make -f Makefile.inc push GOARCH=arm TAG=$(TAG)-arm BINARY=pixiecore REGISTRY=$(REGISTRY) + make -f Makefile.inc push GOARCH=arm64 TAG=$(TAG)-arm64 BINARY=pixiecore REGISTRY=$(REGISTRY) + make -f Makefile.inc push GOARCH=ppc64le TAG=$(TAG)-ppc64le BINARY=pixiecore REGISTRY=$(REGISTRY) + make -f Makefile.inc push GOARCH=s390x TAG=$(TAG)-s390x BINARY=pixiecore REGISTRY=$(REGISTRY) + manifest-tool push from-args --platforms linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x --template $(REGISTRY)/pixiecore:$(TAG)-ARCH --target $(REGISTRY)/pixiecore:$(TAG) + +.PHONY: ci-config +ci-config: + (cd .circleci && go run gen-config.go >config.yml) + .PHONY: update-ipxe update-ipxe: # rm -rf third_party/ipxe diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000..6986558 --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,64 @@ +# -*- mode: makefile-gmake -*- + +# Inputs. Invoke from the parent makefile with these options set. +GOARCH:= +BINARY:= +TAG:= +REGISTRY:= +GOCMD:=go +DOCKER_SUDO:= +GITCOMMIT:= +GITBRANCH:= + +ifeq ($(GOARCH),) + $(error GOARCH not specified) +endif +ifeq ($(BINARY),) + $(error BINARY not specified) +endif +ifeq ($(TAG),) + $(error TAG not specified) +endif +ifeq ($(REGISTRY),) + $(error REGISTRY not specified) +endif + +# Other variables. +GITCOMMIT:=$(shell git describe --dirty --always) +BUILD_DIR:=build/$(GOARCH)/$(BINARY) +DOCKERCMD:=docker +ifneq ($(DOCKER_SUDO),) + DOCKERCMD:=sudo docker +endif +DOCKERFILE_BASE:=alpine:latest +ifneq ($(GOARCH),amd64) + DOCKERFILE_BASE:=$(GOARCH)/alpine:latest +endif +ifeq ($(GOARCH),arm) + DOCKERFILE_BASE:=arm32v6/alpine:latest +endif +ifeq ($(GOARCH),arm64) + DOCKERFILE_BASE:=arm64v8/alpine:latest +endif + +.PHONY: push +push: image + $(DOCKERCMD) push $(REGISTRY)/$(BINARY):$(TAG) + +.PHONY: image +image: dockerfile binary + $(DOCKERCMD) build -t $(REGISTRY)/$(BINARY):$(TAG) $(BUILD_DIR) + +.PHONY: dockerfile +dockerfile: build-dir + perl -pe "s#alpine:latest#$(DOCKERFILE_BASE)#g" ./cmd/$(BINARY)/Dockerfile >$(BUILD_DIR)/Dockerfile + +.PHONY: binary +binary: build-dir + CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) GOARM=6 \ + $(GOCMD) build -o $(BUILD_DIR)/$(BINARY) \ + go.universe.tf/netboot/cmd/$(BINARY) + +.PHONY: build-dir +build-dir: + mkdir -p $(BUILD_DIR) diff --git a/cmd/pixiecore/Dockerfile b/cmd/pixiecore/Dockerfile new file mode 100644 index 0000000..4682700 --- /dev/null +++ b/cmd/pixiecore/Dockerfile @@ -0,0 +1,4 @@ +FROM alpine:latest + +ADD pixiecore /pixiecore +ENTRYPOINT ["/pixiecore"]