diff --git a/.ci/build.sh b/.ci/build.sh new file mode 100755 index 0000000..e3285dc --- /dev/null +++ b/.ci/build.sh @@ -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; diff --git a/.ci/common b/.ci/common new file mode 100644 index 0000000..60514eb --- /dev/null +++ b/.ci/common @@ -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}; +} diff --git a/.ci/e2e-test/rawfile-driver.yaml b/.ci/e2e-test/rawfile-driver.yaml new file mode 100644 index 0000000..47f3fa1 --- /dev/null +++ b/.ci/e2e-test/rawfile-driver.yaml @@ -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: [] diff --git a/.ci/e2e-test/setup.sh b/.ci/e2e-test/setup.sh new file mode 100755 index 0000000..1a3a292 --- /dev/null +++ b/.ci/e2e-test/setup.sh @@ -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/ diff --git a/.ci/e2e-test/test.sh b/.ci/e2e-test/test.sh new file mode 100755 index 0000000..6b77869 --- /dev/null +++ b/.ci/e2e-test/test.sh @@ -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/ diff --git a/.ci/publish.sh b/.ci/publish.sh new file mode 100755 index 0000000..0a970ef --- /dev/null +++ b/.ci/publish.sh @@ -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; diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 1b51645..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -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 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..45f50ae --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/deploy/charts/rawfile-csi/Chart.yaml b/deploy/charts/rawfile-csi/Chart.yaml index 3af7a54..500c82f 100644 --- a/deploy/charts/rawfile-csi/Chart.yaml +++ b/deploy/charts/rawfile-csi/Chart.yaml @@ -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 diff --git a/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml b/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml index e243a6e..2026c36 100644 --- a/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml +++ b/deploy/charts/rawfile-csi/templates/01-controller-plugin.yaml @@ -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 diff --git a/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml b/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml index 3c4d232..a3bf569 100644 --- a/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml +++ b/deploy/charts/rawfile-csi/templates/01-node-plugin.yaml @@ -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: