From b76e9ee5bc229d6a92ee85cb6d7731d48634845c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 28 Jan 2020 16:30:52 +0300 Subject: Makefile: refactoring --- .travis.yml | 12 +++---- Makefile | 118 +++++++++++++++++++++++++++++------------------------------- README.md | 4 +-- 3 files changed, 64 insertions(+), 70 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ed2cdf..ce0d31a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: minimal +language: shell os: linux dist: bionic @@ -15,7 +15,7 @@ addons: sourceline: 'deb https://download.docker.com/linux/ubuntu "$(lsb_release -cs)" stable' install: - # GCR & BuildKit don't place nice together, e.g.: + # GCR & BuildKit don't play nice together, e.g.: # https://github.com/moby/buildkit/issues/606 - echo '{}' | sudo tee /etc/docker/daemon.json - sudo systemctl restart docker @@ -23,12 +23,12 @@ install: jobs: include: - name: Build native images - script: make docker-build + script: make docker/build - name: Build native images using Compose - script: sudo make install-compose && make compose-build + script: sudo make compose/install && make compose/build - name: Build multi-arch images if: branch != master - script: make builder/create && make buildx + script: make buildx/create && make buildx/build - name: Build & publish multi-arch images if: branch = master - script: make login && make builder/create && make push + script: make login && make buildx/create && make buildx/push diff --git a/Makefile b/Makefile index 2a1e3a2..9e1838d 100644 --- a/Makefile +++ b/Makefile @@ -23,93 +23,87 @@ ifndef DOCKER_PASSWORD endif @echo "$(DOCKER_PASSWORD)" | docker login --username "$(DOCKER_USERNAME)" --password-stdin -# Quickly install a newer Compose version: -install-compose: - curl -L "https://github.com/docker/compose/releases/download/$(compose_version)/docker-compose-$$(uname -s)-$$(uname -m)" -o /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose +# Build natively by default. +build: compose/build -compose: install-compose +clean: + docker system prune --all --force --volumes -# Re-register binfmt_misc formats with the F flag (required i.e. on Bionic): -fix-binfmt: - docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d +# Push multi-arch images by default. +push: buildx/push -binfmt: fix-binfmt +pull: + docker-compose pull -# `docker build` has week support for multiarch repos (you need to use multiple -# Dockerfile's, create a manifest manually, etc.), so it's only here for -# testing purposes, and native builds. -docker-build/%: -ifndef FORCE - $(warning Consider using `docker buildx` instead) -endif - docker build -t "$(DOCKER_USERNAME)/$*" "$*/" +up: + docker-compose up -d -docker-build: docker-build/dump1090 docker-build/fr24feed +down: + docker-compose down --volumes -# `docker-compose build` has the same problems as `docker build`. -compose-build: +check-build: ifndef FORCE - $(warning Consider using `docker buildx` instead) + $(warning Going to build natively; consider `docker buildx build` instead) endif - docker-compose build - -# The simple way to build multiarch repos. -builder/create: fix-binfmt - docker buildx create --use --name "$(PROJECT)_builder" -builder/rm: - docker buildx rm "$(PROJECT)_builder" - -buildx/%: - docker buildx build -t "$(DOCKER_USERNAME)/$*" --platform "$(platforms)" "$*/" +check-push: +ifndef FORCE + $(error Please use `docker buildx build --push` instead) +endif -buildx: buildx/dump1090 buildx/fr24feed +# `docker build` has week support for multiarch repos (you need to use multiple +# Dockerfile's, create a manifest manually, etc.), so it's only here for +# testing purposes, and native builds. +docker/build/%: check-build + docker build -t "$(DOCKER_USERNAME)/$*" "$*/" -# Build natively by default. -build: compose-build +docker/build: docker/build/dump1090 docker/build/fr24feed # `docker push` would replace the multiarch repo with a single image by default # (you'd have to create a manifest and push it instead), so it's only here for # testing purposes. -check-docker-push: -ifndef FORCE - $(error Please do not use `docker push`) -endif - -docker-push/%: check-docker-push docker-build/% +docker/push/%: check-push docker/build/% docker push "$(DOCKER_USERNAME)/$*" -docker-push: check-docker-push docker-push/dump1090 docker-push/fr24feed +docker/push: check-push docker/push/dump1090 docker/push/fr24feed -# `docker-compose push` has the same problems as `docker push`. -check-compose-push: -ifndef FORCE - $(error Please do not use `docker-compose push`) -endif +# Quickly install a newer Compose version: +compose/install: + curl -L "https://github.com/docker/compose/releases/download/$(compose_version)/docker-compose-$$(uname -s)-$$(uname -m)" -o /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose + +# `docker-compose build` has the same problems as `docker build`. +compose/build: check-build + docker-compose build -compose-push: check-compose-push compose-build +# `docker-compose push` has the same problems as `docker push`. +compose/push: check-push compose/build docker-compose push -# The simple way to push multiarch repos. -buildx-push/%: - docker buildx build -t "$(DOCKER_USERNAME)/$*" --platform "$(platforms)" --push "$*/" +# The simple way to build multiarch repos is `docker buildx`. -buildx-push: buildx-push/dump1090 buildx-push/fr24feed +# Re-register binfmt_misc formats with the F flag (required i.e. on Bionic): +fix-binfmt: + docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d -# buildx is used by default. -push: buildx-push +buildx/create: fix-binfmt + docker buildx create --use --name "$(PROJECT)_builder" -pull: - docker-compose pull +buildx/rm: + docker buildx rm "$(PROJECT)_builder" -up: - docker-compose up -d +buildx/build/%: + docker buildx build -t "$(DOCKER_USERNAME)/$*" --platform "$(platforms)" "$*/" -down: - docker-compose down --volumes +buildx/build: buildx/build/dump1090 buildx/build/fr24feed -clean: - docker system prune --all --force --volumes +buildx/push/%: + docker buildx build -t "$(DOCKER_USERNAME)/$*" --platform "$(platforms)" --push "$*/" + +buildx/push: buildx/push/dump1090 buildx/push/fr24feed -.PHONY: all login install-compose compose fix-binfmt binfmt docker-build compose-build builder/create builder/rm buildx build check-docker-push docker-push check-compose-push compose-push buildx-push push pull up down clean +.PHONY: all login build clean push pull up down +.PHONY: check-build check-push +.PHONY: docker/build docker/push +.PHONY: compose/install compose/build compose/push +.PHONY: fix-binfmt buildx/create buildx/rm buildx/build buildx/push diff --git a/README.md b/README.md index 4e9d1a7..8c4e37d 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,11 @@ Development TL;DR: build the native images using - make compose-build + make compose/build Or, if you have Compose version 1.24.x or below, - make docker-build + make docker/build ### Dependencies -- cgit v1.2.3