|
| 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