Skip to content

Commit

Permalink
Extend CI with Docker TCP support
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Jan 13, 2018
1 parent 8d0b89c commit c533fce
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ language: go
go: 1.8.3

before_install:
- sudo cp -v ci_docker_daemon.json /etc/docker/daemon.json
- sudo ln -nfs /bin/bash /bin/sh
- make prepare

install:
- make dep

before_script:
- sudo killall -v dockerd && sudo rm -f /var/run/docker.pid && sudo dockerd 2>&1 | logger -t dockerd &
- git remote set-url --push origin https://${GITHUB_TOKEN}@github.com/ivanilves/lstags.git

script:
Expand All @@ -21,6 +23,12 @@ script:
- make blackbox-integration-test
- make lint
- make vet
- make test-docker-socket
- make test-docker-tcp DOCKER_HOST=tcp://172.17.0.1:2375
- make docker

after_script:
- sudo killall -v dockerd

before_deploy:
- make release
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# NB! This file is a template and might need editing before it works on your project!
#
FROM golang:1.8 AS builder
ENV DOCKER_HOST tcp://172.17.0.1:2375
ENV LOCAL_REGISTRY 172.17.0.1
WORKDIR /go/src/github.com/ivanilves/lstags
COPY . ./
RUN ln -nfs /bin/bash /bin/sh && make assemble
RUN ln -nfs /bin/bash /bin/sh && make all
FROM scratch
# Since we started from scratch, we'll copy following files from the builder:
# * SSL root certificates bundle
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ all: prepare dep test lint vet build

offline: unit-test lint vet build

assemble: prepare dep lint vet build

prepare:
go get -u -v \
github.com/golang/dep/cmd/dep \
Expand Down Expand Up @@ -40,7 +38,8 @@ start-local-registry:
stop-local-registry:
docker rm -f lstags-registry

blackbox-integration-test: build start-local-registry \
blackbox-integration-test: build \
start-local-registry \
shell-test-alpine \
shell-test-wrong-image \
shell-test-pull-public \
Expand Down Expand Up @@ -83,6 +82,13 @@ shell-test-push-local-assumed-tags:
@echo "NB! This should NOT fail, because above we assumed tags 'v1.6.1' and 'v1.7.0' do exist."
./lstags localhost:${REGISTRY_PORT}/qa/calico/cni | egrep "v1\.(6\.1|7\.0)"

test-docker-socket:
unset DOCKER_HOST && ./lstags alpine~/latest/

test-docker-tcp: DOCKER_HOST=tcp://127.0.0.1:2375
test-docker-tcp:
./lstags alpine~/latest/

lint: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i golint {} | tr '`' '|')
lint: fail-on-errors

Expand Down
11 changes: 11 additions & 0 deletions ci_docker_daemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"hosts": [
"unix:///var/run/docker.sock",
"tcp://127.0.0.1:2375",
"tcp://172.17.0.1:2375"
],
"insecure-registries" : [
"127.0.0.1",
"172.17.0.1"
]
}
14 changes: 12 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ import (
"github.com/ivanilves/lstags/tag/remote"
)

func getEnvOrDefault(name, defaultValue string) string {
value := os.Getenv(name)

if value != "" {
return value
}

return defaultValue
}

//
// Here we check the ability to fetch tags from remote registry
//
Expand Down Expand Up @@ -112,8 +122,8 @@ func runTestForPullPush(
const registryContainerName = "lstags-ephemeral-registry"

hostPort := strconv.Itoa(5000 + rand.Intn(1000))
localRegistry := "127.0.0.1:" + hostPort
localPortSpec := localRegistry + ":5000"
localRegistry := getEnvOrDefault("LOCAL_REGISTRY", "127.0.0.1") + ":" + hostPort
localPortSpec := "0.0.0.0:" + hostPort + ":5000"

dockerConfig, err := dockerconfig.Load(dockerJSON)
if err != nil {
Expand Down

0 comments on commit c533fce

Please sign in to comment.