Skip to content

Commit

Permalink
feat: use go embed to include static files
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadl0ck committed Apr 14, 2022
1 parent 0dc44a4 commit f2e2e97
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 307 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
pack-data:
go-bindata -o bindata/bindata.go -pkg bindata the-hook/...

build: pack-data
build:
go build -o bin/gograpple cmd/main.go

install: pack-data
install:
go build -o /usr/local/bin/gograpple cmd/main.go

test:
Expand Down
299 changes: 0 additions & 299 deletions bindata/bindata.go

This file was deleted.

33 changes: 30 additions & 3 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package gograpple

import (
"context"
"embed"
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
)

"github.com/foomo/gograpple/bindata"
var (
//go:embed the-hook
bindata embed.FS
)

type Mount struct {
Expand Down Expand Up @@ -69,11 +74,33 @@ func (g Grapple) Patch(repo, image, tag, container string, mounts []Mount) error
}

g.l.Infof("extracting patch files")
const patchFolder = "the-hook"
if err := bindata.RestoreAssets(os.TempDir(), patchFolder); err != nil {

const (
patchFolder = "the-hook"
dockerfileName = "Dockerfile"
patchFileName = "deployment-patch.yaml"
perm = 0700
)

dockerFile, err := bindata.ReadFile(filepath.Join(patchFolder, dockerfileName))
if err != nil {
return err
}
deploymentPatch, err := bindata.ReadFile(filepath.Join(patchFolder, patchFileName))
if err != nil {
return err
}

theHookPath := path.Join(os.TempDir(), patchFolder)
_ = os.Mkdir(theHookPath, perm)
err = os.WriteFile(filepath.Join(theHookPath, dockerfileName), dockerFile, perm)
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(theHookPath, patchFileName), deploymentPatch, perm)
if err != nil {
return err
}

pathedImageName := g.patchedImageName(repo)
g.l.Infof("building patch image with %v:%v", pathedImageName, tag)
Expand Down

0 comments on commit f2e2e97

Please sign in to comment.