Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/scripts #3

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
# Others
starter/
.github/
scripts/
gcloud_auth_key.json
create.sh
README.md
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ $ helm dep build

### Using Starter

The best way to get started is to use the [`create` script](create.sh) to generate a new chart.
The best way to get started is to use the [`create-chart` script](scripts/create-chart.sh) to generate a new chart.

You can fetch that script, and then execute it locally:

```shell
$ curl -fsSL -o create.sh https://raw.githubusercontent.com/hahow/common-chart/master/create.sh
$ chmod 700 create.sh
$ ./create.sh mychart
$ curl -fsSL -o create.sh https://raw.githubusercontent.com/hahow/common-chart/master/scripts/create-chart.sh
$ chmod 700 create-chart.sh
$ ./create-chart.sh mychart
```

or simply

```shell
$ curl https://raw.githubusercontent.com/hahow/common-chart/master/create.sh | bash -s -- mychart
$ curl https://raw.githubusercontent.com/hahow/common-chart/master/scripts/create-chart.sh | bash -s -- mychart
```

Now, there is a chart in `./mychart`. You can edit it and create your own templates.
Expand Down
16 changes: 0 additions & 16 deletions create.sh

This file was deleted.

53 changes: 53 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

想問 scripts/bump-version.sh 會是誰在用?更改 chart 的人?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yap,之後看能不能透過 CD 自動升(但要配合一套完整的 git branching 流程


set -eu

printusage() {
echo "Usage: bump-version.sh [patch|minor|major]"
}

ROOT_PATH=$(dirname "$0")/..

if [[ $# -eq 0 ]]
then
printusage
exit 1
fi

UPDATED_PART=$1
if [[ ! ($UPDATED_PART == "patch" || $UPDATED_PART == "minor" || $UPDATED_PART == "major") ]]
then
printusage
exit 1
fi

CURRENT_VERSION=$(sed -ne 's/^version: \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$/\1/p' $ROOT_PATH/Chart.yaml)
MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 1)
MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 2)
PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 3)

if [[ $UPDATED_PART = 'patch' ]]
then
(( PATCH_VERSION++ ))
elif [[ $UPDATED_PART = 'minor' ]]
then
(( MINOR_VERSION++ ))
PATCH_VERSION=0
elif [[ $UPDATED_PART = 'major' ]]
then
(( MAJOR_VERSION ++ ))
MINOR_VERSION=0
PATCH_VERSION=0
fi

NEW_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION
echo "Bumping Version $CURRENT_VERSION => $NEW_VERSION..."

echo "Updating starter/Chart.yaml..."
sed -i "" "s/^ version: \"$CURRENT_VERSION\"$/ version: \"$NEW_VERSION\"/" $ROOT_PATH/starter/Chart.yaml

echo "Updating README.md..."
sed -i "" "/^### Adding Dependency$/,/^### Using Starter$/s;version: $CURRENT_VERSION;version: $NEW_VERSION;" $ROOT_PATH/README.md

echo "Updating Chart.yaml..."
sed -i "" "s/^version: $CURRENT_VERSION$/version: $NEW_VERSION/" $ROOT_PATH/Chart.yaml
20 changes: 20 additions & 0 deletions scripts/create-chart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -eu

if [[ $# -eq 0 ]]
then
echo "Usage: create-chart.sh <chartname>"
exit 1
fi

CHART_NAME=$1

echo "Creating chart..."
mkdir "$CHART_NAME"
curl --proto '=https' --tlsv1.2 -sSf https://codeload.github.com/hahow/common-chart/tar.gz/master | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codeload.github.com 是最後 redirect 到的網址沒錯吧?我不確定他不是不是 public facing 的網址,以後可能會被改掉?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確實有可能以後會改,但目前看來這個網址是滿普遍的用法,等被改掉再換?

tar -xz -C "$CHART_NAME" --strip=2 common-chart-master/starter
find "$CHART_NAME" -type f | xargs sed -i "" "s/<CHARTNAME>/$CHART_NAME/g"

echo "Building dependencies..."
helm dep build "$CHART_NAME"