Skip to content

Commit

Permalink
Merge pull request #15 from dafyddj/chore/copier
Browse files Browse the repository at this point in the history
chore: apply template `copier-packer-build` at `v1.0.0`
  • Loading branch information
dafyddj authored Apr 24, 2024
2 parents 2cbd147 + 334bea5 commit 9bbd819
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 100 deletions.
4 changes: 4 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v1.0.0
_src_path: gh:dafyddj/copier-packer-build
box_name: techneg/win81x64-pro-salt
31 changes: 31 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"enabledManagers": [
"custom.regex",
"git-submodules",
],
"extends": [
"config:recommended",
],
// `copier` template updates
// There are two conditions that we need to account for
// * a "clean" `.copier-answers.yml` file
// * update needed but not yet applied (and further updates could appear in this condition)
// `renovate` needs to be able to match both conditions for PRs to work properly
// We make a hacky use of the otherwise unused field `currentDigest` to hold the current copier template version
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^.copier-answers.yml$"],
"matchStrings": [
"_commit: (?<currentValue>\\S+)\\n_src_path: gh:(?<depName>\\S+)\\n",
"_commit: (?<currentDigest>\\S+) # __copier_update_needed (?<currentValue>\\S+)\\n_src_path: gh:(?<depName>\\S+)\\n",
],
"datasourceTemplate": "github-tags",
"autoReplaceStringTemplate": "_commit: {{#if currentDigest}}{{{currentDigest}}}{{else}}{{{currentValue}}}{{/if}} # __copier_update_needed {{{newValue}}}\n_src_path: gh:{{{depName}}}\n",
},
],
"git-submodules": {
"enabled": true
},
}
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/box/
/vms/

/floppy/_packer_config_local*.cmd
/iso

.snapshots/
.kitchen/
.vagrant/
packer_cache/
output-*/
packer_cache/

*.snapshot
*.auto.pkrvars
*.auto.pkrvars.hcl
*.cat.pkr.hcl

.snapshot
serial.box
Makefile.local

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subdirs = boot install guestadd update provision export
subdirs := $(shell cat stages)

include $(addsuffix /Makefile,$(subdirs))
29 changes: 29 additions & 0 deletions kitchen.yml
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: windows
driver:
<% if ENV.key?('TECHNEG_VAGRANT_BOX') %>
box: <%= ENV['TECHNEG_VAGRANT_BOX'] %>
<% else %>
box: techneg/win81x64-pro-salt
<% end %>

suites:
- name: default
1 change: 1 addition & 0 deletions os_vers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
win81 win10
21 changes: 11 additions & 10 deletions post.mk
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
$(_module_name)_srcs := $(addprefix $(_module_path)/,$(srcs)) $(extra_srcs)
$(_module_name)_targets := $(addprefix $(_module_name)-,$(win_vers))
$(_module_name)_targets := $(addprefix $(_module_name)-,$(os_vers))

$(foreach win_ver,$(win_vers), \
$(eval $(_module_name)_artifact_$(win_ver) := $($(_module_name)_output)/$(artifact_pre)$(win_ver)$(artifact_ext)))
$(_module_name)_artifacts := $(foreach win_ver,$(win_vers),$($(_module_name)_artifact_$(win_ver)))
$(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) $(win_vers)
.PHONY: $(_module_name) $($(_module_name)_targets) $(os_vers)
$(_module_name): $($(_module_name)_targets)
$(win_vers): %: $(_module_name)-%
$(os_vers): %: $(_module_name)-%
.SECONDEXPANSION:
$($(_module_name)_targets): $(_module_name)-%: $$($(_module_name)_artifact_%)

_CLEAN := clean-$(_module_name)
_CLEAN_2 := $(addprefix $(_CLEAN)-,$(win_vers))
_CLEAN_2 := $(addprefix $(_CLEAN)-,$(os_vers))
.PHONY: clean $(_CLEAN_1) $(_CLEAN_2)
clean: $(_CLEAN)
$(_CLEAN): %: $(addprefix %-,$(win_vers))
$(_CLEAN): %: $(addprefix %-,$(os_vers))
$(_CLEAN_2): clean-$(_module_name)-%:
$(info Cleaning $($(_module_name)_output)/$*$(artifact_ext))

Expand All @@ -31,7 +31,7 @@ $($(_module_name)_output)/$(artifact_pre)%$(vdiext): $($(_module_name)_srcs) $$(
$(info Making $@)
@$(VBOXMANAGE) controlvm $(*F) poweroff 2>/dev/null || true
@$(VBOXMANAGE) unregistervm $(*F) --delete 2>/dev/null || true
@$(PACKER) build $(PFLAGS) -var "root_dir=$(_ROOT)" -var "output_dir=$(@D)" -only \*.$(*F) $(_path)
@$(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))
Expand All @@ -43,8 +43,9 @@ $($(_module_name)_output)/$(artifact_pre)%$(snapext): $($(_module_name)_srcs) $$
.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) -var "root_dir=$(_ROOT)" -var "box_dir=$(@D)" -only \*.$* $(_path)
@$(PACKER) build $(PFLAGS) $(_pvars) -var "root_dir=$(_ROOT)" -var "box_dir=$(@D)" -only \*.$* $(_path)

%.cat.pkr.hcl: %.build %.provision
$(info Making $@)
Expand Down
2 changes: 1 addition & 1 deletion pre.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vdiext = .vdi
snapext := .snapshot
boxext := .box

win_vers := win81 win10
os_vers := $(shell cat $(_ROOT)/os_vers)

artifact_pre :=
extra_srcs :=
Expand Down
3 changes: 2 additions & 1 deletion provision/main.provision
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
provisioner "powershell" {
inline = [<<-EOF
$env:chocolateyVersion = '1.4.0'
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Expand Down Expand Up @@ -45,7 +46,7 @@
}
provisioner "powershell" {
inline = [
"choco-cleaner.ps1",
"choco-cleaner",
"exit 0",
]
}
1 change: 1 addition & 0 deletions stages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boot install guestadd update provision export
2 changes: 1 addition & 1 deletion update/main.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
packer {
required_plugins {
windows-update = {
version = "0.14.0"
version = "0.15.0"
source = "github.com/rgl/windows-update"
}
}
Expand Down
22 changes: 0 additions & 22 deletions upload/Makefile

This file was deleted.

45 changes: 0 additions & 45 deletions upload/main.build

This file was deleted.

63 changes: 63 additions & 0 deletions upload/main.pkr.hcl
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
}
}
}
11 changes: 0 additions & 11 deletions upload/main.provision

This file was deleted.

0 comments on commit 9bbd819

Please sign in to comment.