Skip to content

Commit db54caf

Browse files
authored
CI: Bug fixes, one image per PR (#47)
* One image per PR * Don't use Travis deploys * Fix if statement in YAML
1 parent 5af635a commit db54caf

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

.travis.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,22 @@ language: go
55
go:
66
- 1.7.x
77

8+
branches:
9+
only:
10+
- master
11+
- v0.*
12+
813
env:
914
global:
10-
- IMG_FQDN=quay.io
1115
- REPO=cloudnativelabs/kube-router
1216
- REPO_PATH=$HOME/gopath/src/github.com/$REPO
17+
- GIT_BRANCH=$TRAVIS_BRANCH
18+
- IMG_FQDN=quay.io
1319

1420
script:
15-
- make all
16-
17-
after_success:
1821
# All successfully built commits get an image placed in the kube-router-git
1922
# image repo and tagged with the commit hash.
20-
- make push
21-
22-
deploy:
23-
# Images from Pull Requests get tagged with the PR number.
24-
- provider: script
25-
on:
26-
condition: $TRAVIS_PULL_REQUEST != "false"
27-
skip_cleanup: true
28-
script:
29-
- make push IMG_PREFIX=PR$TRAVIS_PULL_REQUEST-
30-
31-
# Images from tagged commits get released.
32-
- provider: script
33-
on:
34-
tags: true
35-
# condition: $TRAVIS_PULL_REQUEST == "false"
36-
skip_cleanup: true
37-
script:
38-
- unset IMG_FQDN # Use DockerHub for releases
39-
- make release
23+
- build/travis-deploy.sh
4024

4125
# This fixes issues when a contributor uses their own Travis CI account to test
4226
# code/CI changes.

Makefile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ NAME?=kube-router
22
DEV_SUFFIX?=-git
33
LOCAL_PACKAGES?=app app/controllers app/options app/watchers
44
IMG_NAMESPACE?=cloudnativelabs
5-
IMG_TAG?=$(shell git describe --tags --dirty)
6-
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
5+
GIT_COMMIT=$(shell git describe --tags --dirty)
6+
IMG_TAG?=$(if $(IMG_TAG_PREFIX),$(IMG_TAG_PREFIX)-)
7+
# GIT_BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
78
RELEASE_TAG?=$(shell build/get-git-tag.sh)
89
REGISTRY?=$(if $(IMG_FQDN),$(IMG_FQDN)/$(IMG_NAMESPACE)/$(NAME),$(IMG_NAMESPACE)/$(NAME))
910
REGISTRY_DEV?=$(REGISTRY)$(DEV_SUFFIX)
@@ -16,41 +17,57 @@ UPSTREAM_IMPORT_PATH=$(GOPATH)/src/github.com/cloudnativelabs/kube-router/
1617
all: test kube-router container ## Default target. Runs tests, builds binaries and images.
1718

1819
kube-router: $(shell find . -name \*.go) ## Builds kube-router.
20+
@echo Starting kube-router binary build.
1921
CGO_ENABLED=0 go build -o kube-router kube-router.go
22+
@echo Finished kube-router binary build.
2023

2124
test: gofmt ## Runs code quality pipelines (gofmt, tests, coverage, lint, etc)
2225

2326
run: kube-router ## Runs "kube-router --help".
2427
./kube-router --help
2528

2629
container: kube-router ## Builds a Docker container image.
27-
$(DOCKER) build -t "$(REGISTRY_DEV):$(IMG_PREFIX)$(IMG_TAG)" .
28-
29-
docker-login:
30-
@if [ -z "$(NO_DOCKER_LOGIN)" ]; then \
30+
@echo Starting kube-router container image build.
31+
$(DOCKER) build -t "$(REGISTRY_DEV):$(IMG_TAG)" .
32+
@echo Finished kube-router container image build.
33+
34+
docker-login: ## Logs into a docker registry using {DOCKER,QUAY}_{USERNAME,PASSWORD} variables.
35+
@echo Starting docker login target.
36+
@if [ -n "$(DOCKER_USERNAME)" ] && [ -n "$(DOCKER_PASSWORD)" ]; then \
37+
echo Starting DockerHub registry login.; \
3138
$(DOCKER) login -u="$(value DOCKER_USERNAME)" -p="$(value DOCKER_PASSWORD)"; \
39+
echo Finished DockerHub registry login.; \
3240
fi
3341

34-
@if [ -z "$(NO_QUAY_LOGIN)" ]; then \
42+
@if [ -n "$(QUAY_USERNAME)" ] && [ -n "$(QUAY_PASSWORD)" ]; then \
43+
echo Starting quay.io registry login.; \
3544
$(DOCKER) login -u="$(value QUAY_USERNAME)" -p="$(value QUAY_PASSWORD)" quay.io; \
45+
echo Finished quay.io registry login.; \
3646
fi
47+
@echo Finished docker login target.
3748

3849
push: container docker-login ## Pushes a Docker container image to a registry.
39-
$(DOCKER) tag "$(REGISTRY_DEV):$(IMG_TAG)" "$(REGISTRY_DEV):$(GIT_BRANCH)-latest"
50+
@echo Starting kube-router container image push.
4051
$(DOCKER) push "$(REGISTRY_DEV)"
52+
@echo Finished kube-router container image push.
4153

4254
push-release: push
55+
@echo Starting kube-router release container image push.
4356
@test -n "$(RELEASE_TAG)"
4457
$(DOCKER) tag "$(REGISTRY_DEV):$(IMG_TAG)" "$(REGISTRY):$(RELEASE_TAG)"
4558
$(DOCKER) tag "$(REGISTRY):$(RELEASE_TAG)" "$(REGISTRY):latest"
4659
$(DOCKER) push "$(REGISTRY)"
60+
@echo Finished kube-router release container image push.
4761

4862
github-release: kube-router
63+
@echo Starting kube-router GitHub release creation.
4964
@[ -n "$(value GITHUB_TOKEN)" ] && \
5065
GITHUB_TOKEN=$(value GITHUB_TOKEN); \
5166
curl -sL https://git.io/goreleaser | bash
67+
@echo Finished kube-router GitHub release creation.
5268

5369
release: push-release github-release ## Pushes a release to DockerHub and GitHub
70+
@echo Finished kube-router release target.
5471

5572
clean: ## Removes the kube-router binary and Docker images
5673
rm -f kube-router

build/travis-deploy.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o pipefail
4+
5+
# Pull Request image tag format: PR00-PRUSER
6+
if [ "${TRAVIS_EVENT_TYPE}" = "pull_request" ]; then
7+
PR_USER=$(echo "$TRAVIS_PULL_REQUEST_SLUG" | sed -e 's/\/.*//')
8+
echo "Building/pushing PR$TRAVIS_PULL_REQUEST from $PR_USER"
9+
make push IMG_TAG="PR$TRAVIS_PULL_REQUEST-$PR_USER"
10+
exit 0
11+
fi
12+
13+
# Release image tag format: v0.0.0 and latest
14+
if [ -n "$TRAVIS_TAG" ]; then
15+
echo "Running Release build on Travis"
16+
make release RELEASE_TAG="$TRAVIS_TAG"
17+
exit 0
18+
fi
19+
20+
# Push image tag format: COMMIT
21+
echo "Running push build on Travis"
22+
make push

build/verify-gofmt.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env bash
2-
32
set -o errexit
43
set -o nounset
54
set -o pipefail
@@ -22,4 +21,6 @@ if [[ -n "${bad_files}" ]]; then
2221
echo "or"
2322
echo "Run \"${GOFMT} -w\" on each file."
2423
exit 1
24+
else
25+
echo 'Everything is gofmt approved!'
2526
fi

0 commit comments

Comments
 (0)