Adjust code to project conventions
Following Airship Code and Project conventions [0], adding
standard Makefile targets.
Second iteration (from previous patch e41bd62
).
[0] https://airship-docs.readthedocs.io/en/latest/code-conventions.html#code-and-project-conventions
Change-Id: I9d13bb314e8618a11a957fee43fb24e02320a03d
This commit is contained in:
parent
e41bd62063
commit
1a60c80c0f
66
Makefile
66
Makefile
@ -18,12 +18,12 @@ SHELL := /bin/bash
|
||||
# APP INFO
|
||||
DOCKER_REGISTRY ?= quay.io
|
||||
IMAGE_PREFIX ?= airshipit
|
||||
IMAGE_NAME ?=
|
||||
IMAGE_NAME ?= $@
|
||||
IMAGE_TAG ?= latest
|
||||
BUILD_DIR := $(shell mktemp -d)
|
||||
HELM ?= $(BUILD_DIR)/helm
|
||||
CHARTS := $(patsubst charts/%/.,%,$(wildcard charts/*/.))
|
||||
IMAGES := $(patsubst images/%/.,%,$(wildcard images/*/.))
|
||||
IMAGES := $(addprefix porthole-,$(patsubst images/%/.,%,$(wildcard images/*/.)))
|
||||
PROXY ?= http://proxy.foo.com:8000
|
||||
NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local
|
||||
USE_PROXY ?= false
|
||||
@ -32,28 +32,31 @@ PUSH_IMAGE ?= false
|
||||
LABEL ?= org.airshipit.build=community
|
||||
COMMIT ?= $(shell git rev-parse HEAD)
|
||||
DISTRO_SUFFIX ?= $(DISTRO)
|
||||
IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}-${DISTRO_SUFFIX}
|
||||
IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}${IMAGE_TAG_SUFFIX}
|
||||
BASE_IMAGE ?=
|
||||
|
||||
# VERSION INFO
|
||||
GIT_COMMIT = ${COMMIT}
|
||||
GIT_SHA = $(shell git rev-parse --short HEAD)
|
||||
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
|
||||
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
|
||||
|
||||
HELM_PIDFILE ?= $(abspath ./.helm-pid)
|
||||
|
||||
ifdef VERSION
|
||||
DOCKER_VERSION = $(VERSION)
|
||||
endif
|
||||
|
||||
# TODO(roman_g): DISTRO_SUFFIX should be autogenerated
|
||||
# from Dockerfile extensions, see $(suffix ) Makefile function
|
||||
ifeq "$(DISTRO_SUFFIX)" ""
|
||||
# We expect that container is named 'porthole-xxxxx', and
|
||||
# subdirectory is named 'xxxxx'; so we cut 'porthole-' from
|
||||
# directory names here below and in next statement
|
||||
DOCKERFILE = "images/$(subst porthole-,,$(IMAGE_NAME))/Dockerfile"
|
||||
IMAGE_TAG_SUFFIX = ""
|
||||
else
|
||||
DOCKERFILE = "images/$(subst porthole-,,$(IMAGE_NAME))/Dockerfile.$(DISTRO_SUFFIX)"
|
||||
IMAGE_TAG_SUFFIX = "-$(DISTRO_SUFFIX)"
|
||||
endif
|
||||
|
||||
# VERSION INFO
|
||||
GIT_COMMIT = ${COMMIT}
|
||||
GIT_SHA = $(shell git rev-parse --short HEAD)
|
||||
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
|
||||
GIT_DIRTY = $(shell test -n "$$(git status --porcelain)" && echo "dirty" || echo "clean")
|
||||
|
||||
HELM_PIDFILE ?= $(abspath ./.helm-pid)
|
||||
|
||||
ifdef VERSION
|
||||
DOCKER_VERSION = $(VERSION)
|
||||
endif
|
||||
|
||||
info:
|
||||
@ -64,10 +67,11 @@ info:
|
||||
@echo "Docker Version: ${DOCKER_VERSION}"
|
||||
@echo "Registry: ${DOCKER_REGISTRY}"
|
||||
|
||||
all: lint charts images
|
||||
@echo "And what is there's nothing in there? You die, and there's" \
|
||||
"nothing beyond that. Nothing. Nothing remains. Someone might" \
|
||||
"remember you for a little while after but not for long."
|
||||
# TODO(roman_g): currently does not include images, but eventually it should
|
||||
all: lint charts
|
||||
@echo -e "\n---\nAnd what is there's nothing in there? You die, and " \
|
||||
"there's nothing beyond that. Nothing. Nothing remains. Someone " \
|
||||
"might remember you for a little while after but not for long.\n"
|
||||
|
||||
check-docker:
|
||||
@if [ -z $$(which docker) ]; then \
|
||||
@ -90,7 +94,7 @@ $(CHARTS): $(addprefix dry-run-,$(CHARTS)) chartbanner
|
||||
chartbanner:
|
||||
@echo "Building charts: $(CHARTS)"
|
||||
|
||||
lint: helm_lint
|
||||
lint: helm-lint
|
||||
|
||||
helm-lint: $(addprefix helm-lint-,$(CHARTS))
|
||||
|
||||
@ -132,16 +136,20 @@ tests:
|
||||
format:
|
||||
@echo "Not implemented." >&2; exit 2
|
||||
|
||||
images: $(addprefix build-image-,$(IMAGES))
|
||||
images: $(IMAGES)
|
||||
@echo "Done building images."
|
||||
|
||||
$(IMAGES):
|
||||
@echo
|
||||
@echo "===== Processing [$@] image ====="
|
||||
@make build-image IMAGE_NAME=$(IMAGE_NAME) DOCKERFILE=$(DOCKERFILE)
|
||||
|
||||
_BASE_IMAGE_ARG := $(if $(BASE_IMAGE),--build-arg FROM="${BASE_IMAGE}" ,)
|
||||
|
||||
build-image-%: IMAGE_NAME = $*
|
||||
build-image-%:
|
||||
build-image:
|
||||
@echo "Building $(IMAGE_NAME)..."
|
||||
ifeq ($(USE_PROXY), true)
|
||||
@echo docker build --network host -t $(IMAGE) --label $(LABEL) \
|
||||
docker build --network host -t $(IMAGE) --label $(LABEL) \
|
||||
--label "org.opencontainers.image.revision=$(COMMIT)" \
|
||||
--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
|
||||
--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
|
||||
@ -152,17 +160,17 @@ ifeq ($(USE_PROXY), true)
|
||||
--build-arg HTTP_PROXY=$(PROXY) \
|
||||
--build-arg HTTPS_PROXY=$(PROXY) \
|
||||
--build-arg no_proxy=$(NO_PROXY) \
|
||||
--build-arg NO_PROXY=$(NO_PROXY) .
|
||||
--build-arg NO_PROXY=$(NO_PROXY) "images/$(subst porthole-,,$(IMAGE_NAME))/"
|
||||
else
|
||||
@echo docker build --network host -t $(IMAGE) --label $(LABEL) \
|
||||
docker build --network host -t $(IMAGE) --label $(LABEL) \
|
||||
--label "org.opencontainers.image.revision=$(COMMIT)" \
|
||||
--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
|
||||
--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
|
||||
-f $(DOCKERFILE) \
|
||||
$(_BASE_IMAGE_ARG) .
|
||||
$(_BASE_IMAGE_ARG) "images/$(subst porthole-,,$(IMAGE_NAME))/"
|
||||
endif
|
||||
ifeq ($(PUSH_IMAGE), true)
|
||||
@echo docker push $(IMAGE)
|
||||
docker push $(IMAGE)
|
||||
endif
|
||||
|
||||
.PHONY: $(CHARTS) all build-image-% chartbanner charts check-docker clean \
|
||||
|
@ -93,7 +93,7 @@
|
||||
block:
|
||||
- make:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
target: "build-image-{{ image_name }}"
|
||||
target: "build-image"
|
||||
params:
|
||||
DISTRO_SUFFIX: "{{ distro_suffix }}"
|
||||
IMAGE_NAME: "{{ image_name }}"
|
||||
@ -103,6 +103,12 @@
|
||||
register: docker_images
|
||||
- debug:
|
||||
var: docker_images
|
||||
- shell: |
|
||||
docker images --format \
|
||||
'{{ '{{' }}.Repository{{ '}}' }}:{{ '{{' }}.Tag{{ '}}' }}'
|
||||
register: docker_images_formatted
|
||||
with_items: "{{ image_tags.stdout_lines }}"
|
||||
failed_when: "'{{ image_name }}:{{ item }}' not in docker_images_formatted.stdout"
|
||||
become: True
|
||||
|
||||
- name: Publish images
|
||||
@ -128,4 +134,10 @@
|
||||
register: docker_images
|
||||
- debug:
|
||||
var: docker_images
|
||||
- shell: |
|
||||
docker images --format \
|
||||
'{{ '{{' }}.Repository{{ '}}' }}:{{ '{{' }}.Tag{{ '}}' }}'
|
||||
register: docker_images_formatted
|
||||
with_items: "{{ image_tags.stdout_lines }}"
|
||||
failed_when: "'{{ image_name }}:{{ item }}' not in docker_images_formatted.stdout"
|
||||
become: True
|
||||
|
Loading…
Reference in New Issue
Block a user