Add ci pipeline with GitLab (#3)
* Add automated testing * Create loop device while staging s3backer
This commit is contained in:
parent
f603d84fc5
commit
9291d09baa
7 changed files with 70 additions and 4 deletions
30
.gitlab-ci.yml
Normal file
30
.gitlab-ci.yml
Normal 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
|
2
Makefile
2
Makefile
|
@ -25,7 +25,7 @@ build:
|
||||||
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/s3driver ./cmd/s3driver
|
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/s3driver ./cmd/s3driver
|
||||||
test:
|
test:
|
||||||
docker build -t $(TEST_IMAGE_TAG) -f test/Dockerfile .
|
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
|
container: build
|
||||||
docker build -t $(IMAGE_TAG) -f cmd/s3driver/Dockerfile .
|
docker build -t $(IMAGE_TAG) -f cmd/s3driver/Dockerfile .
|
||||||
push: container
|
push: container
|
||||||
|
|
|
@ -27,6 +27,8 @@ const (
|
||||||
// blockSize to use in k
|
// blockSize to use in k
|
||||||
s3backerBlockSize = "128k"
|
s3backerBlockSize = "128k"
|
||||||
s3backerDefaultSize = 1024 * 1024 * 1024 // 1GiB
|
s3backerDefaultSize = 1024 * 1024 * 1024 // 1GiB
|
||||||
|
// S3backerLoopDevice the loop device required by s3backer
|
||||||
|
S3backerLoopDevice = "/dev/loop0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newS3backerMounter(bucket *bucket, cfg *Config) (Mounter, error) {
|
func newS3backerMounter(bucket *bucket, cfg *Config) (Mounter, error) {
|
||||||
|
@ -55,6 +57,10 @@ func (s3backer *s3backerMounter) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s3backer *s3backerMounter) Stage(stageTarget string) error {
|
func (s3backer *s3backerMounter) Stage(stageTarget string) error {
|
||||||
|
// s3backer uses the loop device
|
||||||
|
if err := createLoopDevice(S3backerLoopDevice); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// s3backer requires two mounts
|
// s3backer requires two mounts
|
||||||
// first mount will fuse mount the bucket to a single 'file'
|
// first mount will fuse mount the bucket to a single 'file'
|
||||||
if err := s3backer.mountInit(stageTarget); err != nil {
|
if err := s3backer.mountInit(stageTarget); err != nil {
|
||||||
|
|
|
@ -121,6 +121,8 @@ var _ = Describe("S3Driver", func() {
|
||||||
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
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)
|
driver, err := s3.NewS3("test-node", csiEndpoint, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -67,3 +68,20 @@ func getCmdLine(pid int) (string, error) {
|
||||||
}
|
}
|
||||||
return string(cmdLine), nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -4,17 +4,25 @@ LABEL description="csi-s3 testing image"
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
git wget && \
|
git wget make && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN wget -q https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz && \
|
RUN wget -q https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz && \
|
||||||
tar -xf 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
|
mv go /usr/local
|
||||||
|
|
||||||
ENV GOROOT /usr/local/go
|
ENV GOROOT /usr/local/go
|
||||||
ENV GOPATH /go
|
ENV GOPATH /go
|
||||||
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
|
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
|
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"]
|
||||||
|
|
|
@ -3,6 +3,8 @@ export MINIO_ACCESS_KEY=FJDSJ
|
||||||
export MINIO_SECRET_KEY=DSG643HGDS
|
export MINIO_SECRET_KEY=DSG643HGDS
|
||||||
|
|
||||||
mkdir -p /tmp/minio
|
mkdir -p /tmp/minio
|
||||||
minio server --quiet /tmp/minio &
|
minio server --quiet /tmp/minio &>/dev/null &
|
||||||
sleep 5
|
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
|
go test github.com/ctrox/csi-s3/pkg/s3 -cover
|
||||||
|
|
Loading…
Reference in a new issue