Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Dev builds create pre-release helm charts/images #85

Merged
merged 5 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 18 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
global:
- GOPROXY="https://proxy.golang.org"
- COVERAGE=true
# for Helm
- DESIRED_VERSION="v3.1.0"
jobs:
- KUBE=1.14.10
- KUBE=1.15.7
Expand All @@ -26,21 +28,17 @@ stages:
- unit
- test

# Avoid too many builds, works for PRs too, as this is also their base branch.
# Otherwise opening a PR from a branch would trigger two builds.
branches:
only:
- master

install:
# Download go dev dependencies
- export PATH=$PATH:$GOPATH/bin
- go install github.com/onsi/ginkgo/ginkgo
- go get github.com/mattn/goveralls
- go get github.com/modocache/gover

# Avoid too many builds.
# Otherwise opening a PR from a local branch would trigger two builds.
if: tag IS blank AND (type = push OR (type = pull_request AND head_repo != repo))

# The matrix build for all Kubernetes versions
before_script:
# Download and install kubectl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Expand All @@ -50,11 +48,11 @@ before_script:
- kind create cluster --image kindest/node:v$KUBE --name kind$KUBE --wait 240s
- kubectl version
# Download and install helm
- export DESIRED_VERSION="v3.1.0"
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
- chmod 700 get_helm.sh
- sudo ./get_helm.sh
# yes, heredocs are broken in before_script: https://travis-ci.community/t/multiline-commands-have-two-spaces-in-front-breaks-heredocs/2756

# The matrix build for all Kubernetes versions
script:
- USE_KIND="true" make test-cluster
- make coverage
Expand All @@ -78,31 +76,21 @@ jobs:
env: KUBE=none

- stage: Publishing
# security: only on master, or if PR repo is our repo
if: branch = master OR (type = pull_request AND head_repo = repo)
# security: only push
if: type = push
# do not inherit
install: []
before_script: []
before_script:
# Download and install helm
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
- chmod 700 get_helm.sh
- sudo ./get_helm.sh
script: echo "Publishing"
before_deploy:
- git fetch --unshallow
- . bin/include/versioning
deploy:
- provider: script
script:
- bin/build-image
- bin/publish-image

- provider: script
script:
- ./bin/build-helm
- |
git clone https://CFContainerizationBot:$GITHUB_TOKEN@github.com/cloudfoundry-incubator/quarks-helm.git ./updated/ &&
cp -a helm/quarks-job*.tgz updated/ &&
./bin/publish-helm-repo

- provider: script
if: branch = master AND type = push
script:
- git tag -a $ARTIFACT_VERSION -m "tag $ARTIFACT_VERSION"
- git push --quiet https://CFContainerizationBot:$GITHUB_TOKEN@github.com/cloudfoundry-incubator/quarks-job.git $ARTIFACT_VERSION > /dev/null 2>&1
on:
all_branches: true
repo: cloudfoundry-incubator/quarks-job
script: bin/deploy
5 changes: 2 additions & 3 deletions bin/build-helm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ GIT_ROOT=${GIT_ROOT:-$(git rev-parse --show-toplevel)}

output_dir=${GIT_ROOT}/helm

# https://semver.org/#semantic-versioning-200
# helm does not accept ^v and considers any version with dash to be a
# pre-release
version=$(echo "$ARTIFACT_VERSION" | sed 's/^v//; s/-/+/')
# pre-release, which is intended for dev builds
version=$(echo "$ARTIFACT_VERSION" | sed 's/^v//')

[ -d "${output_dir}" ] && rm -r "${output_dir}"
cp -r "${GIT_ROOT}/deploy/helm" "${output_dir}"
Expand Down
39 changes: 39 additions & 0 deletions bin/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -euo pipefail

GIT_ROOT=${GIT_ROOT:-$(git rev-parse --show-toplevel)}
. "${GIT_ROOT}/bin/include/versioning"

if [ -z ${ARTIFACT_VERSION+x} ]; then
echo "missing ARTIFACT_VERSION"
exit 1
fi

if [ -z ${GITHUB_TOKEN+x} ]; then
echo "missing GITHUB_TOKEN"
exit 1
fi

if [ -z ${DOCKER_PASSWORD+x} ]; then
echo "missing DOCKER_PASSWORD"
exit 1
fi

echo "Publish Docker Image for $ARTIFACT_VERSION"
"$GIT_ROOT"/bin/build-image
"$GIT_ROOT"/bin/publish-image

echo "Publish Helm Chart for $ARTIFACT_VERSION"
"$GIT_ROOT"/bin/build-helm

base_url="https://CFContainerizationBot:$GITHUB_TOKEN@github.com/cloudfoundry-incubator"
git clone "$base_url/quarks-helm.git" ./updated/ && \
cp -a helm/quarks-job*.tgz updated/ && \
"$GIT_ROOT"/bin/publish-helm-repo

if [ "$TRAVIS_BRANCH" = "master" ]; then
echo "Tag Github Commit with $ARTIFACT_VERSION"
git tag -a "$ARTIFACT_VERSION" -m "tag $ARTIFACT_VERSION"
git push --quiet "$base_url/quarks-job.git" "$ARTIFACT_VERSION" > /dev/null 2>&1
fi
17 changes: 11 additions & 6 deletions bin/include/versioning
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/bin/bash

TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST-}
TRAVIS_BRANCH=${TRAVIS_BRANCH-}
TRAVIS_COMMIT=${TRAVIS_COMMIT-}
COMMIT_NUMBER=$(git rev-list --first-parent --count HEAD)

if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
# https://semver.org/#semantic-versioning-200

if [ "$TRAVIS_BRANCH" = "master" ]; then
# travis is building on master
# unlike quarks-operator do not set a build identifier
ARTIFACT_VERSION="v1.0.$COMMIT_NUMBER"

elif [ -n "${TRAVIS_PULL_REQUEST:-}" ]; then
# this is running on a travis PR
ARTIFACT_VERSION="v0.0.$TRAVIS_PULL_REQUEST-g$TRAVIS_COMMIT"
elif [ -n "${TRAVIS_BRANCH:-}" ]; then
# this is running on a travis push
# return pre-release version
sha=$(git rev-parse --short "$TRAVIS_COMMIT")
ARTIFACT_VERSION="v0.0.$COMMIT_NUMBER-g$sha"

else
# this is not running in travis
# return pre-release version
COMMIT=$(git describe --tags --long | awk -F - '{ print $NF }')
ARTIFACT_VERSION="v0.0.$COMMIT_NUMBER-$COMMIT"
manno marked this conversation as resolved.
Show resolved Hide resolved
fi
Expand Down