Skip to content

Commit

Permalink
Implement Support for Travis CI/CD (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
goruha authored and osterman committed Dec 13, 2016
1 parent 8966482 commit 939cec2
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 35 deletions.
63 changes: 63 additions & 0 deletions .travis.yml
@@ -0,0 +1,63 @@
sudo: required
env:
- DOCKER_IMAGE_NAME=cloudposse/github-authorized-keys
services:
- docker
install:
- |-
docker login \
--email="$DOCKER_HUB_EMAIL" \
--username="$DOCKER_HUB_USERNAME" \
--password="$DOCKER_HUB_PASSWORD"
- pip install docker-compose

script:
- |-
export ETCD_IP=$(ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')
- docker-compose -f docker-compose-test.yaml up -d

- |-
docker build --tag test \
--build-arg RUN_TESTS=1 \
--build-arg TEST_GITHUB_API_TOKEN=${GITHUB_API_TOKEN} \
--build-arg TEST_GITHUB_ORGANIZATION=${GITHUB_ORGANIZATION} \
--build-arg TEST_GITHUB_TEAM=${GITHUB_TEAM} \
--build-arg TEST_GITHUB_TEAM_ID=${GITHUB_TEAM_ID} \
--build-arg TEST_GITHUB_USER=${GITHUB_USER} \
--build-arg TEST_ETCD_ENDPOINT=http://${ETCD_IP}:2379 \
./
after_success:
- docker build -t $DOCKER_IMAGE_NAME .

- |-
if [ ! -z "$TRAVIS_TAG" ]; then \
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$TRAVIS_TAG && \
docker push $DOCKER_IMAGE_NAME:$TRAVIS_TAG; \
fi
- |-
if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then \
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:pr-$TRAVIS_PULL_REQUEST_BRANCH && \
docker push $DOCKER_IMAGE_NAME:pr-$TRAVIS_PULL_REQUEST_BRANCH; \
fi
- |-
if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" && ! -z "$TRAVIS_BRANCH" ]]; then \
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$TRAVIS_BRANCH && \
docker push $DOCKER_IMAGE_NAME:$TRAVIS_BRANCH; \
fi
- |-
if [[ -z "$TRAVIS_TAG" && -z "$TRAVIS_PULL_REQUEST_BRANCH" && -z "$TRAVIS_BRANCH" ]]; then \
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest && \
docker push $DOCKER_IMAGE_NAME:latest; \
fi
- |-
if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]] && [[ "$TRAVIS_BRANCH" == "master" ]]; then \
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest && \
docker push $DOCKER_IMAGE_NAME:latest; \
fi
16 changes: 8 additions & 8 deletions Dockerfile
Expand Up @@ -5,12 +5,12 @@ COPY ./ /go/src/github.com/cloudposse/github-authorized-keys
WORKDIR /go/src/github.com/cloudposse/github-authorized-keys

ARG RUN_TESTS=0
ARG TEST_GITHUB_API_TOKEN=
ARG TEST_GITHUB_ORGANIZATION=
ARG TEST_GITHUB_TEAM=
ARG TEST_GITHUB_TEAM_ID=
ARG TEST_GITHUB_USER=
ARG TEST_ETCD_ENDPOINT=
ARG TEST_GITHUB_API_TOKEN
ARG TEST_GITHUB_ORGANIZATION
ARG TEST_GITHUB_TEAM
ARG TEST_GITHUB_TEAM_ID
ARG TEST_GITHUB_USER
ARG TEST_ETCD_ENDPOINT

# We do tests on alpine so use alpine adduser flags

Expand All @@ -28,7 +28,7 @@ RUN set -ex \
curl \
&& curl https://glide.sh/get | sh \
&& make deps \
&& if [ $RUN_TESTS -eq 1 ]; then make test ; fi \
&& ( [[ $RUN_TESTS -eq 0 ]] || make test; ) \
&& go-wrapper install \
&& rm -rf /go/src \
&& apk del .build-deps
Expand Down Expand Up @@ -70,4 +70,4 @@ ENV LISTEN=":301"
# For production we run container with host network, so expose is just for testing and CI\CD
EXPOSE 301

ENTRYPOINT ["github-authorized-keys"]
ENTRYPOINT ["github-authorized-keys"]
7 changes: 1 addition & 6 deletions Makefile
Expand Up @@ -18,12 +18,7 @@ build: $(GO)
.PHONY: test
## Run tests
test: $(GO)
## Find tests in all dirs expect vendor dir and dirs starts from . ##
## Convert local dir path to package absolute name ##
## Run tests ##
find ! -path "\./\.*" ! -path "\./vendor*" -type d | \
sed -e "s|.|github.com/cloudposse/github-authorized-keys/|" | \
xargs -n 1 $(GO) test -v
$(GO) test $(shell $(GO) list ./... | grep -v /vendor/)

.PHONY: deps
## Install dependencies
Expand Down
15 changes: 9 additions & 6 deletions README.md
@@ -1,4 +1,4 @@
# Github Authorized Keys
# Github Authorized Keys [![Build Status](https://travis-ci.org/cloudposse/github-authorized-keys.svg?branch=master)](https://travis-ci.org/cloudposse/github-authorized-keys)

Use GitHub teams to manage system user accounts and authorized_keys

Expand Down Expand Up @@ -91,10 +91,12 @@ After installation you could find command as

#### Use in containers

Build docker image
Use public image [cloudposse/github-authorized-keys](https://hub.docker.com/r/cloudposse/github-authorized-keys/)

or build docker image from source

```
docker build -t github-authorized-keys .
docker build -t cloudposse/github-authorized-keys .
```

### Start
Expand Down Expand Up @@ -139,7 +141,7 @@ ETCD_TTL={etcd ttl - default 1 day} \
ETCD_PREFIX={prefix or path to store data - default /github-authorized-keys} \
LISTEN={Sets the address and port for IP, default :301} \
INTEGRATE_SSH={integrate with ssh on startup, default false (should be true for production)} \
/usr/local/sbin/github-authorized-keys authorize {user}
/usr/local/sbin/github-authorized-keys
```

or you can mix that approaches
Expand All @@ -165,7 +167,7 @@ docker run \
-e ETCD_PREFIX={prefix or path to store data - default /github-authorized-keys} \
-e LISTEN={Sets the address and port for IP, default :301} \
-e INTEGRATE_SSH={integrate with ssh on startup, default false (should be true for production)} \
github-authorized-keys
cloudposse/github-authorized-keys
```

or as flags
Expand All @@ -174,7 +176,7 @@ or as flags
docker run \
-v /:/{root directory} \
--expose "301:301"
github-authorized-keys
cloudposse/github-authorized-keys
--github-api-token={token} \
--github-organization={organization} \
--github-team={team} \
Expand Down Expand Up @@ -429,6 +431,7 @@ docker build \
--build-arg TEST_GITHUB_TEAM_ID={team_id} \
--build-arg TEST_GITHUB_USER={user} \
--build-arg TEST_ETCD_ENDPOINT={etcd endpoints comma separeted - optional}
./
```

---
Expand Down
16 changes: 4 additions & 12 deletions api/github.go
Expand Up @@ -26,18 +26,10 @@ import (
)

// Naive oauth setup

type accessToken struct {
token *oauth2.Token
}

func (a accessToken) Token() (*oauth2.Token, error) {
return a.token, nil
}

func newAccessToken(token string) accessToken {
t := oauth2.Token{AccessToken: token}
return accessToken{token: &t}
func newAccessToken(token string) oauth2.TokenSource {
return oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
}

// GithubClient - client for operate with Github API
Expand Down
2 changes: 1 addition & 1 deletion api/linux_files_test.go
Expand Up @@ -330,7 +330,7 @@ RIGHT CONTENT`))
linux.FileGet("/tmp/zzz")

Expect(err).NotTo(BeNil())
Expect(err.Error()).To(Equal("Match regexp /.*/ is too wide - [RIGHT CONTENT23 RIGHT CONTENT] matches found."))
Expect(err.Error()).To(Equal("Match regexp /.*/ is too wide - [RIGHT CONTENT23 RIGHT CONTENT] matches found"))
})
})

Expand Down
14 changes: 14 additions & 0 deletions docker-compose-test.yaml
@@ -0,0 +1,14 @@
version: '2'

services:
etcd:
image: quay.io/coreos/etcd:v2.3.7
command:
- "--advertise-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001"
- "--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001"
ports:
- "2379:2379"
- "2380:2380"
- "4001:4001"
- "7001:7001"
restart: always
4 changes: 2 additions & 2 deletions glide.yaml
Expand Up @@ -12,6 +12,8 @@ import:
- github
- package: golang.org/x/oauth2
version: f6093e37b6cb4092101a298aba5d794eb570757f
- package: github.com/spf13/pflag
version: 5ccb023bc27df288a957c5e994cd44fd19619465
- package: github.com/spf13/cobra
version: 9495bc009a56819bdb0ddbc1a373e29c140bc674
subpackages:
Expand Down Expand Up @@ -39,5 +41,3 @@ testImport:
- ginkgo
- package: github.com/onsi/gomega
version: f1f0f388b31eca4e2cbe7a6dd8a3a1dfddda5b1c
- package: github.com/jarcoal/httpmock
version: 145b10d659265440f062c31ea15326166bae56ee

0 comments on commit 939cec2

Please sign in to comment.