This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Makefile, updated Dockerfilem added .drone.yml Signed-off-by: Jacob Blain Christen <[email protected]>
- Loading branch information
Showing
7 changed files
with
223 additions
and
12 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 +1,3 @@ | ||
/bin/ | ||
/dist/ | ||
/k3c |
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,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 | ||
|
||
... |
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,5 +1,5 @@ | ||
ARG GOLANG=golang:1.15-alpine | ||
FROM ${GOLANG} AS build | ||
FROM ${GOLANG} AS base | ||
RUN apk --no-cache add \ | ||
file \ | ||
gcc \ | ||
|
@@ -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 | ||
|
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,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 $* |
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
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
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