Skip to content

Commit

Permalink
all: add --local-frontend, upd docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed May 21, 2021
1 parent 619ee7c commit b1a4809
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to
## [v0.107.0] - 2021-06-28 (APPROX.)
-->

### Added

- New flag `--local-frontend` to serve dinamically changeable frontend files
from disk as opposed to the ones that were compiled into the binary.

### Deprecated

<!--
Expand Down
2 changes: 1 addition & 1 deletion bamboo-specs/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'key': 'AHBRTSPECS'
'name': 'AdGuard Home - Build and run tests'
'variables':
'dockerGo': 'adguard/golang-ubuntu:3.0'
'dockerGo': 'adguard/golang-ubuntu:3.1'

'stages':
- 'Tests':
Expand Down
26 changes: 17 additions & 9 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,23 @@ func setupConfig(args options) {
}
}

func initWeb(clientBuildFS fs.FS) (web *Web, err error) {
clientFS, err := fs.Sub(clientBuildFS, "build/static")
if err != nil {
return nil, fmt.Errorf("getting embedded client subdir: %w", err)
}
func initWeb(args options, clientBuildFS fs.FS) (web *Web, err error) {
var clientFS, clientBetaFS fs.FS
if args.localFrontend {
log.Info("warning: using local frontend files")

clientBetaFS, err := fs.Sub(clientBuildFS, "build2/static")
if err != nil {
return nil, fmt.Errorf("getting embedded beta client subdir: %w", err)
clientFS = os.DirFS("build/static")
clientBetaFS = os.DirFS("build2/static")
} else {
clientFS, err = fs.Sub(clientBuildFS, "build/static")
if err != nil {
return nil, fmt.Errorf("getting embedded client subdir: %w", err)
}

clientBetaFS, err = fs.Sub(clientBuildFS, "build2/static")
if err != nil {
return nil, fmt.Errorf("getting embedded beta client subdir: %w", err)
}
}

webConf := webConfig{
Expand Down Expand Up @@ -345,7 +353,7 @@ func run(args options, clientBuildFS fs.FS) {
log.Fatalf("Can't initialize TLS module")
}

Context.web, err = initWeb(clientBuildFS)
Context.web, err = initWeb(args, clientBuildFS)
if err != nil {
log.Fatal(err)
}
Expand Down
15 changes: 15 additions & 0 deletions internal/home/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type options struct {
// noEtcHosts flag should be provided when /etc/hosts file shouldn't be
// used.
noEtcHosts bool

// localFrontend forces AdGuard Home to use the frontend files from disk
// rather than the ones that have been compiled into the binary.
localFrontend bool
}

// functions used for their side-effects
Expand Down Expand Up @@ -234,6 +238,16 @@ var noEtcHostsArg = arg{
serialize: func(o options) []string { return boolSliceOrNil(o.noEtcHosts) },
}

var localFrontendArg = arg{
description: "Use local frontend directories.",
longName: "local-frontend",
shortName: "",
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.localFrontend = true; return o, nil },
effect: nil,
serialize: func(o options) []string { return boolSliceOrNil(o.localFrontend) },
}

func init() {
args = []arg{
configArg,
Expand All @@ -247,6 +261,7 @@ func init() {
noCheckUpdateArg,
disableMemoryOptimizationArg,
noEtcHostsArg,
localFrontendArg,
verboseArg,
glinetArg,
versionArg,
Expand Down

0 comments on commit b1a4809

Please sign in to comment.