Skip to content

Instantly share code, notes, and snippets.

@subfuzion
Last active July 31, 2017 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subfuzion/7c0a9e5fb0aca3cc1b89d43a7f07352f to your computer and use it in GitHub Desktop.
Save subfuzion/7c0a9e5fb0aca3cc1b89d43a7f07352f to your computer and use it in GitHub Desktop.
amp makefile

This is a simplified makefile for making it easy to to rebuild whatever needs rebuilding when touching any of the protocol buffer files or other source files for either the server or the cli.

For convenience, I use an alias:

$ alias m="make -f amp.makefile"

Then I just invoke m to make all, and then m deploy to update the stack, then restart logs in another terminal (docker service logs -f amplifier_amplifier).

The deploy rule depends on stacksamples/amplifier-lite.yml under cluster/agent, and disables registration and notifications. It uses configs and secrets stored under cluster/agent/defaults, but registration and notifications are overridden by environment variables in the compose file. Note that the deploy rule ensures that the current version from the repo's VERSION file is supplied as the image TAG to the compose file.

.PHONY: cleancli rebuildcli cleanserver rebuildserver cleanall rebuildall deploy
export VERSION := $(shell cat VERSION)
export BUILD := $(shell git rev-parse HEAD | cut -c1-8)
export LDFLAGS := "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD)"
export OWNER := appcelerator
export REPO := github.com/$(OWNER)/amp
VENDOR := vendor
COMMONDIRS := pkg
# ===============================================
# general
# ===============================================
all: protoc server cli
cleanall: cleanserver cleancli
rebuildall: rebuildserver rebuildcli
build: all
# ===============================================
# protocol buffers
# ===============================================
PROTODIRS := api cmd data tests $(COMMONDIRS)
PROTOFILES := $(shell find $(PROTODIRS) -type f -name '*.proto')
PROTOTARGETS := $(PROTOFILES:.proto=.pb.go)
PROTOGWFILES := $(shell find $(PROTODIRS) -type f -name '*.proto' -exec grep -l 'google.api.http' {} \;)
PROTOGWTARGETS := $(PROTOGWFILES:.proto=.pb.gw.go) $(PROTOGWFILES:.pb.gw.go=.swagger.json)
PROTOALLTARGETS := $(PROTOTARGETS) $(PROTOGWTARGETS)
# build any proto target (.pb.go, .pb.gw.go, .swagger.json) that is missing or not newer than .proto
protoc: $(PROTOALLTARGETS)
# build any proto target - use dockerized protobuf toolchain
%.pb.go %.pb.gw.go %.swagger.json: %.proto
@echo $<
@echo "compile proto files"
@ docker run -it --rm -v $${PWD}:/go/src/github.com/appcelerator/amp -w /go/src/github.com/appcelerator/amp appcelerator/amptools make protoc
# ===============================================
# cli
# ===============================================
AMPPATH := cmd/amp
AMPDIRS := $(AMPPATH) cli $(COMMONDIRS)
AMPSRC := $(shell find $(AMPDIRS) -type f -name '*.go')
AMPTARGET := bin/darwin/amd64/amp
AMPPKG := $(REPO)/$(AMPPATH)
$(AMPTARGET): $(VENDOR) $(PROTOTARGETS) $(AMPSRC)
@ echo "building amp"
@go build -ldflags $(LDFLAGS) -o $(AMPTARGET) $(AMPPKG)
cli: $(AMPTARGET)
cleancli:
@rm -f $(AMPTARGET)
rebuildcli: cleancli cli
# ===============================================
# server
# ===============================================
AMPLPATH := cmd/amplifier
AMPLDIRS := $(AMPLPATH) api data $(COMMONDIRS)
AMPLSRC := $(shell find $(AMPLDIRS) -type f -name '*.go')
AMPLTARGET := $(AMPLPATH)/amplifier.alpine
AMPLPKG := $(REPO)/$(AMPLPATH)
AMPLIMG := $(OWNER)/amplifier:$(VERSION)
$(AMPLTARGET): $(VENDOR) $(PROTOTARGETS) $(AMPLSRC)
@ echo "building amplifier"
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags $(LDFLAGS) -o $(AMPLTARGET) $(AMPLPKG)
@docker build -t $(AMPLIMG) $(AMPLPATH)
server: $(AMPLTARGET)
cleanserver:
@rm -f $(AMPLTARGET)
rebuildserver: cleanserver server
# ===============================================
# services
# ===============================================
deploy: $(AMPLTARGET)
@cd cluster/agent && TAG=$(VERSION) docker stack deploy -c stacksamples/amplifier-lite.yml amplifier
version: "3.3"
networks:
default:
external:
name: ampnet
volumes:
etcd-data:
configs:
default.amplifier.yml:
file: defaults/amplifier.yml
secrets:
default.certificate.amp:
file: defaults/certificate.amp
services:
amplifier:
image: appcelerator/amplifier:${TAG:-0.13.0}
networks:
- default
environment:
REGISTRATION: ${REGISTRATION:-none}
NOTIFICATIONS: ${NOTIFICATIONS:-false}
ports:
- "50101:50101"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
labels:
io.amp.role: "infrastructure"
amp.service.stabilize.delay: "6s"
amp.service.stabilize.timeout: "30s"
deploy:
mode: global
labels:
io.amp.role: "infrastructure"
restart_policy:
condition: on-failure
secrets:
- source: default.certificate.amp
target: cert0.pem
mode: 0400
configs:
- source: default.amplifier.yml
target: /run/configs/amplifier.yml
etcd:
image: appcelerator/etcd:3.1.10
networks:
default:
volumes:
- etcd-data:/data
environment:
SERVICE_NAME: "etcd"
MIN_SEEDS_COUNT: 1
command:
- "--advertise-client-urls"
- "http://etcd:2379"
labels:
io.amp.role: "infrastructure"
amp.service.stabilize.delay: "5s"
amp.service.stabilize.timeout: "20s"
deploy:
mode: replicated
replicas: 1
labels:
io.amp.role: "infrastructure"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment