Skip to content

Commit 868e2ea

Browse files
authored
Convert from packr2 to go:embed for bundling files, fixes #2343 (#2872)
* Convert from packr2 to go:embed, fixes #2343 * Move some examples to global commands * Move settings path creation to app.Start() instead of post-start action
1 parent 78b0881 commit 868e2ea

File tree

192 files changed

+103
-10104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+103
-10104
lines changed

.ci-scripts/linux_arm64_setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -o errexit
55
# Basic tools
66

77
set -x
8+
export GO_VERSION=1.16.2
89

910
if [ ! -z "${DOCKERHUB_PULL_USERNAME:-}" ]; then
1011
set +x
@@ -22,6 +23,8 @@ echo "capath=/etc/ssl/certs/" >>~/.curlrc
2223

2324
. ~/.bashrc
2425

26+
curl -sSL https://golang.org/dl/go${GO_VERSION}.linux-arm64.tar.gz -o /tmp/go.tgz && sudo rm -rf /usr/local/go && sudo tar -zxf /tmp/go.tgz -C /usr/local
27+
2528
git clone --branch v1.2.1 https://github.com/bats-core/bats-core.git /tmp/bats-core && pushd /tmp/bats-core >/dev/null && sudo ./install.sh /usr/local
2629

2730
# Install mkcert

Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,6 @@ setup:
158158
@mkdir -p $(TESTTMP)
159159
@mkdir -p $(DOWNLOADTMP)
160160

161-
packr2:
162-
docker run -t --rm -u $(shell id -u):$(shell id -g) \
163-
-v "/$(PWD):/workdir$(DOCKERMOUNTFLAG)" \
164-
-v "/$(PWD)/$(GOTMP)/bin:$(S)/go/bin" \
165-
-e GOCACHE="//workdir/$(GOTMP)/.cache" \
166-
-w //workdir/cmd/ddev/cmd \
167-
$(BUILD_IMAGE) packr2
168-
docker run -t --rm -u $(shell id -u):$(shell id -g) \
169-
-v "/$(PWD):/workdir$(DOCKERMOUNTFLAG)" \
170-
-v "/$(PWD)/$(GOTMP)/bin:$(S)/go/bin" \
171-
-e GOCACHE="//workdir/$(GOTMP)/.cache" \
172-
-w //workdir/pkg/ddevapp \
173-
$(BUILD_IMAGE) packr2
174-
175161
# Required static analysis targets used in circleci - these cause fail if they don't work
176162
staticrequired: setup golangci-lint markdownlint mkdocs pyspelling
177163

cmd/ddev/cmd/cmd-packr.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

cmd/ddev/cmd/commands.go

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package cmd
22

33
import (
44
"bufio"
5+
"embed"
56
"fmt"
67
"github.com/drud/ddev/pkg/nodeps"
7-
"io/ioutil"
88
"os"
99
"path"
1010
"path/filepath"
@@ -16,7 +16,6 @@ import (
1616
"github.com/drud/ddev/pkg/fileutil"
1717
"github.com/drud/ddev/pkg/globalconfig"
1818
"github.com/drud/ddev/pkg/util"
19-
"github.com/gobuffalo/packr/v2"
2019
"github.com/mattn/go-isatty"
2120
"github.com/spf13/cobra"
2221
)
@@ -309,60 +308,26 @@ func findDirectivesInScriptCommand(script string) map[string]string {
309308
return directives
310309
}
311310

312-
// populateExamplesCommandsHomeadditions grabs packr2 assets
313-
// When the items in the assets directory are changed, the packr2 command
314-
// must be run again in this directory (cmd/ddev/cmd) to update the saved
315-
// embedded files.
316-
// "make packr2" can be used to update the packr2 cache.
311+
//The bundled assets for the project .ddev directory are in directory dotddev_assets
312+
//The bundled assets for the global .ddev directory are in directory global_dotddev_assets
313+
//go:embed dotddev_assets global_dotddev_assets
314+
var bundledAssets embed.FS
315+
316+
// populateExamplesCommandsHomeadditions grabs embedded assets
317317
func populateExamplesCommandsHomeadditions() error {
318318
app, err := ddevapp.GetActiveApp("")
319319
if err != nil {
320320
return nil
321321
}
322-
box := packr.New("customcommands", "./dotddev_assets")
323-
324-
list := box.List()
325-
for _, file := range list {
326-
localPath := app.GetConfigPath(file)
327-
sigFound, err := fileutil.FgrepStringInFile(localPath, ddevapp.DdevFileSignature)
328-
if sigFound || err != nil {
329-
content, err := box.Find(file)
330-
if err != nil {
331-
return err
332-
}
333-
err = os.MkdirAll(filepath.Dir(localPath), 0755)
334-
if err != nil {
335-
return err
336-
}
337-
err = ioutil.WriteFile(localPath, content, 0755)
338-
if err != nil {
339-
return err
340-
}
341-
}
342-
}
343322

344-
// This brings in both the commands and the homeadditions files
345-
box = packr.New("global_dotddev", "./global_dotddev_assets")
346-
347-
list = box.List()
348-
globalDdevDir := globalconfig.GetGlobalDdevDir()
349-
for _, file := range list {
350-
localPath := filepath.Join(globalDdevDir, file)
351-
sigFound, err := fileutil.FgrepStringInFile(localPath, ddevapp.DdevFileSignature)
352-
if sigFound || err != nil {
353-
content, err := box.Find(file)
354-
if err != nil {
355-
return err
356-
}
357-
err = os.MkdirAll(filepath.Dir(localPath), 0755)
358-
if err != nil {
359-
return err
360-
}
361-
err = ioutil.WriteFile(localPath, content, 0755)
362-
if err != nil {
363-
return err
364-
}
365-
}
323+
err = ddevapp.CopyEmbedAssets(bundledAssets, "dotddev_assets", app.GetConfigPath(""))
324+
if err != nil {
325+
return err
366326
}
327+
err = ddevapp.CopyEmbedAssets(bundledAssets, "global_dotddev_assets", globalconfig.GetGlobalDdevDir())
328+
if err != nil {
329+
return err
330+
}
331+
367332
return nil
368333
}

cmd/ddev/cmd/commands_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// TestCustomCommands does basic checks to make sure custom commands work OK.
2323
func TestCustomCommands(t *testing.T) {
2424
assert := asrt.New(t)
25-
runTime := util.TimeTrack(time.Now(), "ddev list")
25+
runTime := util.TimeTrack(time.Now(), t.Name())
2626

2727
tmpHome := testcommon.CreateTmpDir(t.Name() + "tempHome")
2828
origHome := os.Getenv("HOME")
@@ -68,7 +68,6 @@ func TestCustomCommands(t *testing.T) {
6868
require.NoError(t, err)
6969

7070
assert.FileExists(filepath.Join(projectCommandsDir, "db", "mysql"))
71-
assert.FileExists(filepath.Join(projectCommandsDir, "host", "mysqlworkbench.example"))
7271
out, err := exec.RunCommand(DdevBin, []string{})
7372
assert.NoError(err)
7473
assert.Contains(out, "mysql client in db container")
@@ -185,11 +184,14 @@ func TestCustomCommands(t *testing.T) {
185184
assert.NoError(err, "expected to find command %s for app.Type=%s", c, app.Type)
186185
}
187186

188-
// Make sure that the non-command stuff we installed is there
189-
for _, f := range []string{"db/mysqldump.example", "db/README.txt", "web/README.txt", "host/README.txt", "host/phpstorm.example"} {
190-
assert.FileExists(filepath.Join(projectCommandsDir, f))
187+
// Make sure that the non-command stuff we installed is in globalCommandsDir
188+
for _, f := range []string{"db/mysqldump.example", "db/README.txt", "host/heidisql", "host/mysqlworkbench.example", "host/phpstorm.example", "host/README.txt", "host/sequelace", "host/sequelpro", "host/tableplus", "web/README.txt"} {
191189
assert.FileExists(filepath.Join(globalCommandsDir, f))
192190
}
191+
// Make sure that the non-command stuff we installed is in project commands dir
192+
for _, f := range []string{"db/mysql", "db/README.txt", "host/launch", "host/README.txt", "host/solrtail.example", "solr/README.txt", "solr/solrtail.example", "web/live", "web/README.txt", "web/xdebug"} {
193+
assert.FileExists(filepath.Join(projectCommandsDir, f))
194+
}
193195

194196
// Make sure we haven't accidentally created anything inappropriate in ~/.ddev
195197
assert.False(fileutil.FileExists(filepath.Join(tmpHome, ".ddev", ".globalcommands")))

cmd/ddev/cmd/dotddev_assets/commands/db/mysqldump.example

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)