-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use Kaniko for builds (#86)
- Loading branch information
1 parent
0fdd552
commit 8ced588
Showing
32 changed files
with
336 additions
and
1,263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
metadata: | ||
repository: autonomy/conform | ||
variables: | ||
linuxBinaryPath: /conform-linux-amd64 | ||
darwinBinaryPath: /conform-darwin-amd64 | ||
gitRepository: github.com/autonomy/conform | ||
maintainer: Andrew Rynhard <[email protected]> | ||
policies: | ||
- type: conventionalCommit | ||
spec: | ||
|
@@ -16,96 +9,5 @@ policies: | |
- style | ||
- test | ||
scopes: | ||
- ci | ||
- cli | ||
- docker | ||
- fmt | ||
- git | ||
- metadata | ||
- pipeline | ||
- policy | ||
- readme | ||
- renderer | ||
- service | ||
- '*' | ||
script: | ||
template: | | ||
#!/bin/bash | ||
set -e | ||
{{ if and (.Git.IsClean) (or (.Git.IsTag) (eq .Git.Branch "master")) }} | ||
docker login --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD | ||
docker tag {{ .Docker.Image.Name }}:{{ .Docker.Image.Tag }} {{ .Docker.Image.Name }}:latest | ||
docker push {{ .Docker.Image.Name }}:{{ .Docker.Image.Tag }} | ||
docker push {{ .Docker.Image.Name }}:latest | ||
{{ if .Git.IsTag }} | ||
docker tag {{ .Docker.Image.Name }}:{{ .Docker.Image.Tag }} {{ .Docker.Image.Name }}:{{ .Version.Original }} | ||
docker push {{ .Docker.Image.Name }}:{{ .Version.Original }} | ||
{{ end }} | ||
{{ end }} | ||
pipeline: | ||
stages: | ||
- src | ||
- test | ||
- build | ||
- image | ||
stages: | ||
build: | ||
artifacts: | ||
- source: /conform-linux-amd64 | ||
destination: ./build/conform-linux-amd64 | ||
- source: /conform-darwin-amd64 | ||
destination: ./build/conform-darwin-amd64 | ||
tasks: | ||
- build | ||
image: | ||
tasks: | ||
- image | ||
src: | ||
tasks: | ||
- src | ||
test: | ||
artifacts: | ||
- source: /src/github.com/autonomy/conform/coverage.txt | ||
destination: coverage.txt | ||
tasks: | ||
- test | ||
tasks: | ||
build: | ||
template: | | ||
FROM autonomy/conform:src AS {{ .Docker.CurrentStage }} | ||
{{ if and .Git.IsClean .Git.IsTag }} | ||
RUN go build -o {{ index .Variables "linuxBinaryPath" }} -ldflags "-s -w -X \"{{ index .Variables "gitRepository" }}/cmd.Tag={{ trimAll "v" .Git.Tag }}\" -X \"{{ index .Variables "gitRepository" }}/cmd.SHA={{ .Git.SHA }}\" -X \"{{ index .Variables "gitRepository" }}/cmd.Built={{ .Built }}\"" | ||
RUN GOOS=darwin go build -o {{ index .Variables "darwinBinaryPath" }} -ldflags "-s -w -X \"{{ index .Variables "gitRepository" }}/cmd.Tag={{ trimAll "v" .Git.Tag }}\" -X \"{{ index .Variables "gitRepository" }}/cmd.SHA={{ .Git.SHA }}\" -X \"{{ index .Variables "gitRepository" }}/cmd.Built={{ .Built }}\"" | ||
{{ else if .Git.IsClean }} | ||
RUN go build -o {{ index .Variables "linuxBinaryPath" }} -ldflags "-s -w -X \"{{ index .Variables "gitRepository" }}/cmd.SHA={{ .Git.SHA }}\" -X \"{{ index .Variables "gitRepository" }}/cmd.Built={{ .Built }}\"" | ||
RUN GOOS=darwin go build -o {{ index .Variables "darwinBinaryPath" }} -ldflags "-s -w -X \"{{ index .Variables "gitRepository" }}/cmd.SHA={{ .Git.SHA }}\" -X \"{{ index .Variables "gitRepository" }}/cmd.Built={{ .Built }}\"" | ||
{{ else }} | ||
RUN go build -o {{ index .Variables "linuxBinaryPath" }} | ||
RUN GOOS=darwin go build -o {{ index .Variables "darwinBinaryPath" }} | ||
{{ end }} | ||
image: | ||
template: | | ||
FROM alpine:3.8 AS {{ .Docker.CurrentStage }} | ||
LABEL maintainer="{{ index .Variables "maintainer" }}" | ||
RUN apk --no-cache add bash | ||
COPY --from={{ .Repository}}:build {{ index .Variables "linuxBinaryPath" }} /bin/conform | ||
ENTRYPOINT ["conform"] | ||
src: | ||
template: | | ||
FROM golang:1.11.1 AS {{ .Docker.CurrentStage }} | ||
ENV GO111MODULE on | ||
ENV CGO_ENABLED 0 | ||
WORKDIR /src/{{ index .Variables "gitRepository" }} | ||
COPY ./ ./ | ||
RUN go mod download | ||
RUN go mod verify | ||
test: | ||
template: | | ||
FROM autonomy/conform:src AS {{ .Docker.CurrentStage }} | ||
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.10.1 | ||
RUN chmod +x ./hack/test.sh | ||
RUN ./hack/test.sh --lint ./hack/golangci-lint.yaml | ||
RUN ./hack/test.sh --unit | ||
RUN ./hack/test.sh --coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
conform-* | ||
coverage.txt | ||
build | ||
cache | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
ARG GOLANG_IMAGE | ||
FROM ${GOLANG_IMAGE} | ||
|
||
ENV CGO_ENABLED 0 | ||
ENV GO111MODULES on | ||
|
||
WORKDIR /conform | ||
COPY ./ ./ | ||
RUN go mod download | ||
RUN go mod verify | ||
RUN go mod tidy | ||
RUN go mod vendor | ||
|
||
ARG TAG | ||
ARG SHA | ||
ARG BUILT | ||
ENV GOOS linux | ||
ENV GOARCH amd64 | ||
RUN go build -o /build/conform-${GOOS}-${GOARCH} -ldflags "-s -w -X \"github.com/autonomy/conform/cmd.Tag=${TAG}\" -X \"github.com/autonomy/conform/cmd.SHA=${SHA}\" -X \"github.com/autonomy/conform/cmd.Built=${BUILT}\"" . | ||
|
||
ARG TAG | ||
ARG SHA | ||
ARG BUILT | ||
ENV GOOS darwin | ||
ENV GOARCH amd64 | ||
RUN go build -o /build/conform-${GOOS}-${GOARCH} -ldflags "-s -w -X \"github.com/autonomy/conform/cmd.Tag=${TAG}\" -X \"github.com/autonomy/conform/cmd.SHA=${SHA}\" -X \"github.com/autonomy/conform/cmd.Built=${BUILT}\"" . | ||
|
||
ENV GOOS linux | ||
ENV GOARCH amd64 | ||
COPY ./hack ./hack | ||
RUN chmod +x ./hack/test.sh | ||
RUN ./hack/test.sh --all | ||
|
||
FROM scratch | ||
COPY /build/conform-linux-amd64 /conform | ||
ENTRYPOINT [ "/conform" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
REPO ?= docker.io/autonomy | ||
EXECUTOR ?= gcr.io/kaniko-project/executor | ||
EXECUTOR_TAG ?= latest | ||
WARMER ?= gcr.io/kaniko-project/warmer | ||
WARMER_TAG ?= latest | ||
GOLANG_IMAGE ?= golang:1.11.2 | ||
AUTH_CONFIG ?= $(HOME)/.kaniko/config.json | ||
|
||
SHA := $(shell gitmeta git sha) | ||
TAG := $(shell gitmeta image tag) | ||
BUILT := $(shell gitmeta built) | ||
|
||
EXECUTOR_ARGS := --context=/workspace --cache=true --cache-dir=/cache --cleanup | ||
EXECUTOR_VOLUMES := --volume $(AUTH_CONFIG):/kaniko/.docker/config.json:ro --volume $(PWD)/cache:/cache --volume $(PWD)/build:/build | ||
|
||
all: enforce clean conform | ||
|
||
enforce: | ||
conform enforce | ||
|
||
conform: cache | ||
docker run \ | ||
--rm \ | ||
$(EXECUTOR_VOLUMES) \ | ||
--volume $(PWD):/workspace \ | ||
$(EXECUTOR):$(EXECUTOR_TAG) \ | ||
$(EXECUTOR_ARGS) \ | ||
--dockerfile=Dockerfile \ | ||
--cache-repo=$(REPO)/$@ \ | ||
--destination=$(REPO)/$@:$(TAG) \ | ||
--single-snapshot \ | ||
--no-push \ | ||
--build-arg GOLANG_IMAGE=$(GOLANG_IMAGE) \ | ||
--build-arg SHA=$(SHA) \ | ||
--build-arg TAG=$(TAG) \ | ||
--build-arg BUILT="$(BUILT)" | ||
|
||
.PHONY: cache | ||
cache: | ||
docker run \ | ||
--rm \ | ||
$(EXECUTOR_VOLUMES) \ | ||
$(WARMER):$(WARMER_TAG) \ | ||
--cache-dir=/cache \ | ||
--image=$(GOLANG_IMAGE) | ||
|
||
debug: | ||
docker run \ | ||
--rm \ | ||
-it \ | ||
$(EXECUTOR_VOLUMES) \ | ||
--volume $(PWD):/workspace \ | ||
--entrypoint=/busybox/sh \ | ||
$(EXECUTOR):debug | ||
|
||
clean: | ||
rm -rf ./build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.