Verified Commit 3acf8551 authored by Xueshan Feng's avatar Xueshan Feng
Browse files

added sub-project.mk, update-repos. docker-registery.mk

parent 1616123d
Loading
Loading
Loading
Loading
+89 −0
Original line number Diff line number Diff line
################################################################################
# docker-registry.mk
################################################################################

ifndef ACME_URL
	export ACME_URL := https://acme-staging.api.letsencrypt.org/directory
endif

ifndef CERT_MANAGER_NS
	export CERT_MANAGER_NS := kube-system
endif

# NOTE cert-manager is not currently support set up renew-before-days, but the defualt is 30 days.
# See https://github.com/jetstack/cert-manager/blob/ce9e5ede2bc6d8ccbc8e4db086f84c17e3f4d3af/docs/user-guides/acme-http-validation.md
ifndef CERT_RENEW_BEFORE_DAYS
	export CERT_RENEW_BEFORE_DAYS := 30
endif

# TEMPLATES is the parent dir of the cert-manager/*.yaml files
ifndef TEMPLATES
	missing_vars := ${missing_vars} TEMPLATES
else
	CERT_TEMPLATES := ${TEMPLATES}/cert-manager
endif

.PHONY: create-cert-manager-ns
cert-manager-ns: config-kube ## create cert-manager namespace
	@if ! kubectl get namespace ${CERT_MANAGER_NS} &> /dev/null ; then \
		kubectl create namespace ${CERT_MANAGER_NS} ; \
	fi

# See Tiller issue on create RBAC: https://github.com/jetstack/cert-manager/issues/256
.PHONY: deploy-cert-manager
deploy-cert-manager: cert-manager-ns ## create the cert-manager
	@helm install \
    	--name cert-manager \
    	--namespace ${CERT_MANAGER_NS} \
		--set rbac.create=false \
    	stable/cert-manager || $(MAKE) deploy-cert-manager-wo-helm

.PHONY: deploy-cert-manager-wo-helm
deploy-cert-manager-wo-helm: CERT_CRD_RESOURCES := 00-namespace.yaml serviceaccount.yaml certificate-crd.yaml clusterissuer-crd.yaml deployment.yaml issuer-crd.yaml rbac.yaml
deploy-cert-manager-wo-helm:  ## Deploy cert manager, without helm
	@for i in ${CERT_CRD_RESOURCES}; do \
		kubectl apply -f ${CERT_TEMPLATES}/$$i ; \
	done

.PHONY: ls-cert-manager
ls-cert-manager: ## list the cert-manager
	@helm ls --all cert-manager

.PHONY: cert-manager-status
cert-manager-status: ## check cert-manager status
	@helm status cert-manager || kubectl describe deployment cert-manager -n ${CERT_MANAGER_NS}

.PHONY: update-cert-manager
update-cert-manager: config-kube ## Update the cert-manager deployment
update-cert-manager: CERT_CRD_RESOURCES := deployment.yaml
update-cert-manager: config-kube
	@for i in ${CERT_CRD_RESOURCES}; do \
		echo $$i ; \
		kubectl apply -f ${CERT_TEMPLATES}/$$i ; \
	done

.PHONY: destroy-cert-manager
destroy-cert-manager: config-kube ## destroy the cert-manager 
	@helm delete --purge cert-manager || $(MAKE) destroy-cert-manager-wo-helm
.PHONY: destroy-cert-manager-wo-helm
destroy-cert-manager-wo-helm: CERT_CRD_RESOURCES := certificate-crd.yaml clusterissuer-crd.yaml deployment.yaml issuer-crd.yaml rbac.yaml serviceaccount.yaml 00-namespace.yaml 
destroy-cert-manager-wo-helm: config-kube ## destroy the cert-manager
	@for i in ${CERT_CRD_RESOURCES}; do \
		echo $$i ; \
		kubectl delete -f ${CERT_TEMPLATES}/$$i ; \
	done
	
.PHONY: deploy-issuers
deploy-issuers: KUBE_SEC_DEF_FILE = ${CERT_TEMPLATES}/secret.yaml
deploy-issuers: kube-sec ## create cert issuers
	@kube_apply.sh ${CERT_TEMPLATES}/cert-issuers.yaml

.PHONY: destroy-issuer
destroy-issuers: destroy-kube-sec ## destroy cert issuers
	@kube_delete.sh ${CERT_TEMPLATES}/cert-issuers.yaml

.PHONY: show-issuers
show-issuers: ## show cert issuers
	@kubectl get clusterissuer,issuer --all-namespaces

## end of cert-manager.mk
+43 −0
Original line number Diff line number Diff line


################################################################################
## sub-projects.mk
################################################################################


ifndef SUB_PROJECTS
	missing_vars := ${missing_vars} SUB_PROJECTS
endif

# Targets for managing sub-projects
.PHONY: clone-repos
clone-repos: update-repos ## clone all related repos into sub-projeccts

.PHONY: update-repos
update-repos: repos.txt ## update all related repos in sub-projects
	git pull
	${SCRIPTS_DIR}/update-repos.sh repos.txt

.PHONY: repos-status
repos-status:  ## check status of the related repos
	git pull
	@cd ${SUB_PROJECTS} ; \
	for dir in `ls`; do \
		if [ -d $$dir ]; \
		then \
			echo Check git status $$dir; \
			cd $$dir; git status; cd ..; \
		fi; \
	done

.PHONY: clean-repos
clean-repos: ## remove all local clone of related repos in sub-projects
	@read -p "This will delete all the local repos, are you sure? [YES/NO] " ; \
	if [ "$$REPLY" = "YES" ] ; \
	then \
		echo "rm -rf ${SUB_PROJECTS}" ; \
		rm -rf ${SUB_PROJECTS} ; \
	else \
		echo "do nothing" ; \
	fi

update-repos.sh

0 → 100755
+59 −0
Original line number Diff line number Diff line
#!/bin/bash
#
# This scripts clone/update git repos defined in <repos.txt>.
# the <repos.txt> file is passed in by $1 and 
# must be in exact this format:
#   <git repo domain>/<namespaces>/<repo name>   <branch>
# 
# all repos will be cloned/pulled to sub-projects dir

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SUB_PROJECTS=${SUB_PROJECTS:-sub-projects}

# include functions
source $THIS_DIR/functions.sh

function update_one_repo() {
    repo_uri=$1
    branch=$2

    # remove possible schema
    repo_uri=${repo_uri#*//}
    # get the domain 
    domain=$(echo $repo_uri | cut -d "/" -f1)
    # get repo path
    repo=$(echo $repo_uri | cut -d "/" -f2-)
    # get the basename of the repo
    checkout_dir=$(basename $repo_uri)
    # remove possible file ext
    checkout_dir=${checkout_dir%.*}
    # if any is empty, skip
    [[ -z "$domain" ]] || [[ -z "$repo" ]] || [[ -z "$checkout_dir" ]]  && continue

    checkout_dir=${SUB_PROJECTS}/${checkout_dir%.*}
    if [ ! -e $checkout_dir ]
    then
        echo Clone git@$domain:$repo to $checkout_dir ...
        git clone -q git@$domain:$repo $checkout_dir
        if [ ! -z $branch ]
        then 
            echo Checkout branch $branch
            git -C $checkout_dir fetch -q
            git -C $checkout_dir checkout -q $branch
        fi
    else
        echo Updating $checkout_dir ...
        git -C $checkout_dir fetch -q
        git -C $checkout_dir pull
    fi
}

function update_repos() {
    repos_file=$1
    grep -v '^#' $repos_file | grep -v -e '^$' |
    while read -r line; do
        update_one_repo $line
    done
}

try update_repos $*
 No newline at end of file