Skip to content

Commit 25f32f4

Browse files
displaguericardorg79
authored andcommitted
use chiefy/linodego to access Linode APIv4 (#4)
* use chiefy/linodego to access Linode APIv4 * dep ensure -update * lookup the instanceID from the linodeLabel, when provided * Made region a required param * Made region argument required * added testing * Added testing via `make test` - Added Makefile script -- added make test -- moved scripts/* code into Makefile - Added waiting for device code to Create function * Fixed code that waited for attachment and detachment of volume * use latest chiefy/linodego for AttachVolume fixes (dep ensure -update) * if AttachVolume fails, it may already be mounted AttachVolumes has changed upstream, update the call to it just poll for matching ids, for now TODO: the 180 timeout should align with some docker specified timeout * Move format from creation time to mount time * removed `go test` from `make check` * Fixing check step
1 parent d8e00f5 commit 25f32f4

17 files changed

+574
-680
lines changed

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ language: go
88
jobs:
99
include:
1010
- stage: build
11-
script: ./scripts/build.sh
12-
- stage: test
13-
script: ./scripts/test.sh
11+
script: make build
12+
- stage: check
13+
script: make check
14+
- stage: unit-test
15+
script: make unit-test
1416
- stage: deploy
15-
script: ./scripts/deploy.sh
17+
script: make deploy
1618
if: tag =~ ^v\d
17-
- stage: deploy-latest
18-
if: tag =~ ^v\d
19-
script: ./scripts/deploy.sh

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ CMD ["/go/bin/docker-volume-linode"]
1414
FROM alpine
1515
COPY --from=builder /go/bin/docker-volume-linode .
1616
RUN apk update && apk add ca-certificates e2fsprogs
17-
CMD ["docker-volume-sshfs"]
17+
CMD ["./docker-volume-linode"]

Gopkg.lock

Lines changed: 23 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
version = "1.0.3"
3131

3232
[[constraint]]
33-
name = "gopkg.in/resty.v1"
34-
version = "1.6.0"
33+
name = "github.com/chiefy/linodego"
34+
branch = "master"
3535

3636
[prune]
3737
go-tests = true

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
# Build Arguments
3+
TRAVIS_BRANCH ?= test
4+
TRAVIS_BUILD_NUMBER ?= 9999
5+
6+
# Deploy Arguments
7+
DOCKER_PASSWORD ?= xxxxx
8+
9+
# Test Arguments
10+
TEST_TOKEN ?= xyz
11+
TEST_REGION ?= xyz
12+
TEST_LABEL ?= xyz
13+
14+
GOPATH=$(shell go env GOPATH)
15+
16+
# e.g: docker-volume-linode:rootfs.30
17+
PLUGIN_NAME_ROOTFS=docker-volume-linode:rootfs.${TRAVIS_BUILD_NUMBER}
18+
19+
# e.g: docker-volume-linode:master.30
20+
# e.g: docker-volume-linode:v1.1.30
21+
PLUGIN_NAME=libgolang/docker-volume-linode:${TRAVIS_BRANCH}.${TRAVIS_BUILD_NUMBER}
22+
PLUGIN_NAME_LATEST=libgolang/docker-volume-linode:latest
23+
24+
PLUGIN_DIR=plugin-contents-dir
25+
26+
all: clean build
27+
28+
deploy: build
29+
# Login to docker
30+
@echo '${DOCKER_PASSWORD}' | docker login -u libgolang --password-stdin
31+
# Push images
32+
docker plugin push ${PLUGIN_NAME}
33+
docker plugin push ${PLUGIN_NAME_LATEST}
34+
35+
build: $(PLUGIN_DIR)
36+
# load plugin with versionied tag
37+
docker plugin rm -f ${PLUGIN_NAME} 2>/dev/null || true
38+
docker plugin create ${PLUGIN_NAME} ./$(PLUGIN_DIR)
39+
# load plugin with `latest` tag
40+
docker plugin rm -f ${PLUGIN_NAME_LATEST} 2>/dev/null || true
41+
docker plugin create ${PLUGIN_NAME_LATEST} ./$(PLUGIN_DIR)
42+
43+
$(PLUGIN_DIR): $(GOPATH)/bin/dep *.go Dockerfile
44+
# compile
45+
dep ensure
46+
docker build --no-cache -q -t ${PLUGIN_NAME_ROOTFS} .
47+
# assemble
48+
mkdir -p ./$(PLUGIN_DIR)/rootfs
49+
docker create --name tmp ${PLUGIN_NAME_ROOTFS}
50+
docker export tmp | tar -x -C ./$(PLUGIN_DIR)/rootfs
51+
cp config.json ./$(PLUGIN_DIR)/
52+
docker rm -vf tmp
53+
54+
# Run Integration Tests
55+
# Requires TEST_* Variables to be set
56+
test: test-pre-check \
57+
build \
58+
test-setup \
59+
test-create-volume-50 \
60+
test-rm-volume-50 \
61+
test-create-volume \
62+
test-use-volume \
63+
clean-volumes
64+
65+
test-create-volume:
66+
docker volume create -d libgolang/docker-volume-linode test-volume-default-size
67+
68+
test-create-volume-50:
69+
docker volume create -d libgolang/docker-volume-linode -o size=50 test-volume-50g
70+
71+
test-rm-volume-50:
72+
docker volume rm test-volume-50g
73+
74+
test-use-volume:
75+
docker run --rm -i -v test-volume-default-size:/mnt busybox touch /mnt/abc.txt
76+
docker run --rm -i -v test-volume-default-size:/mnt busybox test -f /mnt/abc.txt || false
77+
78+
test-pre-check:
79+
@if [ "${TEST_TOKEN}" = "xyz" ] || [ "${TEST_REGION}" = "xyz" ] || [ "${TEST_LABEL}" = "xyz" ] ; then \
80+
echo -en "#############################\nYou must set TEST_* Variables\n#############################\n"; exit 1; fi
81+
82+
test-setup:
83+
@docker plugin set libgolang/docker-volume-linode LINODE_TOKEN=${TEST_TOKEN} LINODE_REGION=${TEST_REGION} LINODE_LABEL=${TEST_LABEL}
84+
docker plugin enable libgolang/docker-volume-linode
85+
86+
check: $(GOPATH)/bin/dep
87+
# Tools
88+
go get -u github.com/tsenart/deadcode
89+
go get -u github.com/kisielk/errcheck
90+
go get -u golang.org/x/lint/golint
91+
# Run Code Tests
92+
dep ensure
93+
go vet
94+
errcheck
95+
golint
96+
deadcode
97+
98+
unit-test: $(GOPATH)/bin/dep
99+
dep ensure
100+
go test
101+
102+
$(GOPATH)/bin/dep:
103+
go get -u github.com/golang/dep/cmd/dep
104+
105+
.PHONY clean:
106+
rm -fr $(PLUGIN_DIR)
107+
108+
clean-volumes:
109+
docker volume ls -q | grep 'test-' | xargs docker volume rm
110+
clean-installed-plugins:
111+
docker plugin ls | grep libgolang | grep -v ID | awk '{print $$1}' | xargs docker plugin rm -f
112+

0 commit comments

Comments
 (0)