From 0a9a04e473c8640e217e6ebd54581751e28ec92a Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 18 Apr 2024 21:53:20 +0100 Subject: [PATCH] feat: initial `copier-template` for building Vagrant boxes using `packer` --- .gitmodules | 3 ++ base | 1 + copier.yaml | 5 ++ template/.gitignore | 14 ++++++ template/.pre-commit-config.yaml | 11 +++++ template/bin/version | 21 +++++++++ template/kitchen.yml.copier-jinja | 29 ++++++++++++ template/post.mk | 58 +++++++++++++++++++++++ template/pre.mk | 28 +++++++++++ template/root.mk | 5 ++ template/upload/main.pkr.hcl | 63 +++++++++++++++++++++++++ test/GenerateProject/catalogue.tt | 10 ++++ test/GenerateProject/gitignore.tt | 1 + test/GenerateProject/kitchen_yml.tt | 1 + test/GenerateProject/options.tt | 2 +- test/GenerateProject/post_mk.tt | 1 + test/GenerateProject/pre-commit_yaml.tt | 1 + test/GenerateProject/pre_mk.tt | 1 + test/GenerateProject/root_mk.tt | 1 + test/GenerateProject/upload_main.tt | 1 + test/GenerateProject/version.tt | 1 + test/SetBoxName/catalogue.tt | 15 ++++++ test/SetBoxName/gitignore.tt | 14 ++++++ test/SetBoxName/kitchen_yml.tt | 29 ++++++++++++ test/SetBoxName/options.tt | 1 + test/SetBoxName/post_mk.tt | 58 +++++++++++++++++++++++ test/SetBoxName/pre-commit_yaml.tt | 11 +++++ test/SetBoxName/pre_mk.tt | 28 +++++++++++ test/SetBoxName/root_mk.tt | 5 ++ test/SetBoxName/stderr.tt | 8 ++++ test/SetBoxName/stdout.tt | 2 + test/SetBoxName/upload_main.tt | 63 +++++++++++++++++++++++++ test/SetBoxName/version.tt | 21 +++++++++ test/config.tt | 10 ++++ test/testsuite.tt | 1 + 35 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 base create mode 100644 template/.gitignore create mode 100644 template/.pre-commit-config.yaml create mode 100755 template/bin/version create mode 100644 template/kitchen.yml.copier-jinja create mode 100644 template/post.mk create mode 100644 template/pre.mk create mode 100644 template/root.mk create mode 100644 template/upload/main.pkr.hcl create mode 120000 test/GenerateProject/gitignore.tt create mode 120000 test/GenerateProject/kitchen_yml.tt create mode 120000 test/GenerateProject/post_mk.tt create mode 120000 test/GenerateProject/pre-commit_yaml.tt create mode 120000 test/GenerateProject/pre_mk.tt create mode 120000 test/GenerateProject/root_mk.tt create mode 120000 test/GenerateProject/upload_main.tt create mode 120000 test/GenerateProject/version.tt create mode 100644 test/SetBoxName/catalogue.tt create mode 100644 test/SetBoxName/gitignore.tt create mode 100644 test/SetBoxName/kitchen_yml.tt create mode 100644 test/SetBoxName/options.tt create mode 100644 test/SetBoxName/post_mk.tt create mode 100644 test/SetBoxName/pre-commit_yaml.tt create mode 100644 test/SetBoxName/pre_mk.tt create mode 100644 test/SetBoxName/root_mk.tt create mode 100644 test/SetBoxName/stderr.tt create mode 100644 test/SetBoxName/stdout.tt create mode 100644 test/SetBoxName/upload_main.tt create mode 100755 test/SetBoxName/version.tt diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c48991c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "base"] + path = base + url = https://github.com/dafyddj/workflow-packer-build diff --git a/base b/base new file mode 160000 index 0000000..9af312b --- /dev/null +++ b/base @@ -0,0 +1 @@ +Subproject commit 9af312b0a37edc2bdc7d8542131d178c21e4e7ce diff --git a/copier.yaml b/copier.yaml index 823b7c8..53e2902 100644 --- a/copier.yaml +++ b/copier.yaml @@ -1,2 +1,7 @@ _subdirectory: template _templates_suffix: .copier-jinja + +# Questions +box_name: + type: str + help: What is the name of your Vagrant box? (including namespace/org) diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 0000000..1341580 --- /dev/null +++ b/template/.gitignore @@ -0,0 +1,14 @@ +/box/ +/vms/ + +/iso + +.kitchen/ +.vagrant/ +output-*/ +packer_cache/ + +*.snapshot +*.cat.pkr.hcl + +serial.box diff --git a/template/.pre-commit-config.yaml b/template/.pre-commit-config.yaml new file mode 100644 index 0000000..0e5ac23 --- /dev/null +++ b/template/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: +# - id: trailing-whitespace +# - id: end-of-file-fixer + - id: check-yaml + exclude: ^kitchen.yml$ + - id: check-added-large-files diff --git a/template/bin/version b/template/bin/version new file mode 100755 index 0000000..e0b1699 --- /dev/null +++ b/template/bin/version @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ "${DEBUG:-false}" = "true" ]; then + set -x # Run the entire script in debug mode +fi + +serial="serial.box" +if [ ! -e "$serial" ] ; then + cur=1 +else + read cur <$serial +fi + +next=$((cur + 1)) +echo $next >$serial + +cur=${GITHUB_RUN_NUMBER:-$cur} + +VERSION="$(date +%Y.%-m).$cur" + +echo $VERSION diff --git a/template/kitchen.yml.copier-jinja b/template/kitchen.yml.copier-jinja new file mode 100644 index 0000000..da60ad0 --- /dev/null +++ b/template/kitchen.yml.copier-jinja @@ -0,0 +1,29 @@ +--- +driver: + name: vagrant + box_check_update: false + ssh: + insert_key: false +<% if ENV.key?('TECHNEG_VAGRANT_PROVIDER') %> + provider: <%= ENV['TECHNEG_VAGRANT_PROVIDER'] %> +<% else %> + provider: qemu +<% end %> + +provisioner: + name: dummy + +verifier: + name: shell + +platforms: + - name: alpine_linux + driver: +<% if ENV.key?('TECHNEG_VAGRANT_BOX') %> + box: <%= ENV['TECHNEG_VAGRANT_BOX'] %> +<% else %> + box: {{ box_name }} +<% end %> + +suites: + - name: default diff --git a/template/post.mk b/template/post.mk new file mode 100644 index 0000000..7e7c4e1 --- /dev/null +++ b/template/post.mk @@ -0,0 +1,58 @@ +$(_module_name)_srcs := $(addprefix $(_module_path)/,$(srcs)) $(extra_srcs) +$(_module_name)_targets := $(addprefix $(_module_name)-,$(os_vers)) + +$(foreach os_ver,$(os_vers), \ + $(eval $(_module_name)_artifact_$(os_ver) := $($(_module_name)_output)/$(artifact_pre)$(os_ver)$(artifact_ext))) +$(_module_name)_artifacts := $(foreach os_ver,$(os_vers),$($(_module_name)_artifact_$(os_ver))) + +ifneq ($(_NO_RULES),T) +ifneq ($($(_module_name)_defined),T) +all: $($(_module_name)_targets) + +.PHONY: $(_module_name) $($(_module_name)_targets) $(os_vers) +$(_module_name): $($(_module_name)_targets) +$(os_vers): %: $(_module_name)-% +.SECONDEXPANSION: +$($(_module_name)_targets): $(_module_name)-%: $$($(_module_name)_artifact_%) + +_CLEAN := clean-$(_module_name) +_CLEAN_2 := $(addprefix $(_CLEAN)-,$(os_vers)) +.PHONY: clean $(_CLEAN_1) $(_CLEAN_2) +clean: $(_CLEAN) +$(_CLEAN): %: $(addprefix %-,$(os_vers)) +$(_CLEAN_2): clean-$(_module_name)-%: + $(info Cleaning $($(_module_name)_output)/$*$(artifact_ext)) + +$($(_module_name)_artifacts): _path := $(_module_path) +$($(_module_name)_artifacts): _pvars := $(_module_pvars) + +.SECONDEXPANSION: +$($(_module_name)_output)/$(artifact_pre)%$(vdiext): $($(_module_name)_srcs) $$($($(_module_name)_depends_on)) + $(info Making $@) + @$(VBOXMANAGE) controlvm $(*F) poweroff 2>/dev/null || true + @$(VBOXMANAGE) unregistervm $(*F) --delete 2>/dev/null || true + @$(PACKER) build $(PFLAGS) $(_pvars) -var "root_dir=$(_ROOT)" -var "output_dir=$(@D)" -only \*.$(*F) $(_path) + +.SECONDEXPANSION: +$($(_module_name)_output)/$(artifact_pre)%$(snapext): $($(_module_name)_srcs) $$($($(_module_name)_depends_on)) + $(info Making $@) + @$(VBOXMANAGE) controlvm $* poweroff 2>/dev/null || true + @$(PACKER) build $(PFLAGS) $(_pvars) -only \*.$* $(_path) + @touch $@ + +.SECONDEXPANSION: +$($(_module_name)_output)/$(artifact_pre)%$(boxext): $($(_module_name)_srcs) $$($($(_module_name)_depends_on)) + $(info Making $@) + [ -n ${GITHUB_ACTIONS+1} ] && echo "vagrant-box=$@" >> $$GITHUB_OUTPUT || true + @$(VBOXMANAGE) controlvm $* poweroff 2>/dev/null || true + @$(PACKER) build $(PFLAGS) $(_pvars) -var "root_dir=$(_ROOT)" -var "box_dir=$(@D)" -only \*.$* $(_path) + +%.cat.pkr.hcl: %.build %.provision + $(info Making $@) + @cat $^ > $@ + @echo } >> $@ + @$(PACKER) init $@ + +$(_module_name)_defined := T +endif +endif diff --git a/template/pre.mk b/template/pre.mk new file mode 100644 index 0000000..e5cfe98 --- /dev/null +++ b/template/pre.mk @@ -0,0 +1,28 @@ +.PHONY: all +all: + +_makefiles := $(filter %/Makefile,$(MAKEFILE_LIST)) +_included_from := $(patsubst $(_ROOT)/%,%,$(if $(_makefiles), \ +$(patsubst %/Makefile,%,$(word $(words $(_makefiles)),$(_makefiles))))) +ifeq ($(_included_from),) +_module := $(patsubst $(_ROOT)/%,%,$(CURDIR)) +else +_module := $(_included_from) +endif +_module_path := $(_ROOT)/$(_module) +_module_name := $(subst /,_,$(_module)) +$(_module_name)_output := $(_module_path) + +vdiext = .vdi +snapext := .snapshot +boxext := .box + +os_vers := $(shell cat $(_ROOT)/os_vers) + +artifact_pre := +extra_srcs := + +PACKER := packer +PFLAGS := -timestamp-ui -force + +VBOXMANAGE := VBoxManage diff --git a/template/root.mk b/template/root.mk new file mode 100644 index 0000000..a836d05 --- /dev/null +++ b/template/root.mk @@ -0,0 +1,5 @@ +_push = $(eval _save$1 := $(MAKEFILE_LIST)) +_pop = $(eval MAKEFILE_LIST := $(_save$1)) +_INCLUDE = $(call _push,$1)$(eval include $(_ROOT)/$1/Makefile)$(call _pop,$1) +depends_on = $(call _INCLUDE,$1) +depends_on_no_build = $(eval _NO_RULES := T)$(call _INCLUDE,$1)$(eval _NO_RULES :=) diff --git a/template/upload/main.pkr.hcl b/template/upload/main.pkr.hcl new file mode 100644 index 0000000..ad13300 --- /dev/null +++ b/template/upload/main.pkr.hcl @@ -0,0 +1,63 @@ +variable "arch" { + type = string + default = "x64" +} + +variable "box_dir" { + type = string + default = "../box/virtualbox" +} + +variable "cm" { + type = string + default = "nocm" +} + +variable "cm_version" { + type = string + default = "" +} + +variable "no_release" { + type = bool + default = true +} + +variable "prefix" { + type = string + default = "test-" +} + +variable "vagrant_cloud_org" { + type = string + default = "techneg" +} + +variable "version" { + type = string + default = "0.0.1pre" +} + +source "null" "upload" { + communicator = "none" +} + +build { + name = "upload" + + source "null.upload" { + name = "alpine318" + } + + post-processors { + post-processor "artifice" { + files = [ "${var.box_dir}/${source.name}.box" ] + } + + post-processor "vagrant-cloud" { + box_tag = "${var.vagrant_cloud_org}/${var.prefix}${source.name}-x64-${var.cm}" + version = "${var.version}" + no_release = var.no_release + } + } +} diff --git a/test/GenerateProject/catalogue.tt b/test/GenerateProject/catalogue.tt index b40f0db..3922e3c 100644 --- a/test/GenerateProject/catalogue.tt +++ b/test/GenerateProject/catalogue.tt @@ -3,3 +3,13 @@ The following new files/directories were created: ----.copier-answers.yml ----.github --------renovate.json5 +----.gitignore +----.pre-commit-config.yaml +----bin +--------version +----kitchen.yml +----post.mk +----pre.mk +----root.mk +----upload +--------main.pkr.hcl diff --git a/test/GenerateProject/gitignore.tt b/test/GenerateProject/gitignore.tt new file mode 120000 index 0000000..76168ea --- /dev/null +++ b/test/GenerateProject/gitignore.tt @@ -0,0 +1 @@ +../../base/.gitignore \ No newline at end of file diff --git a/test/GenerateProject/kitchen_yml.tt b/test/GenerateProject/kitchen_yml.tt new file mode 120000 index 0000000..0cabed5 --- /dev/null +++ b/test/GenerateProject/kitchen_yml.tt @@ -0,0 +1 @@ +../../base/kitchen.yml \ No newline at end of file diff --git a/test/GenerateProject/options.tt b/test/GenerateProject/options.tt index c12a490..ad474b0 100644 --- a/test/GenerateProject/options.tt +++ b/test/GenerateProject/options.tt @@ -1 +1 @@ -$TEXTTEST_ROOT/.. . +-d box_name=techneg/alpine318-x64-nocm $TEXTTEST_ROOT/.. . diff --git a/test/GenerateProject/post_mk.tt b/test/GenerateProject/post_mk.tt new file mode 120000 index 0000000..183ca53 --- /dev/null +++ b/test/GenerateProject/post_mk.tt @@ -0,0 +1 @@ +../../base/post.mk \ No newline at end of file diff --git a/test/GenerateProject/pre-commit_yaml.tt b/test/GenerateProject/pre-commit_yaml.tt new file mode 120000 index 0000000..ab7e797 --- /dev/null +++ b/test/GenerateProject/pre-commit_yaml.tt @@ -0,0 +1 @@ +../../base/.pre-commit-config.yaml \ No newline at end of file diff --git a/test/GenerateProject/pre_mk.tt b/test/GenerateProject/pre_mk.tt new file mode 120000 index 0000000..de01a0d --- /dev/null +++ b/test/GenerateProject/pre_mk.tt @@ -0,0 +1 @@ +../../base/pre.mk \ No newline at end of file diff --git a/test/GenerateProject/root_mk.tt b/test/GenerateProject/root_mk.tt new file mode 120000 index 0000000..d34a244 --- /dev/null +++ b/test/GenerateProject/root_mk.tt @@ -0,0 +1 @@ +../../base/root.mk \ No newline at end of file diff --git a/test/GenerateProject/upload_main.tt b/test/GenerateProject/upload_main.tt new file mode 120000 index 0000000..53e230f --- /dev/null +++ b/test/GenerateProject/upload_main.tt @@ -0,0 +1 @@ +../../base/upload/main.pkr.hcl \ No newline at end of file diff --git a/test/GenerateProject/version.tt b/test/GenerateProject/version.tt new file mode 120000 index 0000000..98d2511 --- /dev/null +++ b/test/GenerateProject/version.tt @@ -0,0 +1 @@ +../../base/bin/version \ No newline at end of file diff --git a/test/SetBoxName/catalogue.tt b/test/SetBoxName/catalogue.tt new file mode 100644 index 0000000..3922e3c --- /dev/null +++ b/test/SetBoxName/catalogue.tt @@ -0,0 +1,15 @@ +The following new files/directories were created: + +----.copier-answers.yml +----.github +--------renovate.json5 +----.gitignore +----.pre-commit-config.yaml +----bin +--------version +----kitchen.yml +----post.mk +----pre.mk +----root.mk +----upload +--------main.pkr.hcl diff --git a/test/SetBoxName/gitignore.tt b/test/SetBoxName/gitignore.tt new file mode 100644 index 0000000..1341580 --- /dev/null +++ b/test/SetBoxName/gitignore.tt @@ -0,0 +1,14 @@ +/box/ +/vms/ + +/iso + +.kitchen/ +.vagrant/ +output-*/ +packer_cache/ + +*.snapshot +*.cat.pkr.hcl + +serial.box diff --git a/test/SetBoxName/kitchen_yml.tt b/test/SetBoxName/kitchen_yml.tt new file mode 100644 index 0000000..0c1c0ed --- /dev/null +++ b/test/SetBoxName/kitchen_yml.tt @@ -0,0 +1,29 @@ +--- +driver: + name: vagrant + box_check_update: false + ssh: + insert_key: false +<% if ENV.key?('TECHNEG_VAGRANT_PROVIDER') %> + provider: <%= ENV['TECHNEG_VAGRANT_PROVIDER'] %> +<% else %> + provider: qemu +<% end %> + +provisioner: + name: dummy + +verifier: + name: shell + +platforms: + - name: alpine_linux + driver: +<% if ENV.key?('TECHNEG_VAGRANT_BOX') %> + box: <%= ENV['TECHNEG_VAGRANT_BOX'] %> +<% else %> + box: techneg/another-box +<% end %> + +suites: + - name: default diff --git a/test/SetBoxName/options.tt b/test/SetBoxName/options.tt new file mode 100644 index 0000000..9fe69d0 --- /dev/null +++ b/test/SetBoxName/options.tt @@ -0,0 +1 @@ +-d box_name=techneg/another-box $TEXTTEST_ROOT/.. . diff --git a/test/SetBoxName/post_mk.tt b/test/SetBoxName/post_mk.tt new file mode 100644 index 0000000..7e7c4e1 --- /dev/null +++ b/test/SetBoxName/post_mk.tt @@ -0,0 +1,58 @@ +$(_module_name)_srcs := $(addprefix $(_module_path)/,$(srcs)) $(extra_srcs) +$(_module_name)_targets := $(addprefix $(_module_name)-,$(os_vers)) + +$(foreach os_ver,$(os_vers), \ + $(eval $(_module_name)_artifact_$(os_ver) := $($(_module_name)_output)/$(artifact_pre)$(os_ver)$(artifact_ext))) +$(_module_name)_artifacts := $(foreach os_ver,$(os_vers),$($(_module_name)_artifact_$(os_ver))) + +ifneq ($(_NO_RULES),T) +ifneq ($($(_module_name)_defined),T) +all: $($(_module_name)_targets) + +.PHONY: $(_module_name) $($(_module_name)_targets) $(os_vers) +$(_module_name): $($(_module_name)_targets) +$(os_vers): %: $(_module_name)-% +.SECONDEXPANSION: +$($(_module_name)_targets): $(_module_name)-%: $$($(_module_name)_artifact_%) + +_CLEAN := clean-$(_module_name) +_CLEAN_2 := $(addprefix $(_CLEAN)-,$(os_vers)) +.PHONY: clean $(_CLEAN_1) $(_CLEAN_2) +clean: $(_CLEAN) +$(_CLEAN): %: $(addprefix %-,$(os_vers)) +$(_CLEAN_2): clean-$(_module_name)-%: + $(info Cleaning $($(_module_name)_output)/$*$(artifact_ext)) + +$($(_module_name)_artifacts): _path := $(_module_path) +$($(_module_name)_artifacts): _pvars := $(_module_pvars) + +.SECONDEXPANSION: +$($(_module_name)_output)/$(artifact_pre)%$(vdiext): $($(_module_name)_srcs) $$($($(_module_name)_depends_on)) + $(info Making $@) + @$(VBOXMANAGE) controlvm $(*F) poweroff 2>/dev/null || true + @$(VBOXMANAGE) unregistervm $(*F) --delete 2>/dev/null || true + @$(PACKER) build $(PFLAGS) $(_pvars) -var "root_dir=$(_ROOT)" -var "output_dir=$(@D)" -only \*.$(*F) $(_path) + +.SECONDEXPANSION: +$($(_module_name)_output)/$(artifact_pre)%$(snapext): $($(_module_name)_srcs) $$($($(_module_name)_depends_on)) + $(info Making $@) + @$(VBOXMANAGE) controlvm $* poweroff 2>/dev/null || true + @$(PACKER) build $(PFLAGS) $(_pvars) -only \*.$* $(_path) + @touch $@ + +.SECONDEXPANSION: +$($(_module_name)_output)/$(artifact_pre)%$(boxext): $($(_module_name)_srcs) $$($($(_module_name)_depends_on)) + $(info Making $@) + [ -n ${GITHUB_ACTIONS+1} ] && echo "vagrant-box=$@" >> $$GITHUB_OUTPUT || true + @$(VBOXMANAGE) controlvm $* poweroff 2>/dev/null || true + @$(PACKER) build $(PFLAGS) $(_pvars) -var "root_dir=$(_ROOT)" -var "box_dir=$(@D)" -only \*.$* $(_path) + +%.cat.pkr.hcl: %.build %.provision + $(info Making $@) + @cat $^ > $@ + @echo } >> $@ + @$(PACKER) init $@ + +$(_module_name)_defined := T +endif +endif diff --git a/test/SetBoxName/pre-commit_yaml.tt b/test/SetBoxName/pre-commit_yaml.tt new file mode 100644 index 0000000..0e5ac23 --- /dev/null +++ b/test/SetBoxName/pre-commit_yaml.tt @@ -0,0 +1,11 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: +# - id: trailing-whitespace +# - id: end-of-file-fixer + - id: check-yaml + exclude: ^kitchen.yml$ + - id: check-added-large-files diff --git a/test/SetBoxName/pre_mk.tt b/test/SetBoxName/pre_mk.tt new file mode 100644 index 0000000..e5cfe98 --- /dev/null +++ b/test/SetBoxName/pre_mk.tt @@ -0,0 +1,28 @@ +.PHONY: all +all: + +_makefiles := $(filter %/Makefile,$(MAKEFILE_LIST)) +_included_from := $(patsubst $(_ROOT)/%,%,$(if $(_makefiles), \ +$(patsubst %/Makefile,%,$(word $(words $(_makefiles)),$(_makefiles))))) +ifeq ($(_included_from),) +_module := $(patsubst $(_ROOT)/%,%,$(CURDIR)) +else +_module := $(_included_from) +endif +_module_path := $(_ROOT)/$(_module) +_module_name := $(subst /,_,$(_module)) +$(_module_name)_output := $(_module_path) + +vdiext = .vdi +snapext := .snapshot +boxext := .box + +os_vers := $(shell cat $(_ROOT)/os_vers) + +artifact_pre := +extra_srcs := + +PACKER := packer +PFLAGS := -timestamp-ui -force + +VBOXMANAGE := VBoxManage diff --git a/test/SetBoxName/root_mk.tt b/test/SetBoxName/root_mk.tt new file mode 100644 index 0000000..a836d05 --- /dev/null +++ b/test/SetBoxName/root_mk.tt @@ -0,0 +1,5 @@ +_push = $(eval _save$1 := $(MAKEFILE_LIST)) +_pop = $(eval MAKEFILE_LIST := $(_save$1)) +_INCLUDE = $(call _push,$1)$(eval include $(_ROOT)/$1/Makefile)$(call _pop,$1) +depends_on = $(call _INCLUDE,$1) +depends_on_no_build = $(eval _NO_RULES := T)$(call _INCLUDE,$1)$(eval _NO_RULES :=) diff --git a/test/SetBoxName/stderr.tt b/test/SetBoxName/stderr.tt new file mode 100644 index 0000000..0f3352e --- /dev/null +++ b/test/SetBoxName/stderr.tt @@ -0,0 +1,8 @@ +/opt/homebrew/Cellar/copier/9.2.0/libexec/lib/python3.12/site-packages/copier/vcs.py:202: DirtyLocalWarning: Dirty template changes included automatically. + warn( + +Copying from template version 0.0.0.post2.dev0+2261517 + identical . + create .copier-answers.yml + create .github + create .github/renovate.json5 diff --git a/test/SetBoxName/stdout.tt b/test/SetBoxName/stdout.tt new file mode 100644 index 0000000..139597f --- /dev/null +++ b/test/SetBoxName/stdout.tt @@ -0,0 +1,2 @@ + + diff --git a/test/SetBoxName/upload_main.tt b/test/SetBoxName/upload_main.tt new file mode 100644 index 0000000..ad13300 --- /dev/null +++ b/test/SetBoxName/upload_main.tt @@ -0,0 +1,63 @@ +variable "arch" { + type = string + default = "x64" +} + +variable "box_dir" { + type = string + default = "../box/virtualbox" +} + +variable "cm" { + type = string + default = "nocm" +} + +variable "cm_version" { + type = string + default = "" +} + +variable "no_release" { + type = bool + default = true +} + +variable "prefix" { + type = string + default = "test-" +} + +variable "vagrant_cloud_org" { + type = string + default = "techneg" +} + +variable "version" { + type = string + default = "0.0.1pre" +} + +source "null" "upload" { + communicator = "none" +} + +build { + name = "upload" + + source "null.upload" { + name = "alpine318" + } + + post-processors { + post-processor "artifice" { + files = [ "${var.box_dir}/${source.name}.box" ] + } + + post-processor "vagrant-cloud" { + box_tag = "${var.vagrant_cloud_org}/${var.prefix}${source.name}-x64-${var.cm}" + version = "${var.version}" + no_release = var.no_release + } + } +} diff --git a/test/SetBoxName/version.tt b/test/SetBoxName/version.tt new file mode 100755 index 0000000..e0b1699 --- /dev/null +++ b/test/SetBoxName/version.tt @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ "${DEBUG:-false}" = "true" ]; then + set -x # Run the entire script in debug mode +fi + +serial="serial.box" +if [ ! -e "$serial" ] ; then + cur=1 +else + read cur <$serial +fi + +next=$((cur + 1)) +echo $next >$serial + +cur=${GITHUB_RUN_NUMBER:-$cur} + +VERSION="$(date +%Y.%-m).$cur" + +echo $VERSION diff --git a/test/config.tt b/test/config.tt index dccb650..8185eb5 100644 --- a/test/config.tt +++ b/test/config.tt @@ -9,6 +9,16 @@ full_name:copier-packer-build create_catalogues:true +[collate_file] +gitignore:.gitignore +kitchen_yml:kitchen.yml +pre-commit_yaml:.pre-commit-config.yaml +post_mk:post.mk +pre_mk:pre.mk +root_mk:root.mk +upload_main:upload/main.pkr.hcl +version:bin/version + [run_dependent_text] stderr:Copying from template version stderr:DirtyLocalWarning{LINES 2} diff --git a/test/testsuite.tt b/test/testsuite.tt index fd29e61..911ba05 100644 --- a/test/testsuite.tt +++ b/test/testsuite.tt @@ -1 +1,2 @@ GenerateProject +SetBoxName