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

Commit

Permalink
Switch to circleci (#539)
Browse files Browse the repository at this point in the history
* Switch to CircleCI

- based configuration off of https://github.com/kubeapps/kubeapps/blob/9a92cbf2bf0c618395389900d22567552282004f/.circleci/config.yml
- builds chartsvc and chart-repo
- template test for helm chart

Signed-off-by: Adnan Abdulhussein <[email protected]>

* update Makefiles and Dockerfiles of Go tools

Signed-off-by: Adnan Abdulhussein <[email protected]>

* fix mispelling

Signed-off-by: Adnan Abdulhussein <[email protected]>

* test ci

Signed-off-by: Adnan Abdulhussein <[email protected]>

* fix repo sync script for CircleCI

Signed-off-by: Adnan Abdulhussein <[email protected]>

* only push images on master or tagged builds

Signed-off-by: Adnan Abdulhussein <[email protected]>

* rename test_go to test_go_packages

Signed-off-by: Adnan Abdulhussein <[email protected]>
  • Loading branch information
prydonius authored Oct 5, 2018
1 parent bfdf421 commit d430401
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 59 deletions.
130 changes: 130 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
version: 2

## Build conditions
# Build in any branch or tag
build_always: &build_always
filters:
tags:
only: /^v.*/
# Build only in master or in tags
build_on_master_and_tags: &build_on_master_and_tags
filters:
tags:
only: /^v.*/
branches:
only: master

workflows:
version: 2
monocular:
jobs:
- test_go_packages:
<<: *build_always
- test_chart_render:
<<: *build_always
- build_and_push_go_images:
<<: *build_always
requires:
- test_go_packages
- test_chart_render
- build_and_push_frontend_image:
<<: *build_always
requires:
- test_go_packages
- test_chart_render
- sync_chart:
<<: *build_on_master_and_tags
requires:
- build_and_push_go_images
- build_and_push_frontend_image

## Definitions
install_helm_cli: &install_helm_cli
run: |
wget https://storage.googleapis.com/kubernetes-helm/helm-$HELM_VERSION-linux-amd64.tar.gz
tar zxf helm-$HELM_VERSION-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/
exports: &exports
run: |
# It is not possible to resolve env vars in the environment section:
# https://circleci.com/docs/2.0/env-vars/#using-bash_env-to-set-environment-variables
# DEV_TAG and PROD_TAG are the tags used for the Kubeapps docker images
echo "export IMAGE_TAG=${CIRCLE_TAG:-latest}" >> $BASH_ENV
###

jobs:
test_go_packages:
working_directory: /go/src/github.com/helm/monocular
environment:
CGO_ENABLED: "0"
docker:
- image: circleci/golang:1.9
steps:
- checkout
# Global test for all Go packages in the repo
- run: go test -v ./...

test_chart_render:
docker:
- image: circleci/golang:1.9
environment:
HELM_VERSION: v2.9.1
steps:
- checkout
- <<: *install_helm_cli
- run: helm init --client-only
- run: helm dep build ./chart/monocular
- run: helm template ./chart/monocular

build_and_push_frontend_image:
docker:
- image: circleci/node:8
environment:
IMAGE_REPO: quay.io/helmpack/monocular-ui
steps:
- setup_remote_docker
- checkout
- <<: *exports
- run: make -C frontend install
- run: make -C frontend VERSION=${IMAGE_TAG} set-version
# required due to apparent yarn issue with node-sass: https://github.com/sass/node-sass/issues/1971
- run: npm --prefix frontend rebuild node-sass
- run: make -C frontend docker-build # Tests disabled for now
- run: |
if [[ -z "${CIRCLE_PULL_REQUEST}" && -n "${DOCKER_USERNAME}" && -n "${DOCKER_PASSWORD}" ]] && [[ "${CIRCLE_BRANCH}" == "master" || -n "${CIRCLE_TAG}" ]]; then
docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" quay.io
docker push ${IMAGE_REPO}:${IMAGE_TAG}
fi
build_and_push_go_images:
docker:
- image: circleci/golang:1.9
working_directory: /go/src/github.com/helm/monocular
environment:
GOPATH: /home/circleci/.go_workspace
IMAGE_REPO_PREFIX: quay.io/helmpack/
steps:
- setup_remote_docker
- checkout
- <<: *exports
- run: |
CMDS=(chart-repo chartsvc)
for CMD in ${CMDS[@]}; do
make -C cmd/${CMD} docker-build
done
if [[ -z "${CIRCLE_PULL_REQUEST}" && -n "${DOCKER_USERNAME}" && -n "${DOCKER_PASSWORD}" ]] && [[ "${CIRCLE_BRANCH}" == "master" || -n "${CIRCLE_TAG}" ]]; then
docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" quay.io
for CMD in ${CMDS[@]}; do
docker push ${IMAGE_REPO_PREFIX}${CMD}:${IMAGE_TAG}
done
fi
sync_chart:
docker:
- image: circleci/golang:1.9
steps:
- checkout
- <<: *exports
- run: |
./scripts/repo-sync.sh
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
frontend/node_modules
.git
docs
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions cmd/chart-repo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM quay.io/deis/go-dev:v1.8.2 as builder
COPY . /go/src/github.com/kubeapps/kubeapps
WORKDIR /go/src/github.com/kubeapps/kubeapps
COPY . /go/src/github.com/helm/monocular
WORKDIR /go/src/github.com/helm/monocular
RUN CGO_ENABLED=0 go build -a -installsuffix cgo ./cmd/chart-repo

FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/github.com/kubeapps/kubeapps/chart-repo /chart-repo
COPY --from=builder /go/src/github.com/helm/monocular/chart-repo /chart-repo
CMD ["/chart-repo"]
6 changes: 6 additions & 0 deletions cmd/chart-repo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
IMAGE_REPO ?= quay.io/helmpack/chart-repo
IMAGE_TAG ?= latest

docker-build:
# We use the context of the root dir
docker build --pull --rm -t ${IMAGE_REPO}:${IMAGE_TAG} -f Dockerfile ../../
6 changes: 3 additions & 3 deletions cmd/chartsvc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM quay.io/deis/go-dev:v1.8.2 as builder
COPY . /go/src/github.com/kubeapps/kubeapps
WORKDIR /go/src/github.com/kubeapps/kubeapps
COPY . /go/src/github.com/helm/monocular
WORKDIR /go/src/github.com/helm/monocular
RUN CGO_ENABLED=0 go build -a -installsuffix cgo ./cmd/chartsvc

FROM scratch
COPY --from=builder /go/src/github.com/kubeapps/kubeapps/chartsvc /chartsvc
COPY --from=builder /go/src/github.com/helm/monocular/chartsvc /chartsvc
EXPOSE 8080
CMD ["/chartsvc"]
6 changes: 6 additions & 0 deletions cmd/chartsvc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
IMAGE_REPO ?= quay.io/helmpack/chartsvc
IMAGE_TAG ?= latest

docker-build:
# We use the context of the root dir
docker build --pull --rm -t ${IMAGE_REPO}:${IMAGE_TAG} -f Dockerfile ../../
23 changes: 12 additions & 11 deletions scripts/repo-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@

GIT_URL=github.com/helm/monocular.git
REPO_URL=https://helm.github.io/monocular
REPO_DIR=$TRAVIS_BUILD_DIR
# Need to expand `~` with $HOME
REPO_DIR="${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}"
CHART_PATH="$REPO_DIR/chart/monocular"
COMMIT_CHANGES=true

log () {
echo -e "\033[0;33m$(date "+%H:%M:%S")\033[0;37m ==> $1."
}

travis_setup_git() {
git config user.email "[email protected]"
git config user.name "Travis CI"
circle_setup_git() {
git config user.email "[email protected]"
git config user.name "Circle CI"
git remote add upstream "https://$GH_TOKEN@$GIT_URL"
}

show_important_vars() {
echo " REPO_URL: $REPO_URL"
echo " BUILD_DIR: $BUILD_DIR"
echo " REPO_DIR: $REPO_DIR"
echo " TRAVIS: $TRAVIS"
echo " CIRCLECI: $CIRCLECI"
echo " COMMIT_CHANGES: $COMMIT_CHANGES"
}

Expand Down Expand Up @@ -71,24 +72,24 @@ update_chart_version() {
CHART_VERSION=$(grep '^version:' $CHART_PATH/Chart.yaml | awk '{print $2}')
CHART_VERSION_NEXT="${CHART_VERSION%.*}.$((${CHART_VERSION##*.}+1))"
sed -i 's|^version:.*|version: '"$CHART_VERSION_NEXT"'|g' $CHART_PATH/Chart.yaml
sed -i 's|^appVersion:.*|appVersion: '"$TRAVIS_TAG"'|g' $CHART_PATH/Chart.yaml
sed -i '/bitnami\/monocular/{n; s/tag:.*/tag: '"$TRAVIS_TAG"'/}' $CHART_PATH/values.yaml
sed -i 's|^appVersion:.*|appVersion: '"$IMAGE_TAG"'|g' $CHART_PATH/Chart.yaml
sed -i '/bitnami\/monocular/{n; s/tag:.*/tag: '"$IMAGE_TAG"'/}' $CHART_PATH/values.yaml

if [ $COMMIT_CHANGES != "false" ]; then
log "Commiting chart source changes to master branch"
git add $CHART_PATH/Chart.yaml $CHART_PATH/values.yaml
git commit --message "chart: bump to $CHART_VERSION_NEXT [skip ci]" --message "travis build #$TRAVIS_BUILD_NUMBER"
git commit --message "chart: bump to $CHART_VERSION_NEXT [skip ci]" --message "circle build #$CIRCLE_BUILD_NUM"
git push -q upstream HEAD:master
fi
}

show_important_vars

travis_setup_git
circle_setup_git
git fetch upstream

# Bump chart if this is a release
if [[ -n "$TRAVIS_TAG" ]]; then
if [[ "$IMAGE_TAG" != "latest" ]]; then
log "Updating chart version"
update_chart_version
fi
Expand Down Expand Up @@ -130,7 +131,7 @@ cp $BUILD_DIR/* $REPO_DIR
if [ $COMMIT_CHANGES != "false" ]; then
log "Commiting changes to gh-pages branch"
git add *.tgz index.yaml
git commit --message "release $CHART_VERSION [skip ci]" --message "travis build #$TRAVIS_BUILD_NUMBER"
git commit --message "release $CHART_VERSION [skip ci]" --message "circle build #$CIRCLE_BUILD_NUM"
git push -q upstream HEAD:gh-pages
fi

Expand Down

0 comments on commit d430401

Please sign in to comment.