Setup CI: Build, run e2e tests, and push images to docker hub

This commit is contained in:
Mehran Kholdi 2020-06-19 22:08:55 +04:30
parent 16f92da467
commit ab407f3349
11 changed files with 123 additions and 21 deletions

8
.ci/build.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
set -ex
source .ci/common
docker build -t $CI_IMAGE_URI --build-arg IMAGE_REPOSITORY=${IMAGE} --build-arg IMAGE_TAG=${COMMIT} .
docker login -u "${DNAME}" -p "${DPASS}";
TagAndPushImage $CI_IMAGE_REPO $CI_TAG;

21
.ci/common Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
set -ex
export IMAGE="openebs/rawfile-localpv"
export COMMIT=$(git rev-parse --short HEAD)
export BRANCH=${TRAVIS_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
export CI_REGISTRY="docker.io"
export CI_TAG="${COMMIT}-ci"
export CI_IMAGE_REPO="${CI_REGISTRY}/${IMAGE}"
export CI_IMAGE_URI="${CI_IMAGE_REPO}:${CI_TAG}"
function TagAndPushImage() {
REPO="$1"
TAG="$2"
IMAGE_URI="${REPO}:${TAG}${TAG_SUFFIX}";
sudo docker tag ${CI_IMAGE_URI} ${IMAGE_URI};
echo " push ${IMAGE_URI}";
sudo docker push ${IMAGE_URI};
}

View File

@ -0,0 +1,19 @@
StorageClass:
FromName: true
SnapshotClass:
FromName: true
DriverInfo:
Name: rawfile.hamravesh.com
Capabilities:
persistence: true
block: false
fsGroup: true
exec: true
snapshotDataSource: false
pvcDataSource: false
multipods: true
RWX: false
controllerExpansion: true
nodeExpansion: true
volumeLimits: false
InlineVolumes: []

22
.ci/e2e-test/setup.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -ex
source .ci/common
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.18.1/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
sudo apt update && sudo apt install -y conntrack
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.8.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
mkdir -p $HOME/.kube $HOME/.minikube
touch $KUBECONFIG
sudo minikube start --profile=minikube --vm-driver=none --kubernetes-version=v1.18.1
minikube update-context --profile=minikube
chown -R travis: /home/travis/.minikube/
eval "$(minikube docker-env --profile=minikube)" && export DOCKER_CLI='docker'
curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm upgrade --wait \
-n kube-system -i rawfile-csi \
--set serviceMonitor.enabled=false \
--set controller.image.repository=$CI_IMAGE_REPO --set controller.image.tag=$CI_TAG \
--set node.image.repository=$CI_IMAGE_REPO --set node.image.tag=$CI_TAG \
./deploy/charts/rawfile-csi/

14
.ci/e2e-test/test.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
set -ex
cd $(dirname $0)
curl --location https://dl.k8s.io/v1.18.1/kubernetes-test-linux-amd64.tar.gz | tar --strip-components=3 -zxf - kubernetes/test/bin/e2e.test kubernetes/test/bin/ginkgo
ssh-keygen -N "" -f $HOME/.ssh/id_rsa
cat $HOME/.ssh/id_rsa.pub >>$HOME/.ssh/authorized_keys
./e2e.test \
-ginkgo.v \
-ginkgo.focus='External.Storage' \
-storage.testdriver=rawfile-driver.yaml \
-report-dir report/

10
.ci/publish.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
set -ex
source .ci/common
docker pull ${CI_IMAGE_URI}
docker login -u "${DNAME}" -p "${DPASS}";
for TAG in $COMMIT $BRANCH; do
TagAndPushImage "docker.io/${IMAGE}" $TAG;
done;

View File

@ -1,20 +0,0 @@
build:
stage: build
image: docker:stable
variables:
IMAGE_REPO: hamravesh/rawfile-csi
script:
- export REGISTRY=docker.io
- mkdir -p ~/.docker/; echo $DOCKER_AUTH_CONFIG >~/.docker/config.json
- export IMAGE="$REGISTRY/$IMAGE_REPO"
- |
docker build \
-t $IMAGE:$CI_COMMIT_SHORT_SHA \
-t $IMAGE:$CI_COMMIT_REF_SLUG \
--build-arg IMAGE_TAG=$CI_COMMIT_SHORT_SHA \
--build-arg IMAGE_REPOSITORY=$IMAGE \
.
- docker push $IMAGE:$CI_COMMIT_SHORT_SHA
- docker push $IMAGE:$CI_COMMIT_REF_SLUG
tags:
- docker

20
.travis.yml Normal file
View File

@ -0,0 +1,20 @@
os: linux
dist: bionic
language: minimal
jobs:
include:
- stage: build
script: ./.ci/build.sh
- stage: e2e-test
install: ./.ci/e2e-test/setup.sh
if: NOT(commit_message =~ /skip-e2e/)
script: ./.ci/e2e-test/test.sh
env:
- CHANGE_MINIKUBE_NONE_USER=true
- MINIKUBE_WANTUPDATENOTIFICATION=false
- MINIKUBE_WANTREPORTERRORPROMPT=false
- MINIKUBE_HOME=$HOME
- CHANGE_MINIKUBE_NONE_USER=true
- KUBECONFIG=$HOME/.kube/config
- stage: publish
script: ./.ci/publish.sh

View File

@ -2,5 +2,5 @@ apiVersion: v2
name: rawfile-csi
description: RawFile Driver Container Storage Interface
type: application
version: 0.1.4
version: 0.1.5
appVersion: 0.0.1

View File

@ -46,6 +46,10 @@ spec:
value: unix:///csi/csi.sock
- name: IMAGE_REPOSITORY
value: "{{ .Values.controller.image.repository }}"
{{- if regexMatch "^.*-ci$" .Values.controller.image.tag }}
- name: IMAGE_TAG
value: "{{ .Values.controller.image.tag }}"
{{- end }}
volumeMounts:
- name: socket-dir
mountPath: /csi

View File

@ -64,6 +64,10 @@ spec:
value: unix:///csi/csi.sock
- name: IMAGE_REPOSITORY
value: "{{ .Values.node.image.repository }}"
{{- if regexMatch "^.*-ci$" .Values.node.image.tag }}
- name: IMAGE_TAG
value: "{{ .Values.node.image.tag }}"
{{- end }}
- name: NODE_ID
valueFrom:
fieldRef: