Skip to content

Commit 5af635a

Browse files
authored
CI: Automated build/release workflow (#46)
TLDR; Run "make help" for options. * gofmt * .gitignore kube-router binary * Docs: build/release workflow * Implement build/release workflow
1 parent d782e89 commit 5af635a

File tree

13 files changed

+379
-39
lines changed

13 files changed

+379
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/kube-router

.goreleaser.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
builds:
2+
- goos:
3+
- linux
4+
goarch:
5+
- amd64
6+
env:
7+
- CGO_ENABLED=0
8+
archive:
9+
format: tar.gz
10+
name_template: '{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{
11+
.Arm }}{{ end }}'
12+
files:
13+
- LICENSE*
14+
- README*
15+
- CHANGELOG*
16+
- Documentation*
17+
snapshot:
18+
name_template: SNAPSHOT-{{ .Commit }}

.travis.yml

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,46 @@ services:
22
- docker
33

44
language: go
5-
go:
5+
go:
66
- 1.7.x
77

88
env:
9-
- REPO=cloudnativelabs/kube-router
10-
after_success:
11-
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
12-
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "master"; else echo $TRAVIS_BRANCH ; fi`
13-
- docker build -f Dockerfile -t "$REPO":"$TRAVIS_COMMIT" .
14-
- docker tag "$REPO":"$TRAVIS_COMMIT" "$REPO":"$TAG"
15-
- if [ ! -z ${TRAVIS_TAG+x} ]; then
16-
docker tag "$REPO":"$TRAVIS_COMMIT" "$REPO":"$TRAVIS_TAG";
17-
docker tag "$REPO":"$TRAVIS_COMMIT" "$REPO":"latest";
18-
fi
19-
- docker push "$REPO"
20-
9+
global:
10+
- IMG_FQDN=quay.io
11+
- REPO=cloudnativelabs/kube-router
12+
- REPO_PATH=$HOME/gopath/src/github.com/$REPO
13+
2114
script:
22-
- make all
15+
- make all
16+
17+
after_success:
18+
# All successfully built commits get an image placed in the kube-router-git
19+
# 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
40+
41+
# This fixes issues when a contributor uses their own Travis CI account to test
42+
# code/CI changes.
43+
before_install:
44+
- mkdir -p $REPO_PATH
45+
- rsync -az ${TRAVIS_BUILD_DIR}/ $REPO_PATH
46+
- export TRAVIS_BUILD_DIR=$REPO_PATH
47+
- cd $REPO_PATH

CONTRIBUTING.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Please read [users guide](./Documentation/README.md#user-guide) and [developers
1111

1212
If you have a question about Kube-router or have a problem using it, please start with contacting us on [community forum](https://gitter.im/kube-router/Lobby) for quick help. If that doesn't answer your questions, or if you think you found a bug, please [file an issue](https://github.com/cloudnativelabs/kube-router/issues).
1313

14-
## Submit PR
14+
## Contributing Changes
1515

1616
### Fork the code
1717

18-
Navigate to: [https://github.com/cloudnativelabs/kube-router](https://github.com/cloudnativelabs/kube-router) fork the repository.
18+
Navigate to:
19+
[https://github.com/cloudnativelabs/kube-router](https://github.com/cloudnativelabs/kube-router)
20+
and fork the repository.
1921

2022
Follow these steps to setup a local repository for working on Kube-router:
2123

@@ -28,7 +30,7 @@ $ git fetch upstream
2830
$ git rebase upstream/master
2931
```
3032

31-
### Making changes and raising PR
33+
### Creating A Feature Branch
3234

3335
Create a new branch to make changes on and that branch.
3436

@@ -51,6 +53,8 @@ $ git rebase master
5153

5254
Now your `feature_x` branch is up-to-date with all the code in `upstream/master`, so push to your fork
5355

56+
### Performing A Pull Request
57+
5458
``` bash
5559
$ git push origin master
5660
$ git push origin feature_x

Documentation/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,6 @@ To enable hairpin traffic for Service `my-service`:
176176
kubectl annotate service my-service 'kube-router.io/hairpin-mode='
177177
```
178178

179-
## Develope Guide
180-
181-
**Go version 1.7 or above is required to build kube-router**
182-
183-
All the dependencies are vendored already, so just run *make build* or *go build -o kube-router kube-router.go* to build
184-
185-
Alternatively you can download the prebuilt binary from https://github.com/cloudnativelabs/kube-router/releases
186179

187180
## BGP configuration
188181

Documentation/developing.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Developer's Guide
2+
3+
We aim to make local development and testing as straightforward as possible. For
4+
basic guidelines around contributing, see the [CONTRIBUTING](/CONTRIBUTING.md) document.
5+
6+
There are a number of automation tools available to help with testing and
7+
building your changes, detailed below.
8+
9+
## Building kube-router
10+
11+
**Go version 1.7 or above is required to build kube-router**
12+
13+
All the dependencies are vendored already, so just run `make` or `go build -o kube-router kube-router.go` to build.
14+
15+
### Building A Docker Image
16+
17+
Running `make container` will compile kube-router (if needed) and build a Docker
18+
image. By default the container will be tagged with the last release version,
19+
and current commit ID.
20+
21+
For example:
22+
```console
23+
$ make container
24+
docker build -t "cloudnativelabs/kube-router-git:0.0.4-22-gd782e89-dirty-build-release"
25+
Sending build context to Docker daemon 151.5MB
26+
Step 1/4 : FROM alpine
27+
---> a41a7446062d
28+
Step 2/4 : RUN apk add --no-cache iptables ipset
29+
---> Using cache
30+
---> 30e25a7640de
31+
Step 3/4 : COPY kube-router /
32+
---> Using cache
33+
---> c06f78fd02e8
34+
Step 4/4 : ENTRYPOINT /kube-router
35+
---> Using cache
36+
---> 5cfcfe54623e
37+
Successfully built 5cfcfe54623e
38+
Successfully tagged cloudnativelabs/kube-router-git:0.0.4-22-gd782e89-dirty-build-release
39+
```
40+
41+
The `-dirty` part of the tag means there are uncommitted changes in your local
42+
git repo.
43+
44+
### Pushing A Docker Image
45+
46+
Running `make push` will push your container image to a Docker registry. The
47+
default configuration will use the Docker Hub repository for the official
48+
kube-router images, cloudnativelabs/kube-router. You can push to a different
49+
repository by changing a couple settings, as described in [Image Options](#image-options)
50+
below.
51+
52+
### Makefile Options
53+
54+
There are several variables which can be modified in the Makefile to customize
55+
your builds. They are specified after your make command like this: `make OPTION=VALUE`.
56+
These options can also be set in your environment variables.
57+
For more details beyond the scope of this document, see the
58+
[Makefile](/Makefile) and run `make help`.
59+
60+
#### Image Options
61+
62+
You can configure the name and tag of the Docker image with a few variables
63+
passed to `make container` and `make push`.
64+
65+
Example:
66+
```console
67+
$ make container IMG_FQDN=quay.io IMG_NAMESPACE=bzub IMAGE_TAG=custom
68+
docker build -t "quay.io/bzub/kube-router-git:custom" .
69+
Sending build context to Docker daemon 151.5MB
70+
Step 1/4 : FROM alpine
71+
---> a41a7446062d
72+
Step 2/4 : RUN apk add --no-cache iptables ipset
73+
---> Using cache
74+
---> 30e25a7640de
75+
Step 3/4 : COPY kube-router /
76+
---> Using cache
77+
---> c06f78fd02e8
78+
Step 4/4 : ENTRYPOINT /kube-router
79+
---> Using cache
80+
---> 5cfcfe54623e
81+
Successfully built 5cfcfe54623e
82+
Successfully tagged quay.io/bzub/kube-router-git:custom
83+
```
84+
85+
- `REGISTRY` is derived from other options. Set this to something else to
86+
quickly override the Docker image registry used to tag and push images.
87+
- Note: This will override other variables below that make up the image
88+
name/tag.
89+
- `IMG_FQDN` should be set if you are not using Docker Hub for images. In
90+
the examples above `IMG_FQDN` is set to `quay.io`.
91+
- `IMG_NAMESPACE` is the Docker registry user or organization. It is used in
92+
URLs.
93+
- Example: quay.io/IMG_NAMESPACE/kube-router
94+
- `NAME` goes onto the end of the Docker registry URL that will be used.
95+
- Example: quay.io/cloudnativelabs/NAME
96+
- `IMAGE_TAG` is used to override the tag of the Docker image being built.
97+
- `DEV_SUFFIX` is appended to Docker image names that are not for release. By
98+
default these images get a name ending with `-git` to signify that they are
99+
for testing purposes.
100+
Example (DEV-SUFFIX=master-latest): quay.io/cloudnativelabs/kube-router-git:master-latest
101+
102+
## Release Workflow
103+
104+
These instructions show how official kube-router releases are performed.
105+
106+
First, you must tag a git commit with the release version.
107+
This will cause the CI system to:
108+
- Build kube-router
109+
- Build a Docker image with ${VERSION} and `latest` tags
110+
- Push the Docker image to the official registry
111+
- Submits a draft release to GitHub
112+
113+
Example:
114+
```
115+
VERSION=v0.5.0
116+
git tag -a ${VERSION} -m "Brief release note" && git push origin ${VERSION}
117+
```
118+
119+
Then the only thing left to do is edit the release notes on the GitHub release
120+
and publish it.
121+
122+
### Manual Releases
123+
124+
These instructions show how To perform a custom or test release outside of the
125+
CI system, using a local git commit.
126+
127+
First tag a commit:
128+
```
129+
VERSION=v0.5.0_bzub
130+
git tag -a ${VERSION} -m "Brief release note"
131+
```
132+
133+
Then you can provide
134+
[options](#makefile-options) to `make release`.
135+
136+
This does the following:
137+
- Builds kube-router
138+
- Builds a Docker image
139+
- Tags the image with the current git commit's tag
140+
- Tags the image with `latest`
141+
- Pushes the image to a docker registry
142+
143+
If you'd like to test the GitHub release functionality as well, you will need to
144+
pass in the `GITHUB_TOKEN` variable with a value of an API token you've
145+
[generated](https://github.com/settings/tokens/new). This Access Token must have
146+
the "repo" OAuth scope enabled.
147+
148+
NOTE: For added security when running a command that contains secure
149+
credentials, add a space before the entire command to prevent it from being
150+
added to your shell history file.
151+
152+
Example:
153+
```console
154+
$ make release IMG_FQDN=quay.io IMG_NAMESPACE=bzub GITHUB_TOKEN=b1ahbl1ahb1ahba1hahb1ah
155+
```

0 commit comments

Comments
 (0)