Skip to content

Commit

Permalink
feat(makefile): add docker buildx support
Browse files Browse the repository at this point in the history
  • Loading branch information
awill1988 committed Dec 10, 2020
1 parent 45c64df commit 507575c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include cnf.mak.docker

APPVERSION := latest
GOVERSION := 1.15
PROGRAM := pg_tileserv
CONTAINER := pramsey/$(PROGRAM)
CONTAINER := $(REPO)/$(PROGRAM)

RM = /bin/rm
CP = /bin/cp
Expand Down Expand Up @@ -37,6 +37,9 @@ bin-docker: ## Build a local binary based off of a golang base docker image
build-docker: $(PROGRAM) Dockerfile ## Generate a CentOS 7 container with APPVERSION tag, using binary from current environment
docker build -f Dockerfile --build-arg VERSION=$(APPVERSION) -t $(CONTAINER):$(APPVERSION) .

buildx-docker: ## Compiles multi-arch images and pushes them to a custom repository
docker buildx build --platform $(ARCH) -t $(CONTAINER):$(APPVERSION) --push .

release: clean docs build build-docker ## Generate the docs, a local build, and then uses the local build to generate a CentOS 7 container

test: ## Run the tests locally
Expand Down
28 changes: 28 additions & 0 deletions cnf.mak.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')

ifeq ($(uname_M),x86_64)
ARCH=amd64
endif

ifeq ($(uname_S),Linux)
ARCH=$(shell sh -c 'dpkg --print-architecture 2>/dev/null || echo not')
endif

TARGET_GOAL := $(firstword $(subst " ", ,$(wordlist 1,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))))

REPO := $(firstword $(subst " ", ,$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))))
$(eval $(REPO):;@:)
ifeq ($(REPO),)
REPO=pramsey
endif

APPVERSION := $(firstword $(subst " ", ,$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))))
$(eval $(APPVERSION):;@:)
ifeq ($(APPVERSION),)
APPVERSION=latest
endif

ifeq ($(TARGET_GOAL),buildx-docker)
ARCH=linux/amd64,linux/arm64
endif

0 comments on commit 507575c

Please sign in to comment.