Skip to content

Commit

Permalink
Simplify and document the build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
Flynn committed Apr 26, 2017
1 parent a6c65f1 commit c6df70f
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
current_version = 0.5.1
commit = True
tag = True
commit = False
tag = False
tag_name = v{new_version}

[bumpversion:file:ambassador-rest.yaml]
Expand Down
55 changes: 55 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Building Ambassador
===================

If you just want to **use** Ambassador, check out the [README.md](README.md)! You don't need to build anything.

If you really want to customize Ambassador, though, read on -- but **NOTE WELL**! This process will change soon.

You'll need the following:

- bash
- make
- docker
- Python 3
- [bump2version](https://pypi.python.org/pypi/bump2version)

(Honestly, you only need Python for `bump2version`.)

Normal Workflow
===============

0. `export DOCKER_REGISTRY=$registry`

This sets the registry to which to push Docker images and is **mandatory** if you're not using Minikube. The `$registry` info should be the prefix for `docker push`:

"dwflynn" will push to Dockerhub with user `dwflynn`
"gcr.io/flynn" will push to GCR with user `flynn`

You can separately tweak the registry from which images will be _pulled_ using `AMBASSADOR_REGISTRY` and `STATSD_REGISTRY`. See the files in `templates` for more here.

1. Make changes. Commit.

Hopefully this step is clear.

2. `make new-$level`

This will correctly set the version number everywhere, then build (and probably push) Docker images, then build YAML files for you. IT WILL NOT COMMIT OR TAG.

`$level` must be one of "major", "minor", or "patch", using [semantic versioning](http://semver.org/):

"major" is for major breaking changes.
"minor" is for new functionality that's still backward compatible.
"patch" is for bug fixes.

(You can do "make artifacts" if you want to rebuild artifacts but not change the version, even though that's likely to not be a great idea.)

3. `make tag`

Do this once you're happy with everything. It will commit (if need be) and then create and push a Git tag for your version.

What if I Don't Want to Push My Images?
---------------------------------------

**NOTE WELL**: if you're not using Minikube, this is almost certainly a mistake.

But suppose you are using Minikube. The Makefile (deliberately) requires you to set DOCKER_REGISTRY, so you can't just unset it -- instead, set it to "-" to prevent any pushes.
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
all: docker-images ambassador.yaml statsd-sink.yaml
all: bump

VERSION=0.5.1

.ALWAYS:

default: docker-images ambassador.yaml statsd-sink.yaml

bump:
@if [ -z "$$LEVEL" ]; then \
echo "LEVEL must be set" >&2 ;\
exit 1 ;\
fi

@if [ -z "$$DOCKER_REGISTRY" ]; then \
echo "DOCKER_REGISTRY must be set" >&2 ;\
exit 1 ;\
fi

@echo "Bumping to new $$LEVEL version..."
bump2version --no-tag --no-commit "$$LEVEL"

new-patch:
$(MAKE) bump default LEVEL=patch

new-minor:
$(MAKE) bump default LEVEL=minor

new-major:
$(MAKE) bump default LEVEL=major

ambassador-sds.yaml: .ALWAYS
sh templates/ambassador-sds.yaml.sh > ambassador-sds.yaml

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ To get rid of the mapping, use

Read on for more details.

Building Ambassador
===================

If you just want to **use** Ambassador, read on! You don't need to build anything.

If you really want to customize Ambassador, though, check out [BUILDING.md](BUILDING.md) for the lowdown.

Running Ambassador
==================

Expand Down
4 changes: 2 additions & 2 deletions ambassador-rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: ambassador
image: ark3/ambassador:0.5.1
image: dwflynn/ambassador:0.5.1
# ports:
# - containerPort: 80
# protocol: TCP
Expand All @@ -25,7 +25,7 @@ spec:
- mountPath: /etc/certs
name: cert-data
- name: statsd
image: ark3/statsd:0.5.1
image: dwflynn/statsd:0.5.1
resources: {}
volumes:
- name: cert-data
Expand Down
4 changes: 2 additions & 2 deletions ambassador.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ spec:
spec:
containers:
- name: ambassador
image: ark3/ambassador:0.5.1
image: dwflynn/ambassador:0.5.1
# ports:
# - containerPort: 80
# protocol: TCP
Expand All @@ -98,7 +98,7 @@ spec:
- mountPath: /etc/certs
name: cert-data
- name: statsd
image: ark3/statsd:0.5.1
image: dwflynn/statsd:0.5.1
resources: {}
volumes:
- name: cert-data
Expand Down
15 changes: 8 additions & 7 deletions scripts/docker_build_maybe_push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e

# If DOCKER_REGISTRY is set, use that as the namespace for the build,
# then push to Docker Hub. Otherwise use the specified namespace to
Expand All @@ -9,9 +9,10 @@ NAME="$2"
VERSION="$3"
TARGET="$4"

if [ -n "${DOCKER_REGISTRY}" ]; then
docker build -t "${DOCKER_REGISTRY}/${NAME}:${VERSION}" "${TARGET}"
docker push "${DOCKER_REGISTRY}/${NAME}:${VERSION}"
else
docker build -t "${DEFAULT_NAMESPACE}/${NAME}:${VERSION}" "${TARGET}"
fi
HERE=$(dirname $0)
eval $(sh $HERE/get_registries.sh)

if [ -z "${DOCKER_REGISTRY}" ]; then exit 1; fi

docker build -t "${DOCKER_REGISTRY}${NAME}:${VERSION}" "${TARGET}"
docker push "${DOCKER_REGISTRY}${NAME}:${VERSION}"
37 changes: 37 additions & 0 deletions scripts/get_registries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

slashify () {
thing="$1"

if [ -n "$thing" ]; then
case "$thing" in
*/) ;;
*) thing="$thing/"
esac
fi

echo "$thing"
}

if [ -z "${DOCKER_REGISTRY}" ]; then
echo "DOCKER_REGISTRY must be set" >&2
exit 1
fi

if [ "$DOCKER_REGISTRY" == "-" ]; then
unset DOCKER_REGISTRY
fi

DOCKER_REGISTRY=$(slashify "$DOCKER_REGISTRY")

# Default to using DOCKER_REGISTRY, but allow overriding.
AMREG=$(slashify "${AMBASSADOR_REGISTRY:-$DOCKER_REGISTRY}")

# Default to using DOCKER_REGISTRY, but allow overriding.
STREG=$(slashify "${STATSD_REGISTRY:-$DOCKER_REGISTRY}")

cat <<EOF
export DOCKER_REGISTRY="$DOCKER_REGISTRY"
export AMREG="$AMREG"
export STREG="$STREG"
EOF
2 changes: 1 addition & 1 deletion statsd-sink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
spec:
containers:
- name: statsd-sink
image: ark3/prom-statsd-exporter:0.5.1
image: dwflynn/prom-statsd-exporter:0.5.1
resources: {}
restartPolicy: Always
status: {}
Expand Down
16 changes: 7 additions & 9 deletions templates/ambassador-rest.yaml.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
if [ -z "${DOCKER_REGISTRY}" ]; then
AMREG=dwflynn
STREG=ark3
else
AMREG="${DOCKER_REGISTRY}"
STREG="${DOCKER_REGISTRY}"
fi
HERE=$(dirname $0)
eval $(sh $HERE/../scripts/get_registries.sh)

if [ -z "${DOCKER_REGISTRY}" ]; then exit 1; fi

cat <<EOF
---
apiVersion: extensions/v1beta1
Expand All @@ -24,7 +22,7 @@ spec:
spec:
containers:
- name: ambassador
image: ${AMREG}/ambassador:0.5.1
image: ${AMREG}ambassador:0.5.1
# ports:
# - containerPort: 80
# protocol: TCP
Expand All @@ -33,7 +31,7 @@ spec:
- mountPath: /etc/certs
name: cert-data
- name: statsd
image: ${STREG}/statsd:0.5.1
image: ${STREG}statsd:0.5.1
resources: {}
volumes:
- name: cert-data
Expand Down
10 changes: 6 additions & 4 deletions templates/ambassador-sds.yaml.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
if [ -z "${DOCKER_REGISTRY}" ]; then
DOCKER_REGISTRY=dwflynn
fi
HERE=$(dirname $0)
eval $(sh $HERE/../scripts/get_registries.sh)

if [ -z "${DOCKER_REGISTRY}" ]; then exit 1; fi

cat <<EOF
---
apiVersion: extensions/v1beta1
Expand All @@ -19,7 +21,7 @@ spec:
spec:
containers:
- name: ambassador-sds
image: ${DOCKER_REGISTRY}/ambassador-sds:0.5.1
image: ${AMREG}ambassador-sds:0.5.1
resources: {}
restartPolicy: Always
status: {}
Expand Down
10 changes: 6 additions & 4 deletions templates/statsd-sink.yaml.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
if [ -z "${DOCKER_REGISTRY}" ]; then
DOCKER_REGISTRY=ark3
fi
HERE=$(dirname $0)
eval $(sh $HERE/../scripts/get_registries.sh)

if [ -z "${DOCKER_REGISTRY}" ]; then exit 1; fi

cat <<EOF
---
apiVersion: extensions/v1beta1
Expand All @@ -19,7 +21,7 @@ spec:
spec:
containers:
- name: statsd-sink
image: ${DOCKER_REGISTRY}/prom-statsd-exporter:0.5.1
image: ${STREG}prom-statsd-exporter:0.5.1
resources: {}
restartPolicy: Always
status: {}
Expand Down

0 comments on commit c6df70f

Please sign in to comment.