Autogenerate template for scripts v0.2.1

```bash
# Pull in the latest scripts
curl -s https://raw.githubusercontent.com/rancher/charts-build-scripts/master/init.sh > /dev/null | BRANCH_ROLE=live sh
# Change the helm repo name back to partner-charts.rancher.io
yq eval -i '.helmRepo.cname = "partner-charts.rancher.io"' configuration.yaml
# Use the latest version of the scripts
sed -i'.bak' "s/CHARTS_BUILD_SCRIPT_VERSION=.*/CHARTS_BUILD_SCRIPT_VERSION=v0.2.1/" scripts/version; rm scripts/version.bak
# Pull in the latest docs
make template
```
pull/94/head
Arvind Iyengar 2021-06-23 17:37:58 -07:00
parent 3447a819be
commit 41119b5189
No known key found for this signature in database
GPG Key ID: A8DD9BFD6C811498
10 changed files with 236 additions and 3 deletions

3
.gitignore vendored Executable file
View File

@ -0,0 +1,3 @@
bin
*.DS_Store
.idea

10
Makefile Executable file
View File

@ -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)

View File

@ -1,3 +1,89 @@
# Asset Branch ## Live Branch
This branch is auto-generated from main-source branch, please open PRs to main-source. This branch contains generated assets that have been officially released on partner-charts.rancher.io.
The following directory structure is expected:
```text
assets/
<package>/
<chart>-<packageVersion>.tgz
...
charts/
<package>
<chart>
<packageVersion>
# 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)

View File

@ -1 +1 @@
exclude: [charts] exclude: [charts]

3
assets/README.md Executable file
View File

@ -0,0 +1,3 @@
## Assets
This folder contains Helm chart archives that are served from partner-charts.rancher.io.

3
charts/README.md Executable file
View File

@ -0,0 +1,3 @@
## Charts
This folder contains unarchived Helm charts that are served from partner-charts.rancher.io.

3
configuration.yaml Normal file
View File

@ -0,0 +1,3 @@
template: live
helmRepo:
cname: partner-charts.rancher.io

46
scripts/pull-scripts Executable file
View File

@ -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

74
scripts/regenerate-assets Executable file
View File

@ -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

5
scripts/version Executable file
View File

@ -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