Skip to content

Commit e0864b6

Browse files
authored
Merge pull request #27 from stefanprodan/ci
Migrate to CircleCI and run e2e tests with Kubernetes Kind
2 parents dc27269 + de2a9c4 commit e0864b6

File tree

14 files changed

+160
-64
lines changed

14 files changed

+160
-64
lines changed

.circleci/config.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
version: 2.1
22
jobs:
3+
e2e-kubernetes:
4+
machine: true
5+
steps:
6+
- checkout
7+
- run: e2e/bootstrap.sh
8+
- run: e2e/install.sh
9+
- run: e2e/test.sh
10+
11+
build-container:
12+
docker:
13+
- image: circleci/golang:1.12
14+
working_directory: ~/build
15+
steps:
16+
- checkout
17+
- setup_remote_docker:
18+
docker_layer_caching: true
19+
- run: make build-container
20+
- run: |
21+
if [ -z "$CIRCLE_TAG" ]; then
22+
echo "Not a release, skipping container push";
23+
else
24+
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin;
25+
echo $QUAY_PASS | docker login -u $QUAY_USER --password-stdin quay.io;
26+
make push-container;
27+
fi
28+
29+
push-binary:
30+
docker:
31+
- image: circleci/golang:1.12
32+
steps:
33+
- checkout
34+
- run: curl -sL https://git.io/goreleaser | bash
35+
336
push-helm-charts:
437
docker:
538
- image: circleci/golang:1.12
@@ -40,11 +73,30 @@ jobs:
4073
else
4174
echo "Not a release! Skip charts publish"
4275
fi
76+
4377
workflows:
4478
version: 2
79+
build-test:
80+
jobs:
81+
- build-container
82+
- e2e-kubernetes
4583
release:
4684
jobs:
85+
- build-container:
86+
filters:
87+
branches:
88+
ignore: /.*/
89+
tags:
90+
ignore: /^chart.*/
91+
- push-binary:
92+
filters:
93+
branches:
94+
ignore: /.*/
95+
tags:
96+
ignore: /^chart.*/
4797
- push-helm-charts:
98+
requires:
99+
- build-container
48100
filters:
49101
branches:
50102
ignore: /.*/

.travis.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ TAG?=latest
66
NAME:=podinfo
77
DOCKER_REPOSITORY:=stefanprodan
88
DOCKER_IMAGE_NAME:=$(DOCKER_REPOSITORY)/$(NAME)
9-
GITCOMMIT:=$(shell git describe --dirty --always)
9+
GIT_COMMIT:=$(shell git describe --dirty --always)
1010
VERSION:=$(shell grep 'VERSION' pkg/version/version.go | awk '{ print $$4 }' | tr -d '"')
1111

1212
run:
13-
GO111MODULE=on go run cmd/podinfo/*
13+
GO111MODULE=on go run -ldflags "-s -w -X github.com/stefanprodan/podinfo/pkg/version.REVISION=$(GIT_COMMIT)" cmd/podinfo/* --level=debug
1414

1515
test:
1616
GO111MODULE=on go test -v -race ./...
1717

1818
build:
19-
GO111MODULE=on GIT_COMMIT=$$(git rev-list -1 HEAD) && GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/stefanprodan/podinfo/pkg/version.REVISION=$${GIT_COMMIT}" -a -o ./bin/podinfo ./cmd/podinfo/*
20-
GO111MODULE=on GIT_COMMIT=$$(git rev-list -1 HEAD) && GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/stefanprodan/podinfo/pkg/version.REVISION=$${GIT_COMMIT}" -a -o ./bin/podcli ./cmd/podcli/*
19+
GO111MODULE=on GIT_COMMIT=$$(git rev-list -1 HEAD) && GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/stefanprodan/podinfo/pkg/version.REVISION=$(GIT_COMMIT)" -a -o ./bin/podinfo ./cmd/podinfo/*
20+
GO111MODULE=on GIT_COMMIT=$$(git rev-list -1 HEAD) && GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/stefanprodan/podinfo/pkg/version.REVISION=$(GIT_COMMIT)" -a -o ./bin/podcli ./cmd/podcli/*
2121

2222
build-charts:
2323
helm lint charts/*
@@ -26,6 +26,13 @@ build-charts:
2626
build-container:
2727
docker build -t $(DOCKER_IMAGE_NAME):$(VERSION) .
2828

29+
test-container:
30+
@docker rm -f podinfo || true
31+
@docker run -dp 9898:9898 --name=podinfo $(DOCKER_IMAGE_NAME):$(VERSION)
32+
@docker ps
33+
@TOKEN=$$(curl -sd 'test' localhost:9898/token | jq -r .token) && \
34+
curl -sH "Authorization: Bearer $${TOKEN}" localhost:9898/token/validate | grep test
35+
2936
push-container:
3037
docker push $(DOCKER_IMAGE_NAME):$(VERSION)
3138
docker tag $(DOCKER_IMAGE_NAME):$(VERSION) quay.io/$(DOCKER_IMAGE_NAME):$(VERSION)

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# podinfo
22

3-
[![Build Status](https://travis-ci.org/stefanprodan/podinfo.svg?branch=master)](https://travis-ci.org/stefanprodan/podinfo)
3+
[![CircleCI](https://circleci.com/gh/stefanprodan/podinfo.svg?style=svg)](https://circleci.com/gh/stefanprodan/podinfo)
44
[![Docker Pulls](https://img.shields.io/docker/pulls/stefanprodan/podinfo)](https://hub.docker.com/r/stefanprodan/podinfo)
55

66
Podinfo is a tiny web application made with Go
@@ -16,7 +16,8 @@ Specifications:
1616
* Structured logging with zap
1717
* 12-factor app with viper
1818
* Fault injection (random errors and latency)
19-
* Helm chart
19+
* Helm and Kustomize installers
20+
* End-to-End testing with Kubernetes Kind and Helm
2021

2122
Web API:
2223

@@ -41,6 +42,10 @@ Web API:
4142
* `GET /ws/echo` echos content via websockets `podcli ws ws://localhost:9898/ws/echo`
4243
* `GET /chunked/{seconds}` uses `transfer-encoding` type `chunked` to give a partial response and then waits for the specified period
4344

45+
Web UI:
46+
47+
![podinfo-ui](https://raw.githubusercontent.com/stefanprodan/podinfo/gh-pages/screens/podinfo-ui.png)
48+
4449
### Guides
4550

4651
* [Automated canary deployments with Flagger and Istio](https://medium.com/google-cloud/automated-canary-deployments-with-flagger-and-istio-ac747827f9d1)
@@ -57,9 +62,12 @@ helm repo add sp https://stefanprodan.github.io/podinfo
5762

5863
helm upgrade --install --wait frontend \
5964
--namespace test \
65+
--set replicaCount=2 \
6066
--set backend=http://backend-podinfo:9898/echo \
6167
sp/podinfo
6268

69+
helm test frontend --cleanup
70+
6371
helm upgrade --install --wait backend \
6472
--namespace test \
6573
--set hpa.enabled=true \

charts/podinfo/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
2-
version: 2.0.0
3-
appVersion: 2.0.0
2+
version: 2.0.1
3+
appVersion: 2.0.1
44
name: podinfo
55
engine: gotpl
66
description: Podinfo Helm chart for Kubernetes

charts/podinfo/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ spec:
5858
- check
5959
- http
6060
- localhost:{{ .Values.service.containerPort }}/healthz
61-
initialDelaySeconds: 5
61+
initialDelaySeconds: 1
6262
timeoutSeconds: 5
6363
readinessProbe:
6464
exec:
@@ -67,7 +67,7 @@ spec:
6767
- check
6868
- http
6969
- localhost:{{ .Values.service.containerPort }}/readyz
70-
initialDelaySeconds: 5
70+
initialDelaySeconds: 1
7171
timeoutSeconds: 5
7272
volumeMounts:
7373
- name: data

charts/podinfo/templates/tests/storage.yaml renamed to charts/podinfo/templates/tests/jwt.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: Pod
33
metadata:
4-
name: {{ template "podinfo.fullname" . }}-storage-test-{{ randAlphaNum 5 | lower }}
4+
name: {{ template "podinfo.fullname" . }}-jwt-test-{{ randAlphaNum 5 | lower }}
55
labels:
66
heritage: {{ .Release.Service }}
77
release: {{ .Release.Name }}
@@ -13,7 +13,7 @@ spec:
1313
containers:
1414
- name: tools
1515
image: giantswarm/tiny-tools
16-
command: ["/bin/sh", "/scripts/ping.sh"]
16+
command: ["/bin/sh", "/scripts/test.sh"]
1717
env:
1818
- name: PODINFO_SVC
1919
value: {{ template "podinfo.fullname" . }}:{{ .Values.service.externalPort }}
@@ -36,6 +36,8 @@ metadata:
3636
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
3737
app: {{ template "podinfo.name" . }}
3838
data:
39-
ping.sh: |
39+
test.sh: |
4040
#!/bin/sh
41-
curl -sS ${PODINFO_SVC}/store/$(curl -sSd 'test' ${PODINFO_SVC}/store | jq -r .hash) |grep test
41+
echo "testing ${PODINFO_SVC}/token"
42+
TOKEN=$(curl -sd 'test' ${PODINFO_SVC}/token | jq -r .token) && \
43+
curl -H "Authorization: Bearer ${TOKEN}" ${PODINFO_SVC}/token/validate | grep test

charts/podinfo/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ faults:
1212

1313
image:
1414
repository: quay.io/stefanprodan/podinfo
15-
tag: 2.0.0
15+
tag: 2.0.1
1616
pullPolicy: IfNotPresent
1717

1818
service:

e2e/bootstrap.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
REPO_ROOT=$(git rev-parse --show-toplevel)
6+
KIND_VERSION=v0.4.0
7+
8+
if [[ "$1" ]]; then
9+
KIND_VERSION=$1
10+
fi
11+
12+
echo ">>> Installing kubectl"
13+
curl -sLO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \
14+
chmod +x kubectl && \
15+
sudo mv kubectl /usr/local/bin/
16+
17+
echo ">>> Installing kind"
18+
curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64"
19+
chmod +x kind
20+
sudo mv kind /usr/local/bin/kind
21+
22+
echo ">>> Creating kind cluster"
23+
kind create cluster --wait 5m
24+
25+
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
26+
kubectl get pods --all-namespaces
27+
28+
echo ">>> Installing Helm"
29+
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
30+
31+
echo '>>> Installing Tiller'
32+
kubectl --namespace kube-system create sa tiller
33+
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
34+
helm init --service-account tiller --upgrade --wait

e2e/install.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
REPO_ROOT=$(git rev-parse --show-toplevel)
6+
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
7+
8+
echo ">>> Building container"
9+
docker build -t test/podinfo:latest .
10+
11+
echo '>>> Loading image in Kind'
12+
kind load docker-image test/podinfo:latest
13+
14+
echo '>>> Installing'
15+
helm upgrade -i podinfo ${REPO_ROOT}/charts/podinfo --namespace=default
16+
kubectl set image deployment/podinfo podinfo=test/podinfo:latest
17+
kubectl rollout status deployment/podinfo

0 commit comments

Comments
 (0)