diff --git a/.gitignore b/.gitignore new file mode 100755 index 000000000..c35cb8584 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin +*.DS_Store +.idea diff --git a/Makefile b/Makefile new file mode 100755 index 000000000..937110810 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +pull-scripts: + ./scripts/pull-scripts + +TARGETS := prepare patch charts clean validate template + +$(TARGETS): + @./scripts/pull-scripts + @./bin/charts-build-scripts $@ + +.PHONY: $(TARGETS) \ No newline at end of file diff --git a/README.md b/README.md index 985c34679..e7a3791d7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,89 @@ -# Asset Branch +## Live Branch -This branch is auto-generated from main-source branch, please open PRs to main-source. \ No newline at end of file +This branch contains generated assets that have been officially released on partner-charts.rancher.io. + +The following directory structure is expected: +```text +assets/ + / + -.tgz + ... +charts/ + + + + # Unarchived Helm chart +``` + +### Configuration + +This repository branch contains a `configuration.yaml` file that is used to specify how it interacts with other repository branches. + +### Cutting a Release + +In the Live branch, cutting a release requires you to copy the contents of the Staging branch into your Live Branch, which can be done with the following simple Bash script. + +```bash +# Assuming that your upstream remote (e.g. https://github.com/rancher/charts.git) is named `upstream` +# Replace the following environment variables +STAGING_BRANCH=dev-v2.x +LIVE_BRANCH=release-v2.x +FORKED_BRANCH=release-v2.x.y +git fetch upstream +git checkout upstream/${LIVE_BRANCH} -b ${FORKED_BRANCH} +git branch -u origin/${FORKED_BRANCH} +git checkout upstream/${STAGING_BRANCH} -- charts assets index.yaml +git add charts assets index.yaml +git commit -m "Releasing chart" +git push --set-upstream origin ${FORKED_BRANCH} +# Create your pull request! +``` + +Once complete, you should see the following: +- The `assets/` and `charts/` directories have been updated to match the Staging branch. All entires should be additions, not modifications. +- The `index.yaml`'s diff shows only adds additional entries and does not modify or remove existing ones. + +No other changes are expected. + +### Cutting an Out-Of-Band Chart Release + +Similar to the above steps, cutting an out-of-band chart release will involve porting over the new chart from the Staging branch via `git checkout`. However, you will need to manually regenerate the Helm index since you only want the index.yaml on the Live branch to be updated to include the single new chart. + +Use the following example Bash script to execute this change: + +```bash +# Assuming that your upstream remote (e.g. https://github.com/rancher/charts.git) is named `upstream` +# Replace the following environment variables +STAGING_BRANCH=dev-v2.x +LIVE_BRANCH=release-v2.x +FORKED_BRANCH=release-v2.x.y +NEW_CHART_DIR=charts/rancher-monitoring/rancher-monitoring/X.Y.Z +NEW_ASSET_TGZ=assets/rancher-monitoring/rancher-monitoring-X.Y.Z.tgz +git fetch upstream +git checkout upstream/${LIVE_BRANCH} -b ${FORKED_BRANCH} +git branch -u origin/${FORKED_BRANCH} +git checkout upstream/${STAGING_BRANCH} -- ${NEW_CHART_DIR} ${NEW_ASSET_TGZ} +helm repo index --merge ./index.yaml --url assets assets; # FYI: This will generate new 'created' timestamps across *all charts*. +mv assets/index.yaml index.yaml +git add ${NEW_CHART_DIR} ${NEW_ASSET_TGZ} index.yaml +git commit -m "Releasing out-of-band chart" +git push --set-upstream origin ${FORKED_BRANCH} +# Create your pull request! +``` + +Once complete, you should see the following: +- The new chart should exist in `assets` and `charts`. Existing charts should not be modified. +- The `index.yaml`'s diff should show an additional entry for your new chart. +- The `index.yaml`'s diff should show modified `created` timestamps across all charts (due to the behavior of `helm repo index`). + +No other changes are expected. + +### Makefile + +#### Basic Commands + +`make pull-scripts`: Pulls in the version of the `charts-build-scripts` indicated in scripts. + +`make validate`: Validates your current repository branch against all the repository branches indicated in your configuration.yaml + +`make template`: Updates the current directory by applying the configuration.yaml on [upstream Go templates](https://github.com/rancher/charts-build-scripts/tree/master/templates/template) to pull in the most up-to-date docs, scripts, etc. from [rancher/charts-build-scripts](https://github.com/rancher/charts-build-scripts) diff --git a/_config.yml b/_config.yml index 3672b43c6..1888c5ad7 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -exclude: [charts] \ No newline at end of file +exclude: [charts] diff --git a/assets/README.md b/assets/README.md new file mode 100755 index 000000000..e334301bf --- /dev/null +++ b/assets/README.md @@ -0,0 +1,3 @@ +## Assets + +This folder contains Helm chart archives that are served from partner-charts.rancher.io. diff --git a/charts/README.md b/charts/README.md new file mode 100755 index 000000000..147434df5 --- /dev/null +++ b/charts/README.md @@ -0,0 +1,3 @@ +## Charts + +This folder contains unarchived Helm charts that are served from partner-charts.rancher.io. diff --git a/configuration.yaml b/configuration.yaml new file mode 100644 index 000000000..a8ce41bd1 --- /dev/null +++ b/configuration.yaml @@ -0,0 +1,3 @@ +template: live +helmRepo: + cname: partner-charts.rancher.io diff --git a/scripts/pull-scripts b/scripts/pull-scripts new file mode 100755 index 000000000..c70b7c500 --- /dev/null +++ b/scripts/pull-scripts @@ -0,0 +1,46 @@ +#!/bin/bash +set -e + +cd $(dirname $0) + +source ./version + +if ls ../bin/charts-build-scripts 1>/dev/null 2>/dev/null; then + CURRENT_SCRIPT_VERSION=$(../bin/charts-build-scripts --version | cut -d' ' -f3) + if [[ "${CURRENT_SCRIPT_VERSION}" == "${CHARTS_BUILD_SCRIPT_VERSION}" ]]; then + exit 0 + fi +fi + +echo "Pulling in charts-build-scripts version ${CHARTS_BUILD_SCRIPTS_REPO}@${CHARTS_BUILD_SCRIPT_VERSION}" + +rm -rf ../bin +cd .. + +mkdir -p bin +ARCH=$(go version | cut -d' ' -f4 | cut -d'/' -f1) +if [[ ${ARCH} == "linux" ]]; then + BINARY_NAME=charts-build-scripts +else + BINARY_NAME=charts-build-scripts-${ARCH} +fi +curl -s -L ${CHARTS_BUILD_SCRIPTS_REPO%.git}/releases/download/${CHARTS_BUILD_SCRIPT_VERSION}/${BINARY_NAME} --output bin/charts-build-scripts +if ! [[ -f bin/charts-build-scripts ]] || [[ $(cat bin/charts-build-scripts) == "Not Found" ]]; then + rm bin/charts-build-scripts; + + # Fall back to old process + echo "Building binary locally..." + rm -rf charts-build-scripts + git clone --depth 1 --branch $CHARTS_BUILD_SCRIPT_VERSION $CHARTS_BUILD_SCRIPTS_REPO 2>/dev/null + + cd charts-build-scripts + ./scripts/build + mv bin .. + cd .. + rm -rf charts-build-scripts +else + echo "${BINARY_NAME} => ./bin/charts-build-scripts" +fi + +chmod +x ./bin/charts-build-scripts +./bin/charts-build-scripts --version diff --git a/scripts/regenerate-assets b/scripts/regenerate-assets new file mode 100755 index 000000000..153eac9b3 --- /dev/null +++ b/scripts/regenerate-assets @@ -0,0 +1,74 @@ +#!/bin/bash +set -e + +# Note: These scripts are only intended to migrate from the original build scripts to charts-build-scripts v0.1.x +# A separate migration process is required for v0.2.x + +cd $(dirname $0) + +if [[ -z ${BRANCH} ]]; then + branch=$(git rev-parse --abbrev-ref HEAD) +else + echo "Using branch ${BRANCH}" + branch=${BRANCH} +fi + +if [[ -z ${REPOSITORY} ]]; then + echo "Need to provide REPOSITORY as environment variable" + exit 1 +fi + +cd .. + +# Setup +rm -rf ./repository +mkdir -p ./repository +cd repository + +# Pull in branch +echo "Pulling in ${REPOSITORY}@${branch}" +git clone --depth 1 --branch ${branch} ${REPOSITORY} . > /dev/null 2>&1 + +if ! (test -d assets && test -d charts); then + echo "There are no charts or assets in this repository" + cd .. + rm -rf ./repository + exit 1 +fi + +# Copy assets and charts into the new format +for package_assets in assets/*; do + cp -R ${package_assets} ../assets + package_name=$(basename -- ${package_assets}) + for asset in ${package_assets}/*; do + if [[ ${asset} =~ .*\.tgz ]]; then + # Parse structure + asset_name=$(basename -- ${asset%.*}) + chart_name=$(echo ${asset_name} | rev | cut -d- -f2- | rev) + chart_name=$(echo ${chart_name} | sed -r 's/-[[:digit:]\.]+$//') + chart_version=${asset_name#${chart_name}-} + + # Fix chart version for rc version + # e.g. 0.0.0-rc100 -> 0.0.000-rc1 to keep the drop release candidate version logic simple + if [[ ${chart_version} =~ [0-9]{2}$ ]] && [[ ${chart_version} =~ -rc ]]; then + actual_version=${chart_version%-*} + package_version=${chart_version: -2} + chart_version_without_package_version=${chart_version%${package_version}} + rc_version=${chart_version_without_package_version#${actual_version}} + chart_version=${actual_version}${package_version}${rc_version} + fi + + # Dump archives as charts + chart_path=../charts/${package_name}/${chart_name}/${chart_version} + echo "Unarchiving ${asset} to ${chart_path}" + mkdir -p ${chart_path} + tar xvzf ${asset} -C ${chart_path} --strip-components=1 > /dev/null 2>&1 + fi + done +done + +# Go back +cd .. +helm repo index --merge ./assets/index.yaml --url assets assets +mv ./assets/index.yaml ./index.yaml +rm -rf ./repository \ No newline at end of file diff --git a/scripts/version b/scripts/version new file mode 100755 index 000000000..44c2e0b41 --- /dev/null +++ b/scripts/version @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +CHARTS_BUILD_SCRIPTS_REPO=https://github.com/rancher/charts-build-scripts.git +CHARTS_BUILD_SCRIPT_VERSION=v0.2.1