-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promote Helm Charts and Docker Images Across Repositories (#85)
## Breaking Changes * `REPO_GATEWAY_ENDPOINT` renamed to `TARGET_CHART_REPO_ENDPOINT` (related to `helm/build/*` targets) * `LATEST_TAG` __depricated__ in`semver` module. Now it always `0.0.0` ## Change log * Reinvent helm build and promote tasks * Added Codefresh pipeline logic
- Loading branch information
Showing
13 changed files
with
238 additions
and
111 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,4 +1,3 @@ | ||
sudo: required | ||
language: go | ||
go: | ||
- 1.9.x | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
## To get GIT_* env variables reference https://github.com/cloudposse/build-harness/blob/master/modules/git/bootstrap.Makefile | ||
|
||
# Extract ticket number from branch name (e.g. feature/ch37684/add-codefresh) | ||
FEATURE ?= $(shell echo "$(GIT_BRANCH)" | cut -s -d'/' -f2 | tr '[:upper:]' '[:lower:]') | ||
|
||
PIPELINE_ACTION = pass | ||
|
||
## Pre-production deploys only released versions | ||
ifeq ($(PIPELINE_ENV),pre-production) | ||
STAGE ?= pre-prod | ||
ifeq ($(GIT_IS_TAG),1) | ||
PIPELINE_ACTION = deploy | ||
endif | ||
endif | ||
|
||
## Staging deploys all commits (working branch should be set on codefresh pipeline trigger config) | ||
ifeq ($(PIPELINE_ENV),staging) | ||
STAGE ?= stage | ||
PIPELINE_ACTION = deploy | ||
endif | ||
|
||
## Integration deploys on each PR create/update. On PR close - cleanup | ||
ifeq ($(PIPELINE_ENV),integration) | ||
STAGE ?= $(FEATURE) | ||
|
||
ifeq ($(CF_PULL_REQUEST_ACTION),opened) | ||
PIPELINE_ACTION = deploy | ||
endif | ||
|
||
ifeq ($(CF_PULL_REQUEST_ACTION),synchronize) | ||
PIPELINE_ACTION = deploy | ||
endif | ||
|
||
ifeq ($(CF_PULL_REQUEST_ACTION),closed) | ||
PIPELINE_ACTION = destroy | ||
endif | ||
|
||
endif | ||
|
||
ifneq ($(PIPELINE_ENV),) | ||
NAMESPACE ?= $(PROJECT)-$(STAGE) | ||
APP_HOST ?= $(APP_NAME).$(STAGE).$(BASE_HOST) | ||
RELEASE_NAME ?= $(NAMESPACE)-$(APP_NAME) | ||
endif | ||
|
||
## Export pipeline vars | ||
codefresh/pipeline/export: | ||
$(call assert-set,PROJECT) | ||
$(call assert-set,PIPELINE_ACTION) | ||
$(call assert-set,NAMESPACE) | ||
$(call assert-set,APP_HOST) | ||
$(call assert-set,RELEASE_NAME) | ||
$(call assert-set,BASE_HOST) | ||
$(call assert-set,APP_NAME) | ||
@echo "PROJECT=$(PROJECT)" | ||
@echo "NAMESPACE=$(NAMESPACE)" | ||
@echo "PIPELINE_ACTION=$(PIPELINE_ACTION)" | ||
@echo "APP_HOST=$(APP_HOST)" | ||
@echo "RELEASE_NAME=$(RELEASE_NAME)" | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
## Build chart $CHART_NAME from $SOURCE_CHART_TPL | ||
helm/chart/build: helm/chart/build/prepare helm/chart/build/deps helm/chart/build/package | ||
@$(SELF) -s helm/chart/build/clean | ||
|
||
## Build chart $CHART_NAME from $SOURCE_CHART_TPL for all available $SEMVERSIONS | ||
helm/chart/build/all: helm/chart/build/prepare helm/chart/build/deps | ||
@for version in $(SEMVERSIONS) ; do \ | ||
echo "Build chart $(CHART_NAME) version $$version"; \ | ||
$(SELF) -s helm/chart/build/package TARGET_VERSION=$$version; \ | ||
done | ||
@$(SELF) -s helm/chart/build/clean | ||
|
||
## Alias for helm/chart/build/all. Depricated. | ||
helm/chart/build-all: helm/chart/build/all | ||
@exit 0 | ||
|
||
## Promote $SOURCE_CHART_FILE to $TARGET_VERSION | ||
helm/chart/promote/local: helm/chart/promote/local/prepare helm/chart/build/package | ||
@$(SELF) -s helm/chart/build/clean | ||
|
||
## Promote $CHART_NAME from $SOURCE_VERSION to $TARGET_VERSION. ($SOURCE_CHART_REPO_ENDPOINT required) | ||
helm/chart/promote/remote: helm/chart/promote/remote/prepare helm/chart/build/package | ||
@$(SELF) -s helm/chart/build/clean | ||
|
||
## Alias for helm/chart/publish/all. WARNING: Eventually will became functional equal to helm/chart/publish/one | ||
helm/chart/publish: helm/chart/publish/all | ||
|
||
## Publish chart $CHART_NAME to $TARGET_CHART_REPO_ENDPOINT | ||
helm/chart/publish/all: | ||
$(call assert-set,CHART_NAME) | ||
$(call assert-set,TARGET_CHART_REPO_ENDPOINT) | ||
@for package in $(shell find ${HELM_PACKAGE_PATH} -maxdepth 1 -mindepth 1 -type f -name '${CHART_NAME}*.tgz') ; do \ | ||
$(SELF) -s helm/chart/publish/package SOURCE_CHART_FILE=$$package; \ | ||
done | ||
|
||
## Publish chart $SOURCE_CHART_FILE to $REPO_GATEWAY_ENDPOINT | ||
helm/chart/publish/package: | ||
$(call assert-set,SOURCE_CHART_FILE) | ||
$(call assert-set,TARGET_CHART_REPO_ENDPOINT) | ||
echo "Publish package $(SOURCE_CHART_FILE)" | ||
curl --insecure --data-binary "@$(SOURCE_CHART_FILE)" $(TARGET_CHART_REPO_ENDPOINT)/api/charts | ||
|
||
## Clean chart packages | ||
helm/chart/clean: | ||
@rm -rf $(HELM_PACKAGE_PATH) | ||
@echo "Remove packages from $(HELM_PACKAGE_PATH)" | ||
|
||
#### Helpers -------------------------------------------------------------------------------------------- | ||
|
||
# Copy $SOURCE_CHART_TPL directory to $HELM_PACKAGE_PATH and rename it $CHART_NAME | ||
helm/chart/build/prepare: helm/chart/build/clean | ||
$(call assert-set,CHART_NAME) | ||
$(call assert-set,SOURCE_CHART_TPL) | ||
$(call assert-set,HELM_PACKAGE_PATH) | ||
@echo "Create $(HELM_PACKAGE_PATH)$(CHART_NAME) from $(SOURCE_CHART_TPL)" | ||
@mkdir -p $(HELM_PACKAGE_PATH) | ||
@cp -R $(SOURCE_CHART_TPL) $(HELM_PACKAGE_PATH)$(CHART_NAME) | ||
|
||
|
||
# Clean temporary chart $CHART_NAME directory in $HELM_PACKAGE_PATH | ||
helm/chart/build/clean: | ||
$(call assert-set,CHART_NAME) | ||
$(call assert-set,HELM_PACKAGE_PATH) | ||
@echo "Cleaning up $(HELM_PACKAGE_PATH)$(CHART_NAME)" | ||
@rm -rf $(HELM_PACKAGE_PATH)$(CHART_NAME) | ||
|
||
# Get dependencies for chart named CHART_NAME that stored in HELM_PACKAGE_PATH | ||
helm/chart/build/deps: | ||
$(call assert-set,CHART_NAME) | ||
$(call assert-set,HELM_PACKAGE_PATH) | ||
@echo "Fetch dependencies for $(HELM_PACKAGE_PATH)$(CHART_NAME)" | ||
@$(HELM) dependency build --debug $(HELM_PACKAGE_PATH)$(CHART_NAME) | ||
|
||
# Create a helm package called CHART_NAME and store it in HELM_PACKAGE_PATH | ||
helm/chart/build/package: | ||
$(call assert-set,CHART_NAME) | ||
$(call assert-set,TARGET_VERSION) | ||
$(call assert-set,HELM_PACKAGE_PATH) | ||
@echo "For back compatibility pinning image.tag to $(TARGET_VERSION)" | ||
@set -o pipefail; yq write --inplace $(HELM_PACKAGE_PATH)$(CHART_NAME)/values.yaml image.tag $(TARGET_VERSION) | head -1 | ||
@echo "Pack $(CHART_NAME) with version $(TARGET_VERSION)" | ||
@$(HELM) package \ | ||
--version $(TARGET_VERSION) \ | ||
--app-version $(TARGET_VERSION) \ | ||
--save=false \ | ||
--debug \ | ||
--destination $(HELM_PACKAGE_PATH) \ | ||
$(HELM_PACKAGE_PATH)$(CHART_NAME) | ||
|
||
# Unpack $SOURCE_CHART_FILE tarball to $HELM_PACKAGE_PATH | ||
helm/chart/promote/local/prepare: helm/chart/build/clean | ||
$(call assert-set,SOURCE_CHART_FILE) | ||
$(call assert-set,HELM_PACKAGE_PATH) | ||
@echo "Create chart from $(SOURCE_CHART_FILE)" | ||
@mkdir -p $(HELM_PACKAGE_PATH) | ||
@tar -zxvf $(SOURCE_CHART_FILE) -C $(HELM_PACKAGE_PATH) | ||
|
||
# Unpack $SOURCE_CHART_REPO_ENDPOINT/$CHART_NAME-$SOURCE_VERSION tarball to $HELM_PACKAGE_PATH | ||
helm/chart/promote/remote/prepare: helm/chart/build/clean | ||
$(call assert-set,CHART_NAME) | ||
$(call assert-set,SOURCE_VERSION) | ||
$(call assert-set,HELM_PACKAGE_PATH) | ||
$(call assert-set,SOURCE_CHART_REPO_ENDPOINT) | ||
@echo "Create $(HELM_PACKAGE_PATH)$(CHART_NAME) from {SOURCE_CHART_REPO_ENDPOINT}/$(CHART_NAME)-$(SOURCE_VERSION)" | ||
@mkdir -p $(HELM_PACKAGE_PATH) | ||
@$(HELM) fetch --untar --untardir $(HELM_PACKAGE_PATH) \ | ||
--repo $(SOURCE_CHART_REPO_ENDPOINT)\ | ||
--version $(SOURCE_VERSION) \ | ||
$(CHART_NAME) | ||
|
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
Oops, something went wrong.