From dc4d7e6532892b69292dde1b34007d3c2ea76458 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Mon, 15 Mar 2021 00:49:13 +0800 Subject: [PATCH] general: update makefiles for project --- .circleci/config.yml | 5 +-- Makefile | 84 ++++++-------------------------------------- Makefile.docker | 77 ++++++++++++++++++++++++++++++++++++++++ README.md | 22 ++++++++++++ frontend/Makefile | 5 +++ proxy/Makefile | 3 ++ 6 files changed, 120 insertions(+), 76 deletions(-) create mode 100644 Makefile.docker create mode 100644 frontend/Makefile create mode 100644 proxy/Makefile diff --git a/.circleci/config.yml b/.circleci/config.yml index 914048b..3ad11f0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,8 +53,9 @@ jobs: PROGRAM: << parameters.program >> BUILD_ID: << pipeline.number >> command: | - make _crossbuild + make -f Makefile.docker _crossbuild echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin - make DOCKER_USERNAME=$DOCKER_USERNAME \ + make -f Makefile.docker \ + DOCKER_USERNAME=$DOCKER_USERNAME \ BUILD_ID=circleci-build$BUILD_ID \ $PROGRAM/$IMAGE_ARCH diff --git a/Makefile b/Makefile index 62c587d..c28b197 100644 --- a/Makefile +++ b/Makefile @@ -1,77 +1,13 @@ -# Basic definitions -DOCKER_USERNAME := xddxdd -ARCHITECTURES := amd64 i386 arm32v7 arm64v8 ppc64le s390x -IMAGES := frontend proxy +frontend: + $(MAKE) -C frontend all -# General Purpose Preprocessor config -GPP_INCLUDE_DIR := include -GPP_FLAGS_U := "" "" "(" "," ")" "(" ")" "\#" "" -GPP_FLAGS_M := "\#" "\n" " " " " "\n" "(" ")" -GPP_FLAGS_EXTRA := +c "\\\n" "" -GPP_FLAGS := -I ${GPP_INCLUDE_DIR} --nostdinc -U ${GPP_FLAGS_U} -M ${GPP_FLAGS_M} ${GPP_FLAGS_EXTRA} +proxy: + $(MAKE) -C proxy all -BUILD_ID ?= $(shell date +%Y%m%d%H%M) +.DEFAULT_GOAL := all +.PHONY: all frontend proxy +all: frontend proxy -define create-image-arch-target -frontend/Dockerfile.$1: frontend/template.Dockerfile - @gpp ${GPP_FLAGS} -D ARCH_$(shell echo $1 | tr a-z A-Z) -o frontend/Dockerfile.$1 frontend/template.Dockerfile || rm -rf frontend/Dockerfile.$1 - -frontend/$1: frontend/Dockerfile.$1 - @if [ -f frontend/Dockerfile.$1 ]; then \ - docker build --pull --no-cache -t ${DOCKER_USERNAME}/bird-lg-go:$1-${BUILD_ID} -f frontend/Dockerfile.$1 frontend || exit 1; \ - docker push ${DOCKER_USERNAME}/bird-lg-go:$1-${BUILD_ID} || exit 1; \ - docker tag ${DOCKER_USERNAME}/bird-lg-go:$1-${BUILD_ID} ${DOCKER_USERNAME}/bird-lg-go:$1 || exit 1; \ - docker push ${DOCKER_USERNAME}/bird-lg-go:$1 || exit 1; \ - else \ - echo "Dockerfile generation failed, see error above"; \ - exit 1; \ - fi - -proxy/Dockerfile.$1: proxy/template.Dockerfile - @gpp ${GPP_FLAGS} -D ARCH_$(shell echo $1 | tr a-z A-Z) -o proxy/Dockerfile.$1 proxy/template.Dockerfile || rm -rf proxy/Dockerfile.$1 - -proxy/$1: proxy/Dockerfile.$1 - @if [ -f proxy/Dockerfile.$1 ]; then \ - docker build --pull --no-cache -t ${DOCKER_USERNAME}/bird-lgproxy-go:$1-${BUILD_ID} -f proxy/Dockerfile.$1 proxy || exit 1; \ - docker push ${DOCKER_USERNAME}/bird-lgproxy-go:$1-${BUILD_ID} || exit 1; \ - docker tag ${DOCKER_USERNAME}/bird-lgproxy-go:$1-${BUILD_ID} ${DOCKER_USERNAME}/bird-lgproxy-go:$1 || exit 1; \ - docker push ${DOCKER_USERNAME}/bird-lgproxy-go:$1 || exit 1; \ - else \ - echo "Dockerfile generation failed, see error above"; \ - exit 1; \ - fi - -endef - -$(foreach arch,${ARCHITECTURES},$(eval $(call create-image-arch-target,$(arch)))) - -frontend:$(foreach arch,latest ${ARCHITECTURES},frontend/${arch}) - -frontend/latest: frontend/amd64 - @docker tag ${DOCKER_USERNAME}/bird-lg-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lg-go:${BUILD_ID} || exit 1 - @docker push ${DOCKER_USERNAME}/bird-lg-go:${BUILD_ID} || exit 1 - @docker tag ${DOCKER_USERNAME}/bird-lg-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lg-go:latest || exit 1 - @docker push ${DOCKER_USERNAME}/bird-lg-go:latest || exit 1 - -proxy:$(foreach arch,latest ${ARCHITECTURES},proxy/${arch}) - -proxy/latest: proxy/amd64 - @docker tag ${DOCKER_USERNAME}/bird-lgproxy-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lgproxy-go:${BUILD_ID} || exit 1 - @docker push ${DOCKER_USERNAME}/bird-lgproxy-go:${BUILD_ID} || exit 1 - @docker tag ${DOCKER_USERNAME}/bird-lgproxy-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lgproxy-go:latest || exit 1 - @docker push ${DOCKER_USERNAME}/bird-lgproxy-go:latest || exit 1 - -.DEFAULT_GOAL := images -.DELETE_ON_ERROR: -.SECONDARY: - -# Target to enable multiarch support -_crossbuild: - @docker run --rm --privileged multiarch/qemu-user-static --reset -p yes >/dev/null - -dockerfiles: $(foreach image,${IMAGES},$(foreach arch,${ARCHITECTURES},$(image)/Dockerfile.$(arch))) - -images: $(foreach image,${IMAGES},$(image)) - -clean: - @rm -rf */Dockerfile.{$(shell echo ${ARCHITECTURES} | sed "s/ /,/g")} +install: + install -m 755 frontend/frontend /usr/local/bin/frontend + install -m 755 proxy/proxy /usr/local/bin/proxy diff --git a/Makefile.docker b/Makefile.docker new file mode 100644 index 0000000..62c587d --- /dev/null +++ b/Makefile.docker @@ -0,0 +1,77 @@ +# Basic definitions +DOCKER_USERNAME := xddxdd +ARCHITECTURES := amd64 i386 arm32v7 arm64v8 ppc64le s390x +IMAGES := frontend proxy + +# General Purpose Preprocessor config +GPP_INCLUDE_DIR := include +GPP_FLAGS_U := "" "" "(" "," ")" "(" ")" "\#" "" +GPP_FLAGS_M := "\#" "\n" " " " " "\n" "(" ")" +GPP_FLAGS_EXTRA := +c "\\\n" "" +GPP_FLAGS := -I ${GPP_INCLUDE_DIR} --nostdinc -U ${GPP_FLAGS_U} -M ${GPP_FLAGS_M} ${GPP_FLAGS_EXTRA} + +BUILD_ID ?= $(shell date +%Y%m%d%H%M) + +define create-image-arch-target +frontend/Dockerfile.$1: frontend/template.Dockerfile + @gpp ${GPP_FLAGS} -D ARCH_$(shell echo $1 | tr a-z A-Z) -o frontend/Dockerfile.$1 frontend/template.Dockerfile || rm -rf frontend/Dockerfile.$1 + +frontend/$1: frontend/Dockerfile.$1 + @if [ -f frontend/Dockerfile.$1 ]; then \ + docker build --pull --no-cache -t ${DOCKER_USERNAME}/bird-lg-go:$1-${BUILD_ID} -f frontend/Dockerfile.$1 frontend || exit 1; \ + docker push ${DOCKER_USERNAME}/bird-lg-go:$1-${BUILD_ID} || exit 1; \ + docker tag ${DOCKER_USERNAME}/bird-lg-go:$1-${BUILD_ID} ${DOCKER_USERNAME}/bird-lg-go:$1 || exit 1; \ + docker push ${DOCKER_USERNAME}/bird-lg-go:$1 || exit 1; \ + else \ + echo "Dockerfile generation failed, see error above"; \ + exit 1; \ + fi + +proxy/Dockerfile.$1: proxy/template.Dockerfile + @gpp ${GPP_FLAGS} -D ARCH_$(shell echo $1 | tr a-z A-Z) -o proxy/Dockerfile.$1 proxy/template.Dockerfile || rm -rf proxy/Dockerfile.$1 + +proxy/$1: proxy/Dockerfile.$1 + @if [ -f proxy/Dockerfile.$1 ]; then \ + docker build --pull --no-cache -t ${DOCKER_USERNAME}/bird-lgproxy-go:$1-${BUILD_ID} -f proxy/Dockerfile.$1 proxy || exit 1; \ + docker push ${DOCKER_USERNAME}/bird-lgproxy-go:$1-${BUILD_ID} || exit 1; \ + docker tag ${DOCKER_USERNAME}/bird-lgproxy-go:$1-${BUILD_ID} ${DOCKER_USERNAME}/bird-lgproxy-go:$1 || exit 1; \ + docker push ${DOCKER_USERNAME}/bird-lgproxy-go:$1 || exit 1; \ + else \ + echo "Dockerfile generation failed, see error above"; \ + exit 1; \ + fi + +endef + +$(foreach arch,${ARCHITECTURES},$(eval $(call create-image-arch-target,$(arch)))) + +frontend:$(foreach arch,latest ${ARCHITECTURES},frontend/${arch}) + +frontend/latest: frontend/amd64 + @docker tag ${DOCKER_USERNAME}/bird-lg-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lg-go:${BUILD_ID} || exit 1 + @docker push ${DOCKER_USERNAME}/bird-lg-go:${BUILD_ID} || exit 1 + @docker tag ${DOCKER_USERNAME}/bird-lg-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lg-go:latest || exit 1 + @docker push ${DOCKER_USERNAME}/bird-lg-go:latest || exit 1 + +proxy:$(foreach arch,latest ${ARCHITECTURES},proxy/${arch}) + +proxy/latest: proxy/amd64 + @docker tag ${DOCKER_USERNAME}/bird-lgproxy-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lgproxy-go:${BUILD_ID} || exit 1 + @docker push ${DOCKER_USERNAME}/bird-lgproxy-go:${BUILD_ID} || exit 1 + @docker tag ${DOCKER_USERNAME}/bird-lgproxy-go:amd64-${BUILD_ID} ${DOCKER_USERNAME}/bird-lgproxy-go:latest || exit 1 + @docker push ${DOCKER_USERNAME}/bird-lgproxy-go:latest || exit 1 + +.DEFAULT_GOAL := images +.DELETE_ON_ERROR: +.SECONDARY: + +# Target to enable multiarch support +_crossbuild: + @docker run --rm --privileged multiarch/qemu-user-static --reset -p yes >/dev/null + +dockerfiles: $(foreach image,${IMAGES},$(foreach arch,${ARCHITECTURES},$(image)/Dockerfile.$(arch))) + +images: $(foreach image,${IMAGES},$(image)) + +clean: + @rm -rf */Dockerfile.{$(shell echo ${ARCHITECTURES} | sed "s/ /,/g")} diff --git a/README.md b/README.md index 5cf1867..c3fabe5 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,28 @@ An alternative implementation for [bird-lg](https://github.com/sileht/bird-lg) w Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) +## Build Instructions + +Run `make` to build binaries for both the frontend and the proxy. You need to have Go installed on your machine. + +Optionally run `make install` to install them to `/usr/local/bin`. + +Or, you can manually do the building steps: + +```bash +# Build frontend binary +cd frontend +go get -u github.com/kevinburke/go-bindata/... +go generate +go build -ldflags "-w -s" -o frontend +cd .. + +# Build proxy binary +cd proxy +go build -ldflags "-w -s" -o proxy +cd .. +``` + ## Frontend The frontend directory contains the code for the web frontend, where users see BGP states, do traceroutes and whois, etc. It's a replacement for "lg.py" in original bird-lg project. diff --git a/frontend/Makefile b/frontend/Makefile new file mode 100644 index 0000000..867738e --- /dev/null +++ b/frontend/Makefile @@ -0,0 +1,5 @@ +.PHONY: all +all: + go get -u github.com/kevinburke/go-bindata/... + go generate + go build -ldflags "-w -s" -o frontend diff --git a/proxy/Makefile b/proxy/Makefile new file mode 100644 index 0000000..4acf456 --- /dev/null +++ b/proxy/Makefile @@ -0,0 +1,3 @@ +.PHONY: all +all: $(shell find . -name \*.go -type f) + go build -ldflags "-w -s" -o proxy