Skip to content

Commit

Permalink
Merge pull request #15 from pkorovin/packer_plugin_sdk
Browse files Browse the repository at this point in the history
reads sensible, let's do some progress
  • Loading branch information
double-p authored Sep 20, 2021
2 parents a55b052 + 422def9 commit 846a5f7
Show file tree
Hide file tree
Showing 33 changed files with 903 additions and 473 deletions.
16 changes: 8 additions & 8 deletions builder/openbsd-vmm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"path/filepath"

"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer-plugin-sdk/multistep"
commonsteps "github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

const BuilderID = "packer.openbsd-vmm"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
)

steps = append(steps,
&common.StepHTTPServer{
&commonsteps.StepHTTPServer{
HTTPDir: b.config.HTTPDir,
HTTPPortMin: b.config.HTTPPortMin,
HTTPPortMax: b.config.HTTPPortMax,
Expand Down Expand Up @@ -118,17 +118,17 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
)

steps = append(steps,
&common.StepProvision{},
&commonsteps.StepProvision{},
)

steps = append(steps,
&stepShutdown{},
)

// Run; step-wise if -debug/-on-error=ask
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
b.runner = commonsteps.NewRunner(steps, b.config.PackerConfig, ui)
if b.config.PackerDebug {
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
b.runner = commonsteps.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
}
b.runner.Run(ctx, state)

Expand Down
17 changes: 9 additions & 8 deletions builder/openbsd-vmm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ package openbsdvmm
import (
"fmt"

"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/common/bootcommand"
"github.com/hashicorp/packer/common/shutdowncommand"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
common "github.com/hashicorp/packer-plugin-sdk/common"
"github.com/hashicorp/packer-plugin-sdk/communicator"
commonsteps "github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
"github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/shutdowncommand"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

const (
Expand All @@ -22,7 +23,7 @@ const (

type Config struct {
common.PackerConfig `mapstructure:",squash"`
common.HTTPConfig `mapstructure:",squash"`
commonsteps.HTTPConfig `mapstructure:",squash"`
bootcommand.BootConfig `mapstructure:",squash"`
shutdowncommand.ShutdownConfig `mapstructure:",squash"`

Expand Down
4 changes: 2 additions & 2 deletions builder/openbsd-vmm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strings"
"time"

"github.com/hashicorp/packer/common/bootcommand"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

type Driver interface {
Expand Down
2 changes: 1 addition & 1 deletion builder/openbsd-vmm/ssh.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package openbsdvmm

import (
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer-plugin-sdk/multistep"
)

func CommHost() func(multistep.StateBag) (string, error) {
Expand Down
17 changes: 10 additions & 7 deletions builder/openbsd-vmm/step_bootcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,41 @@ import (
"log"
"time"

"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/common/bootcommand"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

type stepBootCmd struct {
cmd string
BootWait time.Duration
VMName string
ctx interpolate.Context
}

type bootCommandTemplateData struct {
HTTPIP string
HTTPPort int
Name string
}

func (step *stepBootCmd) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
ui := state.Get("ui").(packersdk.Ui)

step_descr := state.Get("step_descr").(string)
httpPort := state.Get("http_port").(int)
hostIP := state.Get("host_ip").(string)

log.Printf("HTTP IP/port: %s:%d", hostIP, httpPort)
common.SetHTTPIP(hostIP)

state.Put("http_ip", hostIP)
step.ctx.Data = &bootCommandTemplateData{
hostIP,
httpPort,
step.VMName,
}

if int64(step.BootWait) > 0 {
Expand Down
5 changes: 2 additions & 3 deletions builder/openbsd-vmm/step_create_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"fmt"
"path/filepath"

"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

type stepCreateDisks struct {
Expand Down
4 changes: 2 additions & 2 deletions builder/openbsd-vmm/step_gen_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"path/filepath"
"strings"

"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/template/interpolate"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

type stepGenFiles struct {
Expand Down
4 changes: 2 additions & 2 deletions builder/openbsd-vmm/step_outdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"path/filepath"

"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

type stepOutDir struct {
Expand Down
4 changes: 2 additions & 2 deletions builder/openbsd-vmm/step_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"log"
"time"

"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

// This step shuts down the machine. It first attempts to do so gracefully,
Expand Down
4 changes: 2 additions & 2 deletions builder/openbsd-vmm/step_start_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"log"
"net"

"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

type stepStartVM struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/etc/httpd.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ server "openbsd.local" {
log style combined
root "/htdocs/openbsd"
location "/snapshots/amd64/" { directory auto index }
location "/snapshots/packages/amd64/" { directory auto index }
location "/snapshots/packages/amd64/all/" { directory auto index }
location "/snapshots/amd64/SHA256.sig" { no log }
}

types { include "/usr/share/misc/mime.types" }
12 changes: 3 additions & 9 deletions examples/etc/unbound/unbound.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $OpenBSD: unbound.conf,v 1.19 2019/11/07 15:46:37 sthen Exp $
# $OpenBSD: unbound.conf,v 1.21 2020/10/28 11:35:58 sthen Exp $

server:
#interface: 127.0.0.1
Expand All @@ -19,12 +19,12 @@ server:
hide-identity: yes
hide-version: yes

# Perform DNSSEC validation. Comment out the below option to disable.
# Perform DNSSEC validation.
#
auto-trust-anchor-file: "/var/unbound/db/root.key"
val-log-level: 2

# Uncomment to synthesize NXDOMAINs from DNSSEC NSEC chains
# Synthesize NXDOMAINs from DNSSEC NSEC chains.
# https://tools.ietf.org/html/rfc8198
#
aggressive-nsec: yes
Expand All @@ -39,12 +39,6 @@ server:
#local-zone: "2.0.192.in-addr.arpa." static
#local-data-ptr: "192.0.2.51 mycomputer.local"

# UDP EDNS reassembly buffer advertised to peers. Default 4096.
# May need lowering on broken networks with fragmentation/MTU issues,
# particularly if validating DNSSEC.
#
#edns-buffer-size: 1480

# Use TCP for "forward-zone" requests. Useful if you are making
# DNS requests over an SSH port forwarding.
#
Expand Down
3 changes: 2 additions & 1 deletion examples/etc/vm.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ switch "local" {

vm generic {
disable
boot device cdrom
owner packer_user
allow instance { boot, cdrom, disk, instance, interface, memory }
memory 1G
Expand All @@ -12,7 +13,7 @@ vm generic {

#vm generic instance dev {
# disable
# memory 4G
# memory 2G
# disk /home/_vmd/openbsd-dev.qcow2
# interface tap { switch "local" }
#}
8 changes: 5 additions & 3 deletions examples/packer.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ XDG_CACHE_HOME=$HOME/.cache
XDG_CONFIG_HOME=$HOME/.config
export XDG_CACHE_HOME XDG_CONFIG_HOME

PKR_VAR_home=$HOME
PKR_VAR_user=$USER

CHECKPOINT_DISABLE=1
PACKER_CACHE_DIR=$XDG_CACHE_HOME/packer
PACKER_CONFIG_DIR=$XDG_CONFIG_HOME/packer
PACKER_CACHE_DIR=$XDG_CACHE_HOME/packer
PACKER_LOG=1
PACKER_LOG_PATH=~/.log/packer.log
PACKER_NO_COLOR=1
export CHECKPOINT_DISABLE PACKER_CACHE_DIR PACKER_CONFIG_DIR PACKER_LOG PACKER_LOG_PATH PACKER_NO_COLOR
export PKR_VAR_home PKR_VAR_user CHECKPOINT_DISABLE PACKER_CACHE_DIR PACKER_CONFIG_DIR PACKER_LOG PACKER_LOG_PATH
32 changes: 0 additions & 32 deletions examples/packer/_http/alpine.autoinstall.pkr.in

This file was deleted.

1 change: 1 addition & 0 deletions examples/packer/_http/authorized_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put your root's authorized key here. It will also be used for packer user.
27 changes: 13 additions & 14 deletions examples/packer/_http/centos.autoinstall.pkr.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,47 @@ cdrom

lang en_US.UTF-8
keyboard us
timezone Europe/Moscow --utc
timezone Europe/Moscow --utc --ntpservers=_gateway

network --hostname={{ .VMName }} --onboot yes --bootproto dhcp --noipv6 --activate
network --hostname=centos --onboot yes --bootproto dhcp --noipv6 --activate
firewall --enabled --service=ssh

zerombr
clearpart --all --initlabel
autopart --type=lvm
bootloader --append="console=ttyS0,115200 no_timer_check net.ifnames=0" --location=mbr
bootloader --append="console=ttyS0,115200 no_timer_check net.ifnames=0 clocksource_failover=acpi_pm" --location=mbr

auth --enableshadow --passalgo=sha512 --kickstart
authselect --useshadow --passalgo sha512
rootpw packer
user --name=p --uid 1001 --gid 1001 --groups=wheel --plaintext --password packer
user --name=packer --uid 1001 --gid 1001 --groups=wheel --plaintext --password packer

selinux --permissive
services --disabled=kdump --enabled=chronyd,rsyslog,sshd

firstboot --disabled
reboot
poweroff

%post --erroronfail
%post --log=/var/log/anaconda/post-install.log --erroronfail
dnf clean all
dnf update -y
sed -i /^HWADDR=.*/d /etc/sysconfig/network-scripts/ifcfg-eth0

mkdir -m 700 /root/.ssh
curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/authorized_keys -o /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
restorecon -R /root/.ssh/
cp -R /root/.ssh /home/packer
chown -R packer.packer /home/p/.ssh
echo "packer ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/packer
%end

%packages --excludedocs
@core
NetworkManager
centos-gpg-keys
centos-stream-repos
chrony
curl
dnf-utils
dracut-config-generic
firewalld
grub2
Expand All @@ -51,10 +56,6 @@ sudo
tar
vim
wget
-biosdevname
-dracut-config-rescue
-iprutils
-irqbalance
-iwl100-firmware
-iwl1000-firmware
-iwl105-firmware
Expand All @@ -70,8 +71,6 @@ wget
-iwl6000g2a-firmware
-iwl6050-firmware
-iwl7260-firmware
-plymouth
-trousers
%end

%addon com_redhat_kdump --disable
Expand Down
Loading

0 comments on commit 846a5f7

Please sign in to comment.