Skip to content

Commit

Permalink
upgrade to go 1.16 and use go embed
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Feb 21, 2021
1 parent 3434815 commit a3634df
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -10,7 +10,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: '^1.15.0'
go-version: '^1.16.0'
- name: Set up msys2
uses: msys2/setup-msys2@v2
with:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,5 +2,4 @@ dist/
packer-provisioner-windows-update
packer-provisioner-windows-update.exe
tmp*
assets_vfsdata.go
.idea/
7 changes: 2 additions & 5 deletions Makefile
Expand Up @@ -3,7 +3,7 @@ GOEXE := $(shell go env GOEXE)
GOHOSTOS := $(shell go env GOHOSTOS)
GOHOSTARCH := $(shell go env GOHOSTARCH)
GORELEASER := $(GOPATH)/bin/goreleaser
SOURCE_FILES := *.go update/* update/assets_vfsdata.go update/provisioner.hcl2spec.go
SOURCE_FILES := *.go update/* update/provisioner.hcl2spec.go

all: build

Expand All @@ -21,9 +21,6 @@ release: $(GORELEASER) $(SOURCE_FILES)
$(GORELEASER) release --rm-dist
$(MAKE) package-chocolatey

update/assets_vfsdata.go: update/assets_generate.go update/*.ps1
cd update && go run assets_generate.go

# see https://www.packer.io/guides/hcl/component-object-spec/
update/provisioner.hcl2spec.go: update/provisioner.go
go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2
Expand All @@ -46,6 +43,6 @@ install: dist/packer-provisioner-windows-update_$(GOHOSTOS)_$(GOHOSTARCH)/packer
cp -f $< $(HOME)/.packer.d/plugins/$(notdir $<)

clean:
rm -rf dist tmp* update/assets_vfsdata.go
rm -rf dist tmp*

.PHONY: all build release release-snapshot package-chocolatey install clean
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -6,7 +6,7 @@

This is a Packer plugin for installing Windows updates (akin to [rgl/vagrant-windows-update](https://github.com/rgl/vagrant-windows-update)).

**NB** This was only tested with Packer 1.6.1 on Windows Server 2019, macOS Catalina and Ubuntu 20.04.
**NB** This was only tested with Packer 1.7.0 on Windows Server 2019, macOS Catalina and Ubuntu 20.04.

# Usage

Expand Down
8 changes: 4 additions & 4 deletions go.mod
@@ -1,9 +1,9 @@
module github.com/rgl/packer-provisioner-windows-update

require (
github.com/hashicorp/hcl/v2 v2.8.0
github.com/hashicorp/packer-plugin-sdk v0.0.13
github.com/zclconf/go-cty v1.7.0
github.com/hashicorp/hcl/v2 v2.8.2
github.com/hashicorp/packer-plugin-sdk v0.1.0
github.com/zclconf/go-cty v1.7.1
)

go 1.15
go 1.16
222 changes: 218 additions & 4 deletions go.sum

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions update/assets.go

This file was deleted.

27 changes: 0 additions & 27 deletions update/assets_generate.go

This file was deleted.

6 changes: 5 additions & 1 deletion update/elevated.go
Expand Up @@ -3,6 +3,7 @@
package update

import (
_ "embed" // this is needed for using the go:embed directive
"text/template"
)

Expand All @@ -14,6 +15,9 @@ type elevatedOptions struct {
Command string
}

//go:embed elevated-template.ps1
var elevatedTemplatePs1 string

var elevatedTemplate = template.Must(
template.New("Elevated").Parse(
string(MustAsset("elevated-template.ps1"))))
elevatedTemplatePs1))
6 changes: 5 additions & 1 deletion update/provisioner.go
Expand Up @@ -7,6 +7,7 @@ package update
import (
"bytes"
"context"
_ "embed" // this is needed for using the go:embed directive
"encoding/base64"
"errors"
"fmt"
Expand Down Expand Up @@ -35,6 +36,9 @@ const (
retryableDelay = 5 * time.Second
)

//go:embed windows-update.ps1
var windowsUpdatePs1 []byte

type Config struct {
common.PackerConfig `mapstructure:",squash"`

Expand Down Expand Up @@ -151,7 +155,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
ui.Say("Uploading the Windows update script...")
err = comm.Upload(
windowsUpdatePath,
bytes.NewReader(MustAsset("windows-update.ps1")),
bytes.NewReader(windowsUpdatePs1),
nil)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions update/provisioner.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3634df

Please sign in to comment.