Skip to content

Commit

Permalink
Cherry Picking commits (#71)
Browse files Browse the repository at this point in the history
* Removing status subresource from the chaosengine CRD (#64)

Signed-off-by: shubhamchaudhary <[email protected]>

* (chore)ci: update circleci to push tagged images (#69)

Signed-off-by: ksatchit <[email protected]>

* (chore)ci: ensure circle ci builds for tags (#70)

Signed-off-by: ksatchit <[email protected]>
  • Loading branch information
imrajdas authored and Karthik Satchitanand committed Oct 15, 2019
1 parent 654d76a commit d21d03a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 43 deletions.
102 changes: 84 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
version: 2.1

jobs:

build:
machine:
image: circleci/classic:201808-01
docker_layer_caching: true
machine:
image: circleci/classic:201808-01
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
environment:
K8S_VERSION: v1.12.0
KUBECONFIG: /home/circleci/.kube/config
MINIKUBE_VERSION: v1.3.1
HOME: /home/circleci
CHANGE_MINIKUBE_NONE_USER: true

working_directory: ~/go/src/github.com/litmuschaos/chaos-operator

REPONAME: litmuschaos
IMGNAME: chaos-operator
IMGTAG: latest
steps:
- checkout
- run:
Expand All @@ -31,22 +33,86 @@ jobs:
name: Start minikube
command: |
sudo -E minikube start --vm-driver=none --cpus 2 --memory 4096 --kubernetes-version=${K8S_VERSION}
- run: mkdir -p workspace
- run:
name: Setup ENV
command: |
echo 'export GOPATH="$HOME/go"' >> $BASH_ENV
echo 'export PATH="$GOPATH/bin:$PATH"' >> $BASH_ENV
echo 'export REPONAME=litmuschaos' >> $BASH_ENV
echo 'export IMGNAME=chaos-operator' >> $BASH_ENV
echo 'export IMGTAG=latest' >> $BASH_ENV
echo 'export IMGSHATAG="$(echo $CIRCLE_SHA1 | cut -c -6)"'>> $BASH_ENV
echo 'export GOPATH="$HOME/go"' >> workspace/env-vars
echo 'export PATH="$GOPATH/bin:$PATH"' >> workspace/env-vars
echo 'export REPONAME="litmuschaos"' >> workspace/env-vars
echo 'export IMGNAME="chaos-operator"' >> workspace/env-vars
echo 'export IMGTAG="latest"' >> workspace/env-vars
cat workspace/env-vars >> $BASH_ENV
source $BASH_ENV
- run: sed '/chaos-operator:latest/s/latest/'${IMGSHATAG}'/' -i ./deploy/operator.yaml
- run: make deps
- run: make gotasks
- run: |
docker build . -f build/Dockerfile -t "${REPONAME}"/"${IMGNAME}":"${IMGSHATAG}"
docker tag "${REPONAME}"/"${IMGNAME}":"${IMGSHATAG}" "${REPONAME}"/"${IMGNAME}":"${IMGTAG}"
- run: make test
docker build . -f build/Dockerfile -t ${REPONAME}/${IMGNAME}:${IMGTAG}
- run: make test
- run: |
docker save -o workspace/image.tar ${REPONAME}/${IMGNAME}:${IMGTAG}
- persist_to_workspace:
root: workspace
paths:
- image.tar
- env-vars

push:
machine:
image: circleci/classic:201808-01
environment:
IMGTAG: latest
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
steps:
- attach_workspace:
at: /tmp/workspace
- run: |
cat /tmp/workspace/env-vars >> $BASH_ENV
- checkout
- run: |
docker load -i /tmp/workspace/image.tar
~/go/src/github.com/litmuschaos/chaos-operator/buildscripts/push --type=ci
release:
machine:
image: circleci/classic:201808-01
environment:
IMGTAG: latest
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
steps:
- attach_workspace:
at: /tmp/workspace
- run: |
${GOPATH}/src/github.com/litmuschaos/chaos-operator/buildscripts/push
cat /tmp/workspace/env-vars >> $BASH_ENV
- checkout
- run: |
docker load -i /tmp/workspace/image.tar
~/go/src/github.com/litmuschaos/chaos-operator/buildscripts/push --type=release
workflows:
version: 2
operator_build_deploy:
jobs:
- build:
filters:
## build jobs needs to be run for branch commits as well as tagged releases
tags:
only: /.*/
- push:
requires:
- build
filters:
## push jobs needs to be run for branch commits as well as tagged releases
## docker images push won't be performed for PRs due to ENV not being applied
tags:
only: /.*/
- release:
requires:
- build
filters:
## release jobs needs to be run for tagged releases alone & not for any branch commits
branches:
ignore: /.*/
tags:
only: /.*/

58 changes: 35 additions & 23 deletions buildscripts/push
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
#!/bin/bash
set -e

if [ -z "${REPONAME}" ]
then
REPONAME="litmuschaos"
fi
# Push CI images
function push_ci_image(){

echo "Pushing ${REPONAME}/${IMGNAME}:${IMGTAG} ..."
docker push ${REPONAME}/${IMGNAME}:${IMGTAG}

}

# Push Release Images
function push_release_image(){

if [ ! -z "${CIRCLE_TAG}" ];
then
# Push with different tags if tagged as a release
# When github is tagged with a release, then CircleCI will
# set the release tag in env CIRCLE_TAG
echo "Pushing ${REPONAME}/${IMGNAME}:${CIRCLE_TAG} ..."
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:${CIRCLE_TAG}
docker push ${REPONAME}/${IMGNAME}:${CIRCLE_TAG}
fi;

}

if [ -z "${IMGNAME}" ] || [ -z "${IMGTAG}" ] || [ -z "${IMGSHATAG}" ]

# Check for Image Details
if [ -z "${REPONAME}" ] || [ -z "${IMGNAME}" ] || [ -z "${IMGTAG}" ]
then
echo "Image details are missing. Nothing to push.";
exit 1
fi

IMAGEID=$( docker images -q ${REPONAME}/${IMGNAME}:${IMGTAG} )
IMAGESHAID=$( docker images -q ${REPONAME}/${IMGNAME}:${IMGSHATAG} )

# Verify Docker Credentials
if [ ! -z "${DNAME}" ] && [ ! -z "${DPASS}" ];
then
docker login -u "${DNAME}" -p "${DPASS}";
# Push image to docker hub
echo "Pushing ${REPONAME}/${IMGNAME}:${IMGTAG} ...";
docker push ${REPONAME}/${IMGNAME}:${IMGTAG} ;
docker push ${REPONAME}/${IMGNAME}:${IMGSHATAG} ;
if [ ! -z "${TRAVIS_TAG}" ] ;
then
# Push with different tags if tagged as a release
# When github is tagged with a release, then Travis will
# set the release tag in env TRAVIS_TAG
echo "Pushing ${REPONAME}/${IMGNAME}:${TRAVIS_TAG} ...";
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:${TRAVIS_TAG}
docker push ${REPONAME}/${IMGNAME}:${TRAVIS_TAG};
echo "Pushing ${REPONAME}/${IMGNAME}:latest ...";
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:latest
docker push ${REPONAME}/${IMGNAME}:latest;
fi;
build_type=$(echo $1 | cut -d "=" -f 2)
if [ "${build_type}" == "ci" ]; then
push_ci_image;
elif [ "${build_type}" == "release" ]; then
push_release_image;
else
echo "Invalid build type"; exit 1
fi
else
echo "No docker credentials provided. Skip uploading ${REPONAME}/${IMGNAME}:${IMGTAG} to docker hub";
fi;
fi
1 change: 0 additions & 1 deletion deploy/chaos_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ spec:
singular: chaosengine
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
Expand Down
1 change: 0 additions & 1 deletion deploy/crds/chaosengine_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ spec:
singular: chaosengine
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
Expand Down

0 comments on commit d21d03a

Please sign in to comment.