Add a CircleCI configuration for building container images.

This commit is contained in:
David Anderson 2018-02-06 23:45:09 -08:00
parent 87f66d15c7
commit d63047cea3
7 changed files with 220 additions and 5 deletions

70
.circleci/config.yml Normal file
View File

@ -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

46
.circleci/config.yml.tmpl Normal file
View File

@ -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

19
.circleci/gen-config.go Normal file
View File

@ -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)
}
}

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ dhcp4/dhcp4.test
pcap/pcap.test
pixiecore/pixiecore.test
vendor/
build/

View File

@ -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

64
Makefile.inc Normal file
View File

@ -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)

4
cmd/pixiecore/Dockerfile Normal file
View File

@ -0,0 +1,4 @@
FROM alpine:latest
ADD pixiecore /pixiecore
ENTRYPOINT ["/pixiecore"]