Add ci pipeline with GitLab (#3)

* Add automated testing
* Create loop device while staging s3backer
This commit is contained in:
Cyrill Troxler 2018-08-03 20:30:46 +02:00 committed by GitHub
parent f603d84fc5
commit 9291d09baa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 4 deletions

30
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,30 @@
image:
name: ctrox/csi-s3:test
entrypoint: [""]
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
GO_PROJECT_BASE: /go/src/github.com/ctrox
GO_PROJECT_DIR: $GO_PROJECT_BASE/csi-s3
stages:
- build
- test
build:
stage: build
before_script:
- mkdir -p $GO_PROJECT_BASE
- ln -s $CI_PROJECT_DIR $GO_PROJECT_BASE
- cd $GO_PROJECT_DIR
script:
- make build
test:
stage: test
image: docker:stable
services:
- docker:dind
script:
- docker run --rm --privileged -v $(pwd):$GO_PROJECT_DIR --device /dev/fuse ctrox/$CI_PROJECT_NAME:test

View file

@ -25,7 +25,7 @@ build:
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/s3driver ./cmd/s3driver
test:
docker build -t $(TEST_IMAGE_TAG) -f test/Dockerfile .
docker run --rm --privileged -v $(PWD):$(PROJECT_DIR):ro -v /dev:/dev $(TEST_IMAGE_TAG)
docker run --rm --privileged -v $(PWD):$(PROJECT_DIR):ro --device /dev/fuse $(TEST_IMAGE_TAG)
container: build
docker build -t $(IMAGE_TAG) -f cmd/s3driver/Dockerfile .
push: container

View file

@ -27,6 +27,8 @@ const (
// blockSize to use in k
s3backerBlockSize = "128k"
s3backerDefaultSize = 1024 * 1024 * 1024 // 1GiB
// S3backerLoopDevice the loop device required by s3backer
S3backerLoopDevice = "/dev/loop0"
)
func newS3backerMounter(bucket *bucket, cfg *Config) (Mounter, error) {
@ -55,6 +57,10 @@ func (s3backer *s3backerMounter) String() string {
}
func (s3backer *s3backerMounter) Stage(stageTarget string) error {
// s3backer uses the loop device
if err := createLoopDevice(S3backerLoopDevice); err != nil {
return err
}
// s3backer requires two mounts
// first mount will fuse mount the bucket to a single 'file'
if err := s3backer.mountInit(stageTarget); err != nil {

View file

@ -121,6 +121,8 @@ var _ = Describe("S3Driver", func() {
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
Expect(err).NotTo(HaveOccurred())
}
// Clear loop device so we cover the creation of it
os.Remove(s3.S3backerLoopDevice)
driver, err := s3.NewS3("test-node", csiEndpoint, cfg)
if err != nil {
log.Fatal(err)

View file

@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"syscall"
"time"
@ -67,3 +68,20 @@ func getCmdLine(pid int) (string, error) {
}
return string(cmdLine), nil
}
func createLoopDevice(device string) error {
if _, err := os.Stat(device); !os.IsNotExist(err) {
return nil
}
args := []string{
device,
"b", "7", "0",
}
cmd := exec.Command("mknod", args...)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Error configuring loop device: %s", out)
}
return nil
}

View file

@ -4,17 +4,25 @@ LABEL description="csi-s3 testing image"
RUN apt-get update && \
apt-get install -y \
git wget && \
git wget make && \
rm -rf /var/lib/apt/lists/*
RUN wget -q https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz && \
tar -xf go1.10.3.linux-amd64.tar.gz && \
rm go1.10.3.linux-amd64.tar.gz && \
mv go /usr/local
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
# install dep
RUN wget -q https://raw.githubusercontent.com/golang/dep/master/install.sh && \
mkdir -p /go/bin && \
sh ./install.sh
RUN go get -u github.com/minio/minio && go install github.com/minio/minio/cmd
ENTRYPOINT ["/go/src/github.com/ctrox/csi-s3/test/test.sh"]
ADD test/test.sh /usr/local/bin
ENTRYPOINT ["/usr/local/bin/test.sh"]

View file

@ -3,6 +3,8 @@ export MINIO_ACCESS_KEY=FJDSJ
export MINIO_SECRET_KEY=DSG643HGDS
mkdir -p /tmp/minio
minio server --quiet /tmp/minio &
minio server --quiet /tmp/minio &>/dev/null &
sleep 5
cd $GOPATH/src/github.com/ctrox/csi-s3
if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
go test github.com/ctrox/csi-s3/pkg/s3 -cover