From: Jared Reisinger Date: Wed, 21 Sep 2016 16:34:57 +0000 (-0700) Subject: Improve optional/default squashing. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0e0a4a48cf2fb54203333e14a78baa02d727980a;p=discourse_docker.git Improve optional/default squashing. I've verified that: - OSX/Darwin-specific docker-squash, - with gnu-tar 1.29 (>=1.27) in the path as "tar", - and run as root, actually works. As such, using docker-squash is now the default behavior (consistent with the previous behavior), but you can opt out of it by prefix your `make` command with the `SQUASH=NO` environment variable: SQUASH=NO make all Also note that rather than running the _entire_ make with "sudo", it's now used specifically for the docker-squash call only, so that the various make commands aren't running more privileged than they really need to. --- diff --git a/image/Makefile b/image/Makefile index b7b7aa1..29916cb 100644 --- a/image/Makefile +++ b/image/Makefile @@ -3,9 +3,12 @@ IMAGE_VERSION := 1.3.7 SHELL := /bin/bash OS := $(shell uname | tr '[:upper:]' '[:lower:]') +SQUASH ?= YES + DOCKER_SQUASH_URL := https://github.com/jwilder/docker-squash/releases/download/v0.2.0/docker-squash-${OS}-amd64-v0.2.0.tar.gz + # omitting discourse_fast_switch from 'all' as it seems obsolete. all: base discourse discourse_dev discourse_test discourse_bench .PHONY: all base discourse discourse_dev discourse_test discourse_bench discourse_fast_switch @@ -37,23 +40,22 @@ discourse_dev-deps: cp ../templates/redis.template.yml discourse_dev/redis.template.yml .PHONY: discourse_dev-deps -# docker-squash doesn't seem to work on OSX... there's an error about calling -# tar with an unsuported "--xattrs" option. If/when that gets fixed, the ifeq -# can be removed. For now, OSX skips the docker-squash step, so don't push -# images built on OSX! +# If you don't want to docker-squash the image, prefix your command line with +# SQUASH=NO, like: +# SQUASH=NO make discourse_dev build-image: docker-squash update-dockerfile @echo "----- building image: discourse/${IMAGE_DIR}:${IMAGE_VERSION} -----" -ifeq ($(OS), darwin) - docker build -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} ${IMAGE_DIR} -else +ifeq (${SQUASH}, YES) docker build ${IMAGE_DIR} | tee .build.out - @echo "squashing $(shell tail -1 .build.out | awk '/^Successfully built / {print $$3}')..." - docker save -o img.tar $(shell tail -1 .build.out | awk '/^Successfully built / {print $$3}') - ./docker-squash -verbose -i img.tar -o squash.tar $(if $(IS_BASE),-from root) -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} + @echo "squashing $$(tail -1 .build.out | awk '/^Successfully built / {print $$3}')..." + docker save -o img.tar $$(tail -1 .build.out | awk '/^Successfully built / {print $$3}') + sudo ./docker-squash -verbose -i img.tar -o squash.tar $(if $(IS_BASE),-from root) -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} docker load -i squash.tar rm -f squash.tar rm -f img.tar rm -f .build.out +else + docker build -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} ${IMAGE_DIR} endif .PHONY: build-image