-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial
copier-template
for building Vagrant boxes using `pac…
…ker`
- Loading branch information
Showing
35 changed files
with
523 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "base"] | ||
path = base | ||
url = https://github.com/dafyddj/workflow-packer-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/box/ | ||
/vms/ | ||
|
||
/iso | ||
|
||
.kitchen/ | ||
.vagrant/ | ||
output-*/ | ||
packer_cache/ | ||
|
||
*.snapshot | ||
*.cat.pkr.hcl | ||
|
||
serial.box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 :=) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/kitchen.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
$TEXTTEST_ROOT/.. . | ||
-d box_name=techneg/alpine318-x64-nocm $TEXTTEST_ROOT/.. . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/post.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/.pre-commit-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/pre.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/root.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/upload/main.pkr.hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../base/bin/version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
The following new files/directories were created: | ||
<Test Directory> | ||
----.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/box/ | ||
/vms/ | ||
|
||
/iso | ||
|
||
.kitchen/ | ||
.vagrant/ | ||
output-*/ | ||
packer_cache/ | ||
|
||
*.snapshot | ||
*.cat.pkr.hcl | ||
|
||
serial.box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-d box_name=techneg/another-box $TEXTTEST_ROOT/.. . |
Oops, something went wrong.