Makefile: use official alpine images for build

This commit modifies the build tooling so that we use the official
alipne build images rather than the images from the multiarch org. This
requires new logic to parse docker manifests but results in a cleaner
solution with fewer architecture definitions.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
Lucas Servén Marín 2020-01-08 17:10:06 +01:00
parent 5277ab5bad
commit 4b2f6c6692
No known key found for this signature in database
GPG Key ID: 586FEAF680DA74AD
2 changed files with 11 additions and 5 deletions

View File

@ -13,6 +13,9 @@ go:
env:
- GO111MODULE=on DOCKER_CLI_EXPERIMENTAL=enabled
before_install:
- sudo apt-get update && sudo apt-get -y install jq
install: true
script:

View File

@ -3,8 +3,7 @@ export GO111MODULE=on
ARCH ?= amd64
ALL_ARCH := amd64 arm arm64
DOCKER_ARCH := "" "arm v7" "arm64 v8"
IMAGE_ARCH := amd64 armhf arm64
DOCKER_ARCH := "amd64" "arm v7" "arm64 v8"
BINS := $(addprefix bin/$(ARCH)/,kg kgctl)
PROJECT := kilo
PKG := github.com/squat/$(PROJECT)
@ -34,6 +33,7 @@ OPENAPI_GEN_BINARY := bin/openapi-gen
GOLINT_BINARY := bin/golint
BUILD_IMAGE ?= golang:1.13.4-alpine
BASE_IMAGE ?= alpine:3.11
build: $(BINS)
@ -203,9 +203,12 @@ header: .header
container: .container-$(ARCH)-$(VERSION) container-name
.container-$(ARCH)-$(VERSION): $(BINS) Dockerfile
@i=0; for a in $(ALL_ARCH); do [ "$$a" = $(ARCH) ] && break; i=$$((i+1)); done; \
ia=""; \
j=0; for a in $(IMAGE_ARCH); do [ "$$i" -eq "$$j" ] && ia="$$a" && break; j=$$((j+1)); done; \
docker build -t $(IMAGE):$(ARCH)-$(VERSION) --build-arg FROM=multiarch/alpine:$$ia-v3.11 --build-arg GOARCH=$(ARCH) .
ia=""; iv=""; \
j=0; for a in $(DOCKER_ARCH); do \
[ "$$i" -eq "$$j" ] && ia=$$(echo "$$a" | awk '{print $$1}') && iv=$$(echo "$$a" | awk '{print $$2}') && break; j=$$((j+1)); \
done; \
SHA=$$(docker manifest inspect $(BASE_IMAGE) | jq '.manifests[] | select(.platform.architecture == "'$$ia'") | if .platform | has("variant") then select(.platform.variant == "'$$iv'") else . end | .digest' -r); \
docker build -t $(IMAGE):$(ARCH)-$(VERSION) --build-arg FROM=$(BASE_IMAGE)@$$SHA --build-arg GOARCH=$(ARCH) .
@docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@
container-latest: .container-$(ARCH)-$(VERSION)