Build a manifest list

Retool some of the build/test to produce a manifest-list rather than a
single image.
This commit is contained in:
Tim Hockin 2018-11-09 14:16:13 -08:00
parent 76bda81e0f
commit ada75e9c6c
4 changed files with 97 additions and 81 deletions

View File

@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
FROM ARG_FROM FROM {ARG_FROM}
MAINTAINER Tim Hockin <thockin@google.com> MAINTAINER Tim Hockin <thockin@google.com>
ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
RUN apk update --no-cache && apk add \ RUN apk update --no-cache && apk add \
ca-certificates \ ca-certificates \
@ -28,4 +28,4 @@ RUN apk update --no-cache && apk add \
ENV HOME /tmp ENV HOME /tmp
USER nobody:nobody USER nobody:nobody
ENTRYPOINT ["/ARG_BIN"] ENTRYPOINT ["/{ARG_BIN}"]

155
Makefile
View File

@ -21,8 +21,11 @@ PKG := k8s.io/git-sync
# Where to push the docker image. # Where to push the docker image.
REGISTRY ?= staging-k8s.gcr.io REGISTRY ?= staging-k8s.gcr.io
# Which architecture to build - see $(ALL_ARCH) for options. # Which platform to build - see $(ALL_PLATFORMS) for options.
ARCH ?= amd64 PLATFORM ?= linux/amd64
OS := $(firstword $(subst /, ,$(PLATFORM)))
ARCH := $(lastword $(subst /, ,$(PLATFORM)))
# This version-strategy uses git tags to set the version string # This version-strategy uses git tags to set the version string
VERSION := $(shell git describe --tags --always --dirty) VERSION := $(shell git describe --tags --always --dirty)
@ -36,27 +39,29 @@ VERSION := $(shell git describe --tags --always --dirty)
SRC_DIRS := cmd pkg # directories which hold app source (not vendored) SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
ALL_ARCH := amd64 ALL_PLATFORMS := linux/amd64
# TODO: get a baseimage that works for other architectures # TODO: get a baseimage that works for other platforms
# arm arm64 ppc64le # linux/arm linux/arm64 linux/ppc64le
# Set default base image dynamically for each arch # Set default base image dynamically for each arch
ifeq ($(ARCH),amd64) ifeq ($(PLATFORM),linux/amd64)
BASEIMAGE?=alpine:3.7 BASEIMAGE ?= alpine:3.8
endif #endif
ifeq ($(ARCH),arm) #ifeq ($(PLATFORM),linux/arm)
BASEIMAGE?=armel/busybox # BASEIMAGE ?= armel/busybox
endif #endif
ifeq ($(ARCH),arm64) #ifeq ($(PLATFORM),linux/arm64)
BASEIMAGE?=aarch64/busybox # BASEIMAGE ?= aarch64/busybox
endif #endif
ifeq ($(ARCH),ppc64le) #ifeq ($(PLATFORM),linux/ppc64le)
BASEIMAGE?=ppc64le/busybox # BASEIMAGE ?= ppc64le/busybox
else
$(error Unsupported platform '$(PLATFORM)')
endif endif
IMAGE := $(REGISTRY)/$(BIN)-$(ARCH) IMAGE := $(REGISTRY)/$(BIN)
LEGACY_IMAGE := $(REGISTRY)/$(BIN) TAG := $(VERSION)__$(OS)_$(ARCH)
BUILD_IMAGE ?= golang:1.11-alpine BUILD_IMAGE ?= golang:1.11-alpine
@ -74,86 +79,92 @@ container-%:
push-%: push-%:
@$(MAKE) --no-print-directory ARCH=$* push @$(MAKE) --no-print-directory ARCH=$* push
all-build: $(addprefix build-, $(ALL_ARCH)) all-build: $(addprefix build-, $(ALL_PLATFORMS))
all-container: $(addprefix container-, $(ALL_ARCH)) all-container: $(addprefix container-, $(ALL_PLATFORMS))
all-push: $(addprefix push-, $(ALL_ARCH)) all-push: $(addprefix push-, $(ALL_PLATFORMS))
build: bin/$(ARCH)/$(BIN) build: bin/$(OS)_$(ARCH)/$(BIN)
bin/$(ARCH)/$(BIN): build-dirs bin/$(OS)_$(ARCH)/$(BIN): build-dirs
@echo "building: $@" @echo "building: $@"
@docker run \ @docker run \
-i \ -i \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \ -v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \ -v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(ARCH):/go/bin \ -v $$(pwd)/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \ -v $$(pwd)/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ -v $$(pwd)/.go/std/$(OS)_$(ARCH):/usr/local/go/pkg/$(OS)_$(ARCH)_static \
-v $$(pwd)/.go/cache:/.cache \ -v $$(pwd)/.go/cache:/.cache \
-w /go/src/$(PKG) \ -w /go/src/$(PKG) \
--rm \ --rm \
$(BUILD_IMAGE) \ $(BUILD_IMAGE) \
/bin/sh -c " \ /bin/sh -c " \
ARCH=$(ARCH) \ ARCH=$(ARCH) \
VERSION=$(VERSION) \ OS=$(OS) \
PKG=$(PKG) \ VERSION=$(VERSION) \
./build/build.sh \ PKG=$(PKG) \
./build/build.sh \
" "
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION) DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
container: .container-$(DOTFILE_IMAGE) container-name container: .container-$(DOTFILE_IMAGE) container-name
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in .container-$(DOTFILE_IMAGE): bin/$(OS)_$(ARCH)/$(BIN) Dockerfile.in
@sed \ @sed \
-e 's|ARG_BIN|$(BIN)|g' \ -e 's|{ARG_BIN}|$(BIN)|g' \
-e 's|ARG_ARCH|$(ARCH)|g' \ -e 's|{ARG_ARCH}|$(ARCH)|g' \
-e 's|ARG_FROM|$(BASEIMAGE)|g' \ -e 's|{ARG_OS}|$(OS)|g' \
Dockerfile.in > .dockerfile-$(ARCH) -e 's|{ARG_FROM}|$(BASEIMAGE)|g' \
@docker build -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) . Dockerfile.in > .dockerfile-$(OS)_$(ARCH)
@docker images -q $(IMAGE):$(VERSION) > $@ @docker build -t $(IMAGE):$(TAG) -f .dockerfile-$(OS)_$(ARCH) .
@if [ "$(ARCH)" = "amd64" ]; then \ @docker images -q $(IMAGE):$(TAG) > $@
docker tag $(IMAGE):$(VERSION) $(LEGACY_IMAGE):$(VERSION); \
fi
container-name: container-name:
@echo "container: $(IMAGE):$(VERSION)" @echo "container: $(IMAGE):$(TAG)"
push: .push-$(DOTFILE_IMAGE) push-name push: .push-$(DOTFILE_IMAGE) push-name
.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE) .push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE)
@gcloud docker -- push $(IMAGE):$(VERSION) @docker push $(IMAGE):$(TAG)
@docker images -q $(IMAGE):$(VERSION) > $@ @docker images -q $(IMAGE):$(TAG) > $@
@if [ "$(ARCH)" = "amd64" ]; then \
gcloud docker -- push $(LEGACY_IMAGE):$(VERSION); \
fi
push-name: push-name:
@echo "pushed: $(IMAGE):$(VERSION)" @echo "pushed: $(IMAGE):$(TAG)"
# This depends on github.com/estesp/manifest-tool in $PATH.
manifest-list: container
manifest-tool \
--username=oauth2accesstoken \
--password=$$(gcloud auth print-access-token) \
push from-args \
--platforms "$(ALL_PLATFORMS)" \
--template $(REGISTRY)/$(BIN):$(VERSION)__OS_ARCH \
--target $(REGISTRY)/$(BIN):$(VERSION)
version: version:
@echo $(VERSION) @echo $(VERSION)
test: build-dirs test: build-dirs
@docker run \ @docker run \
-ti \ -ti \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \ -v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \ -v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(ARCH):/go/bin \ -v $$(pwd)/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ -v $$(pwd)/.go/std/$(OS)_$(ARCH):/usr/local/go/pkg/$(OS)_$(ARCH)_static \
-v $$(pwd)/.go/cache:/.cache \ -v $$(pwd)/.go/cache:/.cache \
-w /go/src/$(PKG) \ -w /go/src/$(PKG) \
$(BUILD_IMAGE) \ $(BUILD_IMAGE) \
/bin/sh -c " \ /bin/sh -c " \
./build/test.sh $(SRC_DIRS) \ ./build/test.sh $(SRC_DIRS) \
" "
@./test_e2e.sh @./test_e2e.sh
build-dirs: build-dirs:
@mkdir -p bin/$(ARCH) @mkdir -p bin/$(OS)_$(ARCH)
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH) .go/cache @mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(OS)_$(ARCH) .go/cache
clean: container-clean bin-clean clean: container-clean bin-clean

View File

@ -18,21 +18,26 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
if [ -z "${PKG}" ]; then if [ -z "${PKG:-}" ]; then
echo "PKG must be set" echo "PKG must be set"
exit 1 exit 1
fi fi
if [ -z "${ARCH}" ]; then if [ -z "${ARCH:-}" ]; then
echo "ARCH must be set" echo "ARCH must be set"
exit 1 exit 1
fi fi
if [ -z "${VERSION}" ]; then if [ -z "${OS:-}" ]; then
echo "OS must be set"
exit 1
fi
if [ -z "${VERSION:-}" ]; then
echo "VERSION must be set" echo "VERSION must be set"
exit 1 exit 1
fi fi
export CGO_ENABLED=0 export CGO_ENABLED=0
export GOARCH="${ARCH}" export GOARCH="${ARCH}"
export GOOS="${OS}"
go install \ go install \
-installsuffix "static" \ -installsuffix "static" \

View File

@ -61,7 +61,7 @@ trap finish INT EXIT
# ##################### # #####################
# Build it # Build it
make container REGISTRY=e2e TAG=$(make -s version) make container REGISTRY=e2e VERSION=$(make -s version)
DIR="" DIR=""
for i in $(seq 1 10); do for i in $(seq 1 10); do
@ -76,14 +76,14 @@ echo "test root is $DIR"
CONTAINER_NAME=git-sync-$RANDOM CONTAINER_NAME=git-sync-$RANDOM
function GIT_SYNC() { function GIT_SYNC() {
#./bin/amd64/git-sync "$@" #./bin/linux_amd64/git-sync "$@"
docker run \ docker run \
--name $CONTAINER_NAME \ --name $CONTAINER_NAME \
-i \ -i \
-u $(id -u):$(id -g) \ -u $(id -u):$(id -g) \
-v "$DIR":"$DIR" \ -v "$DIR":"$DIR" \
--rm \ --rm \
e2e/git-sync-amd64:$(make -s version) \ e2e/git-sync:$(make -s version) \
"$@" "$@"
} }