Skip to content

Commit

Permalink
Add generate-all capability
Browse files Browse the repository at this point in the history
  • Loading branch information
dhodovsk authored and praiskup committed Feb 27, 2018
1 parent 6292101 commit cef6837
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
2 changes: 2 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#! /bin/sh

set -e
test -f auto_targets.mk && rm auto_targets.mk

for version
do
remove_images=
Expand Down
23 changes: 4 additions & 19 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ build = $(SHELL) $(common_dir)/build.sh
test = $(SHELL) $(common_dir)/test.sh
tag = $(SHELL) $(common_dir)/tag.sh
clean = $(SHELL) $(common_dir)/clean.sh
generator = $(SHELL) $(common_dir)/generate.sh

ifeq ($(TARGET),rhel7)
SKIP_SQUASH ?= 0
Expand All @@ -30,13 +29,11 @@ else ifeq ($(TARGET),centos6)
else
OS := centos7
DOCKERFILE ?= Dockerfile
DG_CONF ?= centos-7-x86_64.yaml
DG_CONF := centos-7-x86_64.yaml
endif

SKIP_SQUASH ?= 1
DOCKER_BUILD_CONTEXT ?= .
DISTGEN_BIN ?= /usr/bin/dg
MANIFEST_FILE ?= manifest.sh

script_env = \
SKIP_SQUASH=$(SKIP_SQUASH) \
Expand All @@ -47,11 +44,6 @@ script_env = \
OPENSHIFT_NAMESPACES="$(OPENSHIFT_NAMESPACES)" \
CUSTOM_REPO="$(CUSTOM_REPO)"

generation_env = \
DG_CONF=$(DG_CONF) \
DG=$(DISTGEN_BIN) \
MANIFEST_FILE=$(MANIFEST_FILE)

# TODO: switch to 'build: build-all' once parallel builds are relatively safe
.PHONY: build build-serial build-all
build: build-serial
Expand Down Expand Up @@ -99,14 +91,7 @@ clean:

.PHONY: generate
generate:
@$(MAKE) auto_targets.mk
@$(MAKE) exec-gen-rules
rm auto_targets.mk

auto_targets.mk: $(generator) $(MANIFEST_FILE)
VERSIONS="$(VERSIONS)" $(generation_env) $(generator)

include auto_targets.mk
$(MAKE) VERSIONS="$(VERSIONS)" DG_CONF=$(DG_CONF) -f $(common_dir)/gen.mk gen

.PHONY: exec-gen-rules
exec-gen-rules: $(DISTGEN_TARGETS) $(COPY_TARGETS) $(SYMLINK_TARGETS)
generate-all:
$(MAKE) VERSIONS="$(VERSIONS)" DG_CONF="rhel-7-x86_64.yaml fedora-27-x86_64.yaml centos-7-x86_64.yaml" -f $(common_dir)/gen.mk gen
27 changes: 27 additions & 0 deletions gen.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Helper for generating image repository files

ifndef common_dir
common_dir = common
endif

generator = $(common_dir)/generate.sh
# default path for dg binary from package distgen
DISTGEN_BIN ?= /usr/bin/dg
MANIFEST_FILE ?= manifest.sh

generation_env = \
DG=$(DISTGEN_BIN) \
MANIFEST_FILE=$(MANIFEST_FILE)

.PHONY: gen
gen: auto_targets.mk exec-gen-rules
rm auto_targets.mk


auto_targets.mk: $(generator) $(MANIFEST_FILE)
VERSIONS="$(VERSIONS)" DG_CONF="$(DG_CONF)" $(generation_env) $(generator)

include auto_targets.mk

.PHONY: exec-gen-rules
exec-gen-rules: $(DISTGEN_TARGETS) $(COPY_TARGETS) $(SYMLINK_TARGETS)
28 changes: 26 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,31 @@ parse_rules() {
distgen)
[[ -z "$src" ]] && echo "src has to be specified in distgen rule" && exit 1
[[ -z "$dest" ]] && echo "dest has to be specified in distgen rule" && exit 1
core_subst=$core

if [[ "$dest" == "Dockerfile"* ]]; then
if [[ "$dest" == "Dockerfile.rhel7" ]]; then
if [[ "$DG_CONF" == *"rhel-7-x86_64.yaml"* ]]; then
conf=rhel-7-x86_64.yaml
else
continue
fi
elif [[ "$dest" == *"Dockerfile.fedora" ]]; then
if [[ "$DG_CONF" == *"fedora-27-x86_64.yaml"* ]]; then
conf=fedora-27-x86_64.yaml
else
continue
fi
elif [[ "$dest" == *"Dockerfile" ]]; then
if [[ "$DG_CONF" == *"centos-7-x86_64.yaml"* ]]; then
conf=centos-7-x86_64.yaml
else
continue
fi
fi
else
conf=centos-7-x86_64.yaml
fi
core_subst=$(echo $core | sed -e "s~__conf__~"${conf}"~g")
;;
link)
[[ -z "$link_name" ]] && echo "link_name has to be specified in link rule" && exit 1
Expand Down Expand Up @@ -85,7 +109,7 @@ for version in ${VERSIONS}; do
# distgen targets
rules="$DISTGEN_RULES"
core="${DG} --multispec specs/multispec.yml \\
--template \"\$<\" --distro \"$DG_CONF\" \\
--template \"\$<\" --distro \"__conf__\" \\
--multispec-selector version=\"$version\" --output \"\$@\" ; \\"
message="Generating \"\$@\" using distgen"
creator="distgen"
Expand Down

0 comments on commit cef6837

Please sign in to comment.