Skip to content

Commit

Permalink
Add khj script
Browse files Browse the repository at this point in the history
  • Loading branch information
adostal committed May 25, 2018
1 parent 3f6a782 commit d93e1ed
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ LABEL maintainer="Ales Dostal <a.dostal@apitree.cz>"
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY ./src /usr/src/app
# COPY ./src /usr/src/app

COPY ./src/khj.sh /usr/local/bin
RUN mv /usr/local/bin/khj.sh /usr/local/bin/khj
RUN chmod 777 /usr/local/bin/khj

ENV HELM_VERSION="v2.9.0"

Expand All @@ -16,7 +20,7 @@ ENV INCUBATOR_REPO_URL="https://kubernetes-charts-incubator.storage.googleapis.c

RUN apk add --update ca-certificates \
&& apk add --update -t deps wget \
&& apk add curl make \
&& apk add curl make bash \
&& wget -q ${HELM_URL}/${HELM_TARBALL} \
&& tar xzfv ${HELM_TARBALL} \
&& mv ./linux-amd64/helm /usr/local/bin \
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ VERSION=0.1.0-alpha.1 \
REPO_USER=xxx \
REPO_PASS=xxx \
REPO_URL=xxx \
make helm-all
khj helm-all
```

### Helm init

> Initialize as client only
```bash
make helm-init
khj helm-init
```

### Helm set version
Expand All @@ -32,19 +32,19 @@ make helm-init
```bash
DIRECTORY_CHART=helm-dir \
HELM_VERSION=0.1.0-alpha.1 \
make helm-set-version
khj helm-set-version
```

### Helm show Chart.yaml

```bash
DIRECTORY_CHART=helm-dir make helm-show-chart
DIRECTORY_CHART=helm-dir khj helm-show-chart
```

### Helm package

```bash
DIRECTORY_CHART=helm-dir make helm-package
DIRECTORY_CHART=helm-dir khj helm-package
```

### Helm deploy
Expand All @@ -57,7 +57,7 @@ VERSION=0.1.0-alpha.1 \
REPO_USER=xxx \
REPO_PASS=xxx \
REPO_URL=xxx \
make helm-deploy
khj helm-deploy
```

## Usage in CircleCI 2.0
Expand All @@ -75,7 +75,7 @@ jobs:
- checkout
- run:
name: Package and deploy
command: make helm-all
command: khj helm-all
environment:
DIRECTORY_CHART=.helm/${CIRCLE_PROJECT_REPONAME}
VERSION=${CIRCLE_TAG:1}
Expand Down
92 changes: 92 additions & 0 deletions src/khj.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh

noArg() {
echo >&2 '
***********
** ERROR **
***********
'
echo "ERROR: You must set one argument 'khj (helm-init, helm-set-version, helm-show-chart, helm-package, helm-deploy, helm-all)'" >&2
exit 1
}

checkDirectoryChart() {
if [ ! "${DIRECTORY_CHART:-}" ]; then
echo "ERROR variable \$VDIRECTORY_CHART is not set"
exit 1
fi
}

checkVersionExist() {
if [ ! "${VERSION:-}" ]; then
echo "ERROR variable \$VERSION is not set"
exit 1
fi
}

checkRepoUserExist() {
if [ ! "${REPO_USER:-}" ]; then
echo "ERROR variable \$REPO_USER is not set"
exit 1
fi
}

checkRepoPassExist() {
if [ ! "${REPO_PASS:-}" ]; then
echo "ERROR variable \$REPO_PASS is not set"
exit 1
fi
}

checkRepoUrlExist() {
if [ ! "${REPO_URL:-}" ]; then
echo "ERROR variable \$REPO_URL is not set"
exit 1
fi
}

helmInit() {
echo "Helm init"
helm init --client-only
}

helmSetVersion() {
echo "Helm set version"
checkDirectoryChart;
checkVersionExist;
sed -i -e 's/{HELM_VERSION}/${VERSION}/g' ${DIRECTORY_CHART}/Chart.yaml
}

helmShowChart() {
echo "Helm show chart"
checkDirectoryChart;
cat ${DIRECTORY_CHART}/Chart.yaml
}

helmPackage() {
echo "Helm package"
checkDirectoryChart;
helm package ${DIRECTORY_CHART}/ -d ${DIRECTORY_CHART}
}

helmDeploy() {
echo "Helm deploy"
checkDirectoryChart;
checkVersionExist;
checkRepoUserExist;
checkRepoPassExist;
checkRepoUrlExist;
TGZ_FILENAME=${DIRECTORY_CHART}-${VERSION}.tgz
curl -u ${REPO_USER}:${REPO_PASS} -T ${DIRECTORY_CHART}/${TGZ_FILENAME} "${REPO_URL}/${TGZ_FILENAME}"

}

case $1 in
"") noArg;;
"helm-init") helmInit;;
"helm-set-version") helmSetVersion;;
"helm-show-chart") helmShowChart;;
"helm-package") helmPackage;;
"helm-deploy") helmDeploy;;
"helm-all") helmInit;helmSetVersion;helmShowChart;helmPackage;helmDeploy;;
esac

0 comments on commit d93e1ed

Please sign in to comment.