Skip to content

Commit

Permalink
use chiefy/linodego to access Linode APIv4 (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
displague authored and ricardorg79 committed Jul 20, 2018
1 parent d8e00f5 commit 25f32f4
Show file tree
Hide file tree
Showing 17 changed files with 574 additions and 680 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ language: go
jobs:
include:
- stage: build
script: ./scripts/build.sh
- stage: test
script: ./scripts/test.sh
script: make build
- stage: check
script: make check
- stage: unit-test
script: make unit-test
- stage: deploy
script: ./scripts/deploy.sh
script: make deploy
if: tag =~ ^v\d
- stage: deploy-latest
if: tag =~ ^v\d
script: ./scripts/deploy.sh
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ CMD ["/go/bin/docker-volume-linode"]
FROM alpine
COPY --from=builder /go/bin/docker-volume-linode .
RUN apk update && apk add ca-certificates e2fsprogs
CMD ["docker-volume-sshfs"]
CMD ["./docker-volume-linode"]
38 changes: 23 additions & 15 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
version = "1.0.3"

[[constraint]]
name = "gopkg.in/resty.v1"
version = "1.6.0"
name = "github.com/chiefy/linodego"
branch = "master"

[prune]
go-tests = true
Expand Down
112 changes: 112 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

# Build Arguments
TRAVIS_BRANCH ?= test
TRAVIS_BUILD_NUMBER ?= 9999

# Deploy Arguments
DOCKER_PASSWORD ?= xxxxx

# Test Arguments
TEST_TOKEN ?= xyz
TEST_REGION ?= xyz
TEST_LABEL ?= xyz

GOPATH=$(shell go env GOPATH)

# e.g: docker-volume-linode:rootfs.30
PLUGIN_NAME_ROOTFS=docker-volume-linode:rootfs.${TRAVIS_BUILD_NUMBER}

# e.g: docker-volume-linode:master.30
# e.g: docker-volume-linode:v1.1.30
PLUGIN_NAME=libgolang/docker-volume-linode:${TRAVIS_BRANCH}.${TRAVIS_BUILD_NUMBER}
PLUGIN_NAME_LATEST=libgolang/docker-volume-linode:latest

PLUGIN_DIR=plugin-contents-dir

all: clean build

deploy: build
# Login to docker
@echo '${DOCKER_PASSWORD}' | docker login -u libgolang --password-stdin
# Push images
docker plugin push ${PLUGIN_NAME}
docker plugin push ${PLUGIN_NAME_LATEST}

build: $(PLUGIN_DIR)
# load plugin with versionied tag
docker plugin rm -f ${PLUGIN_NAME} 2>/dev/null || true
docker plugin create ${PLUGIN_NAME} ./$(PLUGIN_DIR)
# load plugin with `latest` tag
docker plugin rm -f ${PLUGIN_NAME_LATEST} 2>/dev/null || true
docker plugin create ${PLUGIN_NAME_LATEST} ./$(PLUGIN_DIR)

$(PLUGIN_DIR): $(GOPATH)/bin/dep *.go Dockerfile
# compile
dep ensure
docker build --no-cache -q -t ${PLUGIN_NAME_ROOTFS} .
# assemble
mkdir -p ./$(PLUGIN_DIR)/rootfs
docker create --name tmp ${PLUGIN_NAME_ROOTFS}
docker export tmp | tar -x -C ./$(PLUGIN_DIR)/rootfs
cp config.json ./$(PLUGIN_DIR)/
docker rm -vf tmp

# Run Integration Tests
# Requires TEST_* Variables to be set
test: test-pre-check \
build \
test-setup \
test-create-volume-50 \
test-rm-volume-50 \
test-create-volume \
test-use-volume \
clean-volumes

test-create-volume:
docker volume create -d libgolang/docker-volume-linode test-volume-default-size

test-create-volume-50:
docker volume create -d libgolang/docker-volume-linode -o size=50 test-volume-50g

test-rm-volume-50:
docker volume rm test-volume-50g

test-use-volume:
docker run --rm -i -v test-volume-default-size:/mnt busybox touch /mnt/abc.txt
docker run --rm -i -v test-volume-default-size:/mnt busybox test -f /mnt/abc.txt || false

test-pre-check:
@if [ "${TEST_TOKEN}" = "xyz" ] || [ "${TEST_REGION}" = "xyz" ] || [ "${TEST_LABEL}" = "xyz" ] ; then \
echo -en "#############################\nYou must set TEST_* Variables\n#############################\n"; exit 1; fi

test-setup:
@docker plugin set libgolang/docker-volume-linode LINODE_TOKEN=${TEST_TOKEN} LINODE_REGION=${TEST_REGION} LINODE_LABEL=${TEST_LABEL}
docker plugin enable libgolang/docker-volume-linode

check: $(GOPATH)/bin/dep
# Tools
go get -u github.com/tsenart/deadcode
go get -u github.com/kisielk/errcheck
go get -u golang.org/x/lint/golint
# Run Code Tests
dep ensure
go vet
errcheck
golint
deadcode

unit-test: $(GOPATH)/bin/dep
dep ensure
go test

$(GOPATH)/bin/dep:
go get -u github.com/golang/dep/cmd/dep

.PHONY clean:
rm -fr $(PLUGIN_DIR)

clean-volumes:
docker volume ls -q | grep 'test-' | xargs docker volume rm
clean-installed-plugins:
docker plugin ls | grep libgolang | grep -v ID | awk '{print $$1}' | xargs docker plugin rm -f

Loading

0 comments on commit 25f32f4

Please sign in to comment.