Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
ci: updated build/ci support
Browse files Browse the repository at this point in the history
Added Makefile, updated Dockerfilem added .drone.yml

Signed-off-by: Jacob Blain Christen <[email protected]>
  • Loading branch information
dweomer committed Jan 22, 2021
1 parent 459b650 commit ed933df
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/bin/
/dist/
/k3c
104 changes: 104 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
kind: pipeline
type: docker
name: amd64

platform:
os: linux
arch: amd64

steps:
- name: build-binaries
image: rancher/dapper:v0.5.0
environment:
GOLANG: golang:1.16beta1-alpine
commands:
- dapper -f Dockerfile --target dapper make GOOS=linux GOARCH=amd64 DRONE_TAG=${DRONE_TAG} dist
- dapper -f Dockerfile --target dapper make GOOS=linux GOARCH=arm64 DRONE_TAG=${DRONE_TAG} dist
- dapper -f Dockerfile --target dapper make GOOS=darwin GOARCH=amd64 DRONE_TAG=${DRONE_TAG} dist
- dapper -f Dockerfile --target dapper make GOOS=darwin GOARCH=arm64 DRONE_TAG=${DRONE_TAG} dist
- dapper -f Dockerfile --target dapper make GOOS=windows GOARCH=amd64 DRONE_TAG=${DRONE_TAG} dist
volumes:
- name: docker
path: /var/run/docker.sock

- name: publish-binaries
image: plugins/github-release
settings:
api_key:
from_secret: github_token
checksum:
- sha256
checksum_file: CHECKSUMsum.txt
checksum_flatten: true
files:
- dist/artifacts/*
prerelease: true
when:
event:
- tag
instance:
- drone-publish.rancher.io
ref:
- refs/head/master
- refs/tags/*

- name: publish-images
image: rancher/dapper:v0.5.0
commands:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- make DRONE_TAG=${DRONE_TAG} publish
environment:
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
when:
event:
- tag
instance:
- drone-publish.rancher.io
ref:
- refs/head/master
- refs/tags/*

volumes:
- name: docker
host:
path: /var/run/docker.sock

---
kind: pipeline
type: docker
name: arm64

platform:
os: linux
arch: arm64

steps:
- name: publish-images
image: rancher/dapper:v0.5.0
commands:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- make DRONE_TAG=${DRONE_TAG} publish
environment:
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
when:
event:
- tag
instance:
- drone-publish.rancher.io
ref:
- refs/head/master
- refs/tags/*

volumes:
- name: docker
host:
path: /var/run/docker.sock

...
27 changes: 21 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG GOLANG=golang:1.15-alpine
FROM ${GOLANG} AS build
FROM ${GOLANG} AS base
RUN apk --no-cache add \
file \
gcc \
Expand All @@ -13,13 +13,28 @@ RUN apk --no-cache add \
RUN GO111MODULE=on go get github.com/gogo/protobuf/[email protected]
COPY . /go/src/k3c
WORKDIR /go/src/k3c
ENV CGO_ENABLED=1
ENV GO_BUILDTAGS="seccomp,selinux,static_build,netgo,osusergo"

FROM base AS dapper
RUN apk --no-cache add docker-cli
ENV DAPPER_ENV GOLANG GODEBUG GOARCH GOOS ORG TAG DRONE_TAG DRONE_BUILD_EVENT
ARG DAPPER_HOST_ARCH
ENV GOARCH $DAPPER_HOST_ARCH
ENV DAPPER_SOURCE /go/src/k3c
ENV DAPPER_OUTPUT ./dist ./bin
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_TARGET dapper
ENV DAPPER_RUN_ARGS "--privileged --network host -v k3c-pkg:/go/pkg -v k3c-cache:/root/.cache/go-build"
RUN go version

FROM base AS build
RUN go mod vendor
RUN go generate -x
#RUN go build -ldflags '-w -linkmode=external -extldflags=-static' -tags="${GO_BUILDTAGS}" -o /usr/local/bin/k3c .
RUN go build -ldflags '-w -extldflags=-static' -tags="${GO_BUILDTAGS}" -o /usr/local/bin/k3c .
RUN file /usr/local/bin/k3c
ARG ORG=rancher
ARG PKG=github.com/rancher/k3c
ARG TAG=0.0.0-dev
RUN make bin/k3c ORG=${ORG} PKG=${PKG} TAG=${TAG}
RUN file bin/k3c
RUN install -s bin/k3c -m 0755 /usr/local/bin

FROM scratch AS release
COPY --from=build /usr/local/bin/k3c /bin/k3c
Expand Down
90 changes: 90 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
ifeq ($(GOARCH),)
GOARCH := $(shell go env GOARCH)
endif

ifeq ($(GOOS),)
GOOS := $(shell go env GOOS)
endif

ifneq ($(DRONE_TAG),)
TAG := $(DRONE_TAG)
endif

DOCKER_BUILDKIT ?= 1

ORG ?= rancher
PKG ?= github.com/rancher/k3c
TAG ?= v0.0.0-dev

ifeq ($(GO_BUILDTAGS),)
GO_BUILDTAGS := static_build,netgo,osusergo
#ifeq ($(GOOS),linux)
#GO_BUILDTAGS := $(GO_BUILDTAGS),seccomp,selinux
#endif
endif

GO_LDFLAGS ?= -w -extldflags=-static
GO_LDFLAGS += -X $(PKG)/pkg/version.GitCommit=$(shell git rev-parse HEAD)
GO_LDFLAGS += -X $(PKG)/pkg/version.Version=$(TAG)
GO_LDFLAGS += -X $(PKG)/pkg/server.DefaultAgentImage=docker.io/$(ORG)/k3c

GO ?= go
GOLANG ?= docker.io/library/golang:1.15-alpine
ifeq ($(GOOS),windows)
BINSUFFIX := .exe
endif
BIN ?= bin/k3c
BIN := $(BIN)$(BINSUFFIX)

.PHONY: build package validate ci publish
build: $(BIN)
package: | dist image-build
validate:
publish: | image-build image-push image-manifest
ci: | build package validate
.PHONY: $(BIN)
$(BIN):
$(GO) build -ldflags "$(GO_LDFLAGS)" -tags "$(GO_BUILDTAGS)" -o $@ .

.PHONY: dist
dist:
@mkdir -p dist/artifacts
@make GOOS=$(GOOS) GOARCH=$(GOARCH) BIN=dist/artifacts/k3c-$(GOOS)-$(GOARCH)$(BINSUFFIX) -C .

.PHONY: clean
clean:
rm -rf bin dist

.PHONY: image-build
image-build:
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build \
--build-arg GOLANG=$(GOLANG) \
--build-arg ORG=$(ORG) \
--build-arg PKG=$(PKG) \
--build-arg TAG=$(TAG) \
--tag $(ORG)/k3c:$(TAG) \
--tag $(ORG)/k3c:$(TAG)-$(GOARCH) \
.

.PHONY: image-push
image-push:
docker push $(ORG)/k3c:$(TAG)-$(GOARCH)

.PHONY: image-manifest
image-manifest:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend \
$(ORG)/k3c:$(TAG) \
$(ORG)/k3c:$(TAG)-$(GOARCH)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push \
$(ORG)/k3c:$(TAG)

./.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/v0.5.0/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp
@@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper

dapper-%: .dapper
@mkdir -p ./bin/ ./dist/
env DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) ./.dapper -f Dockerfile --target dapper make $*
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ because the `containerd` client code assumes a certain level of co-locality with
# git clone --branch=trunk https://github.com/rancher/k3c.git ~/Projects/rancher/k3c
# cd ~/Projects/rancher/k3c
go generate # only necessary when modifying the gRPC protobuf IDL, see Dockerfile for pre-reqs
go build -ldflags '-w -extldflags=-static' -tags="seccomp,selinux,static_build,netgo,osusergo" .
# only needed until @dweomer gets the automated builds publishing again
docker build --tag your/image:tag .
docker push your/image:tag
make ORG=<your-dockerhub-org> build publish
```

## Running
Expand All @@ -60,12 +57,12 @@ Have a working `k3s` installation with a working `$HOME/.kube/config` or `$KUBEC

```bash
# Installation on a single-node cluster
./k3c install --agent-image=docker.io/your/image:tag
./k3c install --agent-image=docker.io/${ORG}/k3c
```

```bash
# Installation on a multi-node cluster, targeting a Node named "my-builder-node"
./k3c install --agent-image=docker.io/your/image:tag --selector k3s.io/hostname=my-builder-node
./k3c install --agent-image=docker.io/${ORG}/k3c --selector k3s.io/hostname=my-builder-node

```

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/rancher/wrangler-cli v0.0.0-20200815040857-81c48cf8ab43
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.1
golang.org/dl v0.0.0-20210120004500-be2bfd84e4cf // indirect
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
google.golang.org/grpc v1.29.1
k8s.io/api v0.19.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,8 @@ go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
gocloud.dev v0.19.0/go.mod h1:SmKwiR8YwIMMJvQBKLsC3fHNyMwXLw3PMDO+VVteJMI=
golang.org/dl v0.0.0-20210120004500-be2bfd84e4cf h1:oJo1nNktpOIZ5JOFRqbGRNdm2xpqA2mGfv1AOnnDxPE=
golang.org/dl v0.0.0-20210120004500-be2bfd84e4cf/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
golang.org/x/build v0.0.0-20190314133821-5284462c4bec/go.mod h1:atTaCNAy0f16Ah5aV1gMSwgiKVHwu/JncqDpuRr7lS4=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down

0 comments on commit ed933df

Please sign in to comment.