Skip to content
Browse files

Merge pull request #109 from ethernetdan/gitlab-ci

Gitlab CI plugin
2 parents 6a0b54a + ee9345b commit ed9568bc689336f00f7f153b43567601351ebeda @ethernetdan ethernetdan committed
Showing with 147 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +26 −3 Makefile
  3. +8 −0 images/gitlabci/Dockerfile
  4. +65 −0 images/gitlabci/README.md
  5. +46 −0 images/gitlabci/entrypoint.sh
View
2 .gitignore
@@ -23,3 +23,5 @@ _testmain.go
*.exe
*.test
*.prof
+
+build/
View
29 Makefile
@@ -11,14 +11,26 @@ GO ?= go
GOX ?= gox
GOFMT ?= gofmt # eventually should add "-s"
GOLINT ?= golint
+DOCKER ?= docker
GOFILES := find . -name '*.go' -not -path "./vendor/*"
GOBUILD_LDFLAGS ?=
-GOBUILD_FLAGS ?=
+GOBUILD_FLAGS ?= -i -v
GOTEST_FLAGS ?= -v
GOX_FLAGS ?= -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" -os="${GOX_OS}" -arch="${GOX_ARCH}"
+STATIC_LDFLAGS ?= --ldflags '-extldflags "-static" --s -w'
+
+GITLAB_CONTEXT ?= ./build/gitlab
+
+# image data
+ORG ?= redspreadapps
+NAME ?= gitlabci
+TAG ?= latest
+
+GITLAB_IMAGE_NAME = "$(ORG)/$(NAME):$(TAG)"
+
GOX_OS ?= linux darwin windows
GOX_ARCH ?= amd64
@@ -37,12 +49,23 @@ validate: lint checkgofmt vet
.PHONY: build
build:
- $(GO) install $(GOBUILD_FLAGS) $(GOBUILD_LDFLAGS) $(EXEC_PKG)
+ $(GO) build $(GOBUILD_FLAGS) $(GOBUILD_LDFLAGS) $(EXEC_PKG)
+
+build/spread-linux-static:
+ GOOS=linux $(GO) build -o $@ $(GOBUILD_FLAGS) $(STATIC_LDFLAGS) $(EXEC_PKG)
+ chmod +x $@
.PHONY: crossbuild
crossbuild: deps gox-setup
$(GOX) $(GOX_FLAGS) -gcflags="$(GOBUILD_FLAGS)" -ldflags="$(GOBUILD_LDFLAGS)" $(EXEC_PKG)
+.PHONY: build-gitlab
+build-gitlab: build/spread-linux-static
+ rm -rf $(GITLAB_CONTEXT)
+ cp -r ./images/gitlabci $(GITLAB_CONTEXT)
+ cp ./build/spread-linux-static $(GITLAB_CONTEXT)
+ $(DOCKER) build $(DOCKER_OPTS) -t $(GITLAB_IMAGE_NAME) $(GITLAB_CONTEXT)
+
.PHONY: vet
vet:
$(GO) vet $(PKGS)
@@ -86,4 +109,4 @@ godep:
@echo "Recalculating godeps, removing Godeps and vendor if not canceled in 5 seconds"
@sleep 5
rm -rf Godeps vendor
- GO15VENDOREXPERIMENT="1" godep save -v ./pkg/... ./cli/... ./cmd/...
+ GO15VENDOREXPERIMENT="1" godep save -v ./pkg/... ./cli/... ./cmd/...
View
8 images/gitlabci/Dockerfile
@@ -0,0 +1,8 @@
+FROM docker:git
+
+ADD spread-linux-static /usr/local/bin/spread
+ADD entrypoint.sh /opt/spread-gitlab/entrypoint.sh
+
+ENV KUBECFG_INSECURE_SKIP_TLS_VERIFY="false"
+
+ENTRYPOINT ["/opt/spread-gitlab/entrypoint.sh"]
View
65 images/gitlabci/README.md
@@ -0,0 +1,65 @@
+# Gitlab Spread Plugin
+
+This plugin allows you to add `spread` Kubernetes deployment to your Gitlab CI build pipeline.
+
+## Environment Variables
+
+These environment variables can be used to configure the deployment.
+
+### spread
+
+`DEPLOY_DIR`
+
+The directory spread should be deployed from
+
+
+### Cluster
+`KUBECFG_SERVER`
+
+Address of the Kubernetes API Server (https://hostname:port)
+
+`KUBECFG_API_VERSION`
+
+Preferred api version for communicating with the kubernetes cluster (v1, v2, etc)
+
+`KUBECFG_INSECURE_SKIP_TLS_VERIFY`
+
+Disable requirement that connections must pass TLS verification
+
+`KUBECFG_CERTIFICATE_AUTHORITY`
+
+Path to a cert file for the certificate authority.
+
+`KUBECFG_CERTIFICATE_AUTHORITY_DATA`
+
+Certificate data
+
+### User
+
+`KUBECFG_CLIENT_CERTIFICATE`
+
+Path to a client cert file for TLS
+
+`KUBECFG_CLIENT_CERTIFICATE_DATA`
+
+TLS client cert data
+
+`KUBECFG_CLIENT_KEY`
+
+Path to a client key file for TLS.
+
+`KUBECFG_CLIENT_KEY_DATA`
+
+Key data
+
+`KUBECFG_TOKEN`
+
+Bearer token for cluster auth
+
+`KUBECFG_USERNAME`
+
+Username for basic auth
+
+`KUBECFG_PASSWORD`
+
+Password for basic auth
View
46 images/gitlabci/entrypoint.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# if config file does not exist produce one with env vars
+if [ ! -f ~/.kube/config ]; then
+ echo "setting up kubectl config"
+ mkdir -p ~/.kube
+
+ >~/.kube/config cat <<EOF
+kind: Config
+apiVersion: v1
+current-context: gitlab
+contexts:
+- name: gitlab
+ context:
+ cluster: default
+ user: default
+clusters:
+- name: default
+ cluster:
+ server: $KUBECFG_SERVER
+ api-version: $KUBECFG_API_VERSION
+ insecure-skip-tls-verify: $KUBECFG_INSECURE_SKIP_TLS_VERIFY
+ certificate-authority: $KUBECFG_CERTIFICATE_AUTHORITY
+ certificate-authority-data: $KUBECFG_CERTIFICATE_AUTHORITY_DATA
+
+users:
+- name: default
+ user:
+ client-certificate: $KUBECFG_CLIENT_CERTIFICATE
+ client-certificate-data: $KUBECFG_CLIENT_CERTIFICATE_DATA
+ client-key: $KUBECFG_CLIENT_KEY
+ client-key-data: $KUBECFG_CLIENT_KEY_DATA
+ token: $KUBECFG_TOKEN
+ username: $KUBECFG_USERNAME
+ password: $KUBECFG_PASSWORD
+EOF
+fi
+
+if [ ! -z "$DEPLOY_DIR" ]; then
+ echo "using DEPLOY_DIR..."
+ spread deploy $DEPLOY_DIR
+ exit
+fi
+
+echo "Using project dir..."
+spread deploy $CI_PROJECT_DIR

0 comments on commit ed9568b

Please sign in to comment.
Something went wrong with that request. Please try again.