Bin Lu | f1b0f47 | 2018-08-22 11:33:38 +0800 | [diff] [blame] | 1 | ############################################################################### |
| 2 | # Shortcut targets |
| 3 | default: image |
| 4 | all: image |
| 5 | |
| 6 | EMPTY := |
| 7 | SPACE := $(EMPTY) $(EMPTY) |
| 8 | COMMA := $(EMPTY),$(EMPTY) |
| 9 | |
| 10 | LINUX_ARCH := amd64 arm64 |
| 11 | PLATFORMS := $(subst $(SPACE),$(COMMA),$(foreach arch,$(LINUX_ARCH),linux/$(arch))) |
| 12 | |
| 13 | REGISTRY ?= nexus3.onap.org:10001/onap/vnfsdk/refrepo |
| 14 | VERSION := latest |
| 15 | TARGET := vnfsdk |
| 16 | DOCKERFILE := Dockerfile |
| 17 | |
| 18 | DOCKERFILE_PATH := ./ |
| 19 | POSTGRES_PATH := "vnfmarket-be/deployment/docker/docker-postgres/src/main/docker" |
| 20 | REFREPO_PATH := "vnfmarket-be/deployment/docker/docker-refrepo/src/main/docker" |
| 21 | |
| 22 | MANIFEST_TOOL_DIR := /usr/local/bin |
| 23 | MANIFEST_TOOL_VERSION := v0.7.0 |
| 24 | |
| 25 | clean: |
| 26 | rm -f ${POSTGRES_PATH}/Dockerfile-* |
| 27 | rm -f ${REFREPO_PATH}/Dockerfile-* |
| 28 | rm -f $(MANIFEST_TOOL_DIR)/manifest-tool |
| 29 | |
| 30 | pre: |
| 31 | for arch in $(LINUX_ARCH); do \ |
| 32 | if [ $$arch = arm64 ]; then \ |
| 33 | sed -e '/FROM ubuntu:16.04/r Dockerfile_header_arm64' ${POSTGRES_PATH}/Dockerfile > ${POSTGRES_PATH}/Dockerfile-$$arch; \ |
| 34 | sed -i 's/FROM ubuntu:16.04//g' ${POSTGRES_PATH}/Dockerfile-$$arch; \ |
| 35 | sed -e 's/postgres:/arm64v8\/postgres:/g' ${REFREPO_PATH}/Dockerfile > ${REFREPO_PATH}/Dockerfile-$$arch; \ |
| 36 | else \ |
| 37 | echo ""; \ |
| 38 | fi \ |
| 39 | done |
| 40 | |
| 41 | pre_manifest: |
| 42 | curl -sSL https://github.com/estesp/manifest-tool/releases/download/$(MANIFEST_TOOL_VERSION)/manifest-tool-linux-amd64 > $(MANIFEST_TOOL_DIR)/manifest-tool |
| 43 | chmod +x $(MANIFEST_TOOL_DIR)/manifest-tool |
| 44 | |
| 45 | ############################################################################### |
| 46 | # Building docker images |
| 47 | ############################################################################### |
| 48 | build_image: |
| 49 | docker build -t $(REGISTRY)/$(TARGET):$(VERSION) -f $(DOCKERFILE) $(DOCKERFILE_PATH) |
| 50 | image: pre |
| 51 | for arch in $(LINUX_ARCH); do \ |
| 52 | if [ $$arch = amd64 ]; then \ |
| 53 | $(MAKE) build_image TARGET="postgres-$$arch" DOCKERFILE=${POSTGRES_PATH}/Dockerfile DOCKERFILE_PATH=$(POSTGRES_PATH); \ |
| 54 | $(MAKE) build_image TARGET="refrepo-$$arch" DOCKERFILE=${REFREPO_PATH}/Dockerfile DOCKERFILE_PATH=$(REFREPO_PATH); \ |
| 55 | elif [ $$arch = arm64 ]; then \ |
| 56 | $(MAKE) build_image TARGET="postgres-$$arch" DOCKERFILE=${POSTGRES_PATH}/Dockerfile-$$arch DOCKERFILE_PATH=$(POSTGRES_PATH); \ |
| 57 | $(MAKE) build_image TARGET="refrepo-$$arch" DOCKERFILE=${REFREPO_PATH}/Dockerfile-$$arch DOCKERFILE_PATH=$(REFREPO_PATH); \ |
| 58 | else \ |
| 59 | echo "ARCH unknown"; \ |
| 60 | fi \ |
| 61 | done |
| 62 | |
| 63 | ############################################################################### |
| 64 | # push images, please use command: make push |
| 65 | ############################################################################### |
| 66 | push-manifest: |
| 67 | $(MANIFEST_TOOL_DIR)/manifest-tool push from-args --platforms $(PLATFORMS) --template $(REGISTRY)/$(TARGET)-ARCH:$(VERSION) --target $(REGISTRY)/$(TARGET):$(VERSION) |
| 68 | |
| 69 | push-single-image: |
| 70 | docker push $(REGISTRY)/$(TARGET):$(VERSION) |
| 71 | |
| 72 | push: pre_manifest |
| 73 | for arch in $(LINUX_ARCH); do \ |
| 74 | $(MAKE) push-single-image TARGET="postgres-$$arch"; \ |
| 75 | $(MAKE) push-single-image TARGET="refrepo-$$arch"; \ |
| 76 | done |
| 77 | $(MAKE) push-manifest TARGET="postgres" |
| 78 | $(MAKE) push-manifest TARGET="refrepo" |