-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds required `GCLOUD_SDK_VERSION` `--build-arg` to `Dockerfile` - removes `Dockerfile.1.10`, `Dockerfile.1.11` (can now be customized via `GCLOUD_SDK_VERSION` build arg) - removes `bin/dist`; replaced with `make`-based implementation - adds several misc config / rc files - updates `README`, `DOCS.md` to reflect changes, address linting
- Loading branch information
Showing
12 changed files
with
371 additions
and
114 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.git | ||
.github | ||
.vscode | ||
local-example | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.go] | ||
indent_style = tab | ||
|
||
[{go.mod,go.sum}] | ||
indent_style = tab | ||
|
||
[Makefile] | ||
indent_style = tab |
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,2 @@ | ||
/drone-gke | ||
.vscode |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
# latest kubectl in the SDK | ||
# https://cloud.google.com/sdk/docs/release-notes | ||
FROM google/cloud-sdk:alpine | ||
|
||
# Install kubectl | ||
RUN gcloud components install kubectl && \ | ||
rm -rf ./google-cloud-sdk/.install | ||
# see https://hub.docker.com/r/google/cloud-sdk/tags for available tags / versions | ||
ARG GCLOUD_SDK_VERSION | ||
|
||
FROM google/cloud-sdk:${GCLOUD_SDK_VERSION} AS cloud-sdk | ||
ENV CLOUDSDK_CONTAINER_USE_APPLICATION_DEFAULT_CREDENTIALS=true | ||
ENV CLOUDSDK_CORE_DISABLE_PROMPTS=1 | ||
ADD bin/install-kubectl /usr/local/bin/ | ||
RUN install-kubectl && rm -f /usr/local/bin/install-kubectl | ||
|
||
# Add the Drone plugin | ||
ADD drone-gke /bin/ | ||
|
||
ENTRYPOINT ["/bin/drone-gke"] | ||
FROM cloud-sdk | ||
ADD drone-gke /usr/local/bin/ | ||
ENTRYPOINT ["drone-gke"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,191 @@ | ||
# executables | ||
docker := $(shell which docker) --log-level error | ||
gcloud := $(shell which gcloud) --quiet --verbosity=error | ||
git := $(shell which git) | ||
go := $(shell which go) | ||
kubectl := $(shell which kubectl) | ||
|
||
# plugin's binary options | ||
binary_name = drone-gke | ||
|
||
# git options | ||
git_default_branch = $(shell cat $(CURDIR)/.git/refs/remotes/origin/HEAD | cut -d ' ' -f 2 | cut -d '/' -f 4) | ||
git_current_branch = $(shell $(git) rev-parse --abbrev-ref HEAD) | ||
git_current_revision = $(shell $(git) rev-parse --short HEAD) | ||
|
||
# plugin's docker options | ||
docker_default_repo_name = nytimes | ||
docker_image_name = drone-gke | ||
docker_default_tag = latest | ||
ifneq ($(git_current_branch), $(git_default_branch)) | ||
docker_default_tag = $(git_current_branch) | ||
endif | ||
docker_default_file = $(CURDIR)/Dockerfile | ||
docker_default_build_context = $(CURDIR) | ||
|
||
# gcloud SDK options | ||
gcloud_sdk_image_name = google/cloud-sdk | ||
gcloud_default_sdk_version = alpine | ||
|
||
# print usage (default target) | ||
usage : | ||
@echo "Usage:" | ||
@echo "" | ||
@echo " \$$ make check # run tests for required software" | ||
@echo " \$$ make clean # delete plugin binary, docker image" | ||
@echo " \$$ make dist # build and push plugin docker image" | ||
@echo " \$$ make docker-image # build plugin docker image" | ||
@echo " \$$ make docker-release # push plugin docker image" | ||
@echo " \$$ make docker-run-local # run docker container using local-example" | ||
@echo " \$$ make $(binary_name) # build plugin binary" | ||
@exit 0 | ||
|
||
.PHONY : usage | ||
|
||
# check that docker is installed | ||
check-docker : | ||
ifneq (0,$(shell command -v $(docker) 2>&1 >/dev/null ; echo $$?)) | ||
$(error "docker not installed") | ||
else | ||
@exit 0 | ||
endif | ||
|
||
.PHONY : check-docker | ||
|
||
# check that gcloud is installed | ||
check-gcloud : | ||
ifneq (0,$(shell command -v $(gcloud) 2>&1 >/dev/null ; echo $$?)) | ||
$(error "gcloud not installed") | ||
else | ||
@exit 0 | ||
endif | ||
|
||
.PHONY : check-gcloud | ||
|
||
# check that git is installed | ||
check-git : | ||
ifneq (0,$(shell command -v $(git) 2>&1 >/dev/null ; echo $$?)) | ||
$(error "git not installed") | ||
else | ||
@exit 0 | ||
endif | ||
|
||
.PHONY : check-git | ||
|
||
# check that go is installed | ||
check-go : | ||
ifneq (0,$(shell command -v $(go) 2>&1 >/dev/null ; echo $$?)) | ||
$(error "go not installed") | ||
else | ||
@exit 0 | ||
endif | ||
|
||
.PHONY : check-go | ||
|
||
# check that kubectl is installed | ||
check-kubectl : | ||
ifneq (0,$(shell command -v $(kubectl) 2>&1 >/dev/null ; echo $$?)) | ||
$(error "kubectl not installed") | ||
else | ||
@exit 0 | ||
endif | ||
|
||
.PHONY : check-kubectl | ||
|
||
# check that all required executables are installed | ||
check : check-docker check-gcloud check-git check-go check-kubectl | ||
|
||
.PHONY : check | ||
|
||
# clean configuration | ||
clean : export docker_repo_name ?= $(docker_default_repo_name) | ||
clean : export docker_tag ?= $(docker_default_tag) | ||
|
||
# delete binary, docker image | ||
clean : | ||
@rm -f $(binary_name) | ||
@$(docker) rmi --force $(docker_repo_name)/$(docker_image_name):$(docker_tag) 2>/dev/null | ||
|
||
.PHONY : clean | ||
|
||
# compilation configuration | ||
$(binary_name) : export CGO_ENABLED ?= 0 | ||
$(binary_name) : export GO111MODULE ?= on | ||
$(binary_name) : export GOARCH ?= amd64 | ||
$(binary_name) : export GOOS ?= linux | ||
$(binary_name) : export GOPROXY ?= https://proxy.golang.org | ||
$(binary_name) : export revision ?= $(git_current_revision) | ||
|
||
# compile binary | ||
$(binary_name) : main.go exec.go go.sum | ||
@$(go) build -a -ldflags "-X main.rev=$(revision)" | ||
|
||
# docker build configuration | ||
docker-image : export docker_build_context ?= $(docker_default_build_context) | ||
docker-image : export docker_file ?= $(docker_default_file) | ||
docker-image : export docker_repo_name ?= $(docker_default_repo_name) | ||
docker-image : export docker_tag ?= $(docker_default_tag) | ||
docker-image : export gcloud_sdk_version ?= $(gcloud_default_sdk_version) | ||
|
||
# build docker image | ||
docker-image : $(binary_name) $(docker_file) | ||
@$(docker) build \ | ||
--build-arg GCLOUD_SDK_VERSION=$(gcloud_sdk_version) \ | ||
--tag $(docker_repo_name)/$(docker_image_name):$(docker_tag) \ | ||
--file $(docker_file) $(docker_build_context) | ||
|
||
.PHONY : docker-image | ||
|
||
# docker push configuration | ||
docker-release : export docker_repo_name ?= $(docker_default_repo_name) | ||
docker-release : export docker_tag ?= $(docker_default_tag) | ||
|
||
# push docker image | ||
docker-release : | ||
@$(docker) push $(docker_repo_name)/$(docker_image_name):$(docker_tag) | ||
|
||
.PHONY : docker-release | ||
|
||
# compile binary, build and push docker image | ||
dist : docker-image docker-release | ||
|
||
# local docker run configuration | ||
docker-run-local : export CONFIG_HOME ?= $(CURDIR)/local-example | ||
docker-run-local : export GOOGLE_APPLICATION_CREDENTIALS ?= xxx | ||
docker-run-local : export PLUGIN_CLUSTER ?= yyy | ||
docker-run-local : export PLUGIN_NAMESPACE ?= drone-gke | ||
docker-run-local : export PLUGIN_SECRET_TEMPLATE ?= $(CONFIG_HOME)/.kube.sec.yml | ||
docker-run-local : export PLUGIN_TEMPLATE ?= $(CONFIG_HOME)/.kube.yml | ||
docker-run-local : export PLUGIN_VARS_PATH ?= $(CONFIG_HOME)/vars.json | ||
docker-run-local : export PLUGIN_ZONE ?= zzz | ||
docker-run-local : export SECRET_API_TOKEN ?= 123 | ||
docker-run-local : export SECRET_BASE64_P12_CERT ?= "cDEyCg==" | ||
docker-run-local : export docker_repo_name ?= $(docker_default_repo_name) | ||
docker-run-local : export docker_tag ?= $(docker_default_tag) | ||
docker-run-local : export docker_cmd ?= --dry-run --verbose | ||
|
||
# run docker container using local-example | ||
docker-run-local : | ||
@[ -d $(CONFIG_HOME) ] || ( echo "$(CONFIG_HOME) does not exist" ; exit 1 ) | ||
@[ -f $(PLUGIN_SECRET_TEMPLATE) ] || ( echo "$(PLUGIN_SECRET_TEMPLATE) does not exist" ; exit 1 ) | ||
@[ -f $(PLUGIN_TEMPLATE) ] || ( echo "$(PLUGIN_TEMPLATE) does not exist" ; exit 1 ) | ||
@[ -f $(PLUGIN_VARS_PATH) ] || ( echo "$(PLUGIN_VARS_PATH) does not exist" ; exit 1 ) | ||
@[ -f $(GOOGLE_APPLICATION_CREDENTIALS) ] || ( echo "$(GOOGLE_APPLICATION_CREDENTIALS) does not exist" ; exit 1 ) | ||
@cd $(CONFIG_HOME) ; \ | ||
$(docker) run \ | ||
--env PLUGIN_CLUSTER=$(PLUGIN_CLUSTER) \ | ||
--env PLUGIN_NAMESPACE=$(PLUGIN_NAMESPACE) \ | ||
--env PLUGIN_SECRET_TEMPLATE=$(PLUGIN_SECRET_TEMPLATE) \ | ||
--env PLUGIN_TEMPLATE=$(PLUGIN_TEMPLATE) \ | ||
--env PLUGIN_VARS="$$(cat $(PLUGIN_VARS_PATH))" \ | ||
--env PLUGIN_ZONE=$(PLUGIN_ZONE) \ | ||
--env SECRET_API_TOKEN=$(SECRET_API_TOKEN) \ | ||
--env SECRET_BASE64_P12_CERT=$(SECRET_BASE64_P12_CERT) \ | ||
--env TOKEN="$$(cat $(GOOGLE_APPLICATION_CREDENTIALS))" \ | ||
--volume $(CONFIG_HOME):$(CONFIG_HOME) \ | ||
--workdir $(CONFIG_HOME) \ | ||
$(docker_repo_name)/$(docker_image_name):$(docker_tag) $(docker_cmd) | ||
|
||
.PHONY : docker-run-local | ||
|
||
.PHONY : dist |
Oops, something went wrong.