Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move ui back into monorepo #1467

Merged
merged 12 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

## Issues

Let me know how I can help!
Let us know how we can help!

* Include any **stack traces** with your error
* List versions you are using: Flipt, Go, OS, etc.
* List the contents of your Flipt configuration file. (ex: default.yml)

## Code

It's always best to open an issue before investing a lot of time into a
fix or new functionality.
It's always best to open a dialogue before investing a lot of time into a fix or new functionality.

Functionality must meet the design goals and vision for the project to be accepted; I would be happy to discuss how your idea can best fit into Flipt.
Functionality must meet the design goals and vision for the project to be accepted; we would be happy to discuss how your idea can best fit into the future of Flipt.

Join our [Discord](https://www.flipt.io/discord) to chat with the team about any feature ideas or open a [Discussion](https:/flipt-io/flipt/discussions) here on GitHub.

### Conventional Commits

We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages. Please adhere to this specification when contributing.

## Testing

Expand Down
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ updates:
# kodiak `merge.automerge_label`
- "automerge"

- package-ecosystem: npm
directory: '/ui'
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: '*'
update-types:
- version-update:semver-major
labels:
- 'dependencies'
- 'javascript'
# kodiak `merge.automerge_label`
- 'automerge'

- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ jobs:
with:
node-version: "18"

- uses: actions/checkout@v3
with:
repository: flipt-io/flipt-ui
path: .build/ui

- uses: magefile/mage-action@v2
with:
version: latest
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ jobs:
input: "rpc/flipt"
against: "https:/${GITHUB_REPOSITORY}.git#branch=main"

ui-lint:
name: "Lint UI"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
cache-dependency-path: ui/package-lock.json

- name: Lint
run: |
npm ci
npm run lint
working-directory: ui

go-mod-tidy:
name: "Go Mod Tidy"
runs-on: ubuntu-latest
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ jobs:
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin

- uses: actions/checkout@v3
with:
repository: flipt-io/flipt-ui
path: .build/ui

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ jobs:
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin

- uses: actions/checkout@v3
with:
repository: flipt-io/flipt-ui
path: .build/ui

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ jobs:
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin

- uses: actions/checkout@v3
with:
repository: flipt-io/flipt-ui
path: .build/ui

- uses: magefile/mage-action@v2
with:
version: latest
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:

jobs:
test:
name: Test
name: "Tests (Go)"
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -38,6 +38,24 @@ jobs:
- name: Upload Coverage
uses: codecov/[email protected]

ui:
name: "Tests (UI)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
cache-dependency-path: ui/package-lock.json

- name: Unit Test
run: |
npm ci
npm run test
working-directory: ui

database:
name: Database Test
runs-on: ubuntu-latest
Expand Down
6 changes: 2 additions & 4 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ After changing `flipt.proto`, you'll need to run `mage proto`. This will regener

The UI is built using [NPM](https://nodejs.org/en/) and [Vite](https://vitejs.dev/) and is also statically compiled into the Flipt binary using [go:embed](https://golang.org/pkg/embed/).

The UI code has been migrated to it's own repository: [flipt-ui](https:/flipt-io/flipt-ui), clone it somewhere on your machine and follow the instructions in the README to get started.

To develop the project with the UI also in development mode (with hot reloading):

1. Run `npm run dev` where you have the `flipt-ui` repository checked out. This will start a development server on port `5173` and proxy API requests to the Flipt API on port `8080`.
1. Run `npm run dev` from the `ui` directory. This will start a development server on port `5173` and proxy API requests to the Flipt API on port `8080`.
2. Run `mage dev` from the this repository. This will create a dev build that will serve the UI from the development server, while still making it accessible on port `8080`.
3. Run the binary with the local config: `./bin/flipt --config ./config/local.yml`. This will enable CORS with the correct configuration and start the server on port `8080`.
4. Visit `http://localhost:8080` to see the UI.
5. Any changes made in the `flipt-ui` repository will be picked up by the development server and the UI will be reloaded.
5. Any changes made in the `ui` directory will be picked up by the development server and the UI will be reloaded.

### Ports

Expand Down
3 changes: 1 addition & 2 deletions hack/build/internal/flipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Base(ctx context.Context, client *dagger.Client, req FliptRequest) (*dagger
)
}

// add base dependencies to intialize project with
// add base dependencies to initialize project with
src := client.Host().Directory(".", dagger.HostDirectoryOpts{
Include: includes,
})
Expand Down Expand Up @@ -147,7 +147,6 @@ func Base(ctx context.Context, client *dagger.Client, req FliptRequest) (*dagger
// which is used to embed the built frontend
// distribution directory.
"./ui/",
"./.build/",
"./bin/",
"./.git/",
},
Expand Down
48 changes: 7 additions & 41 deletions hack/build/internal/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,17 @@ import (
"context"
"crypto/sha256"
"fmt"
"os"
"strings"

"dagger.io/dagger"
)

func parseUIRepoPath(ctx context.Context, client *dagger.Client, path string) (*dagger.Directory, error) {
protocol, path, found := strings.Cut(path, "://")
if !found {
return nil, fmt.Errorf("protocol required: %q", path)
}

switch protocol {
case "file":
return client.Host().Directory(path, dagger.HostDirectoryOpts{
Exclude: []string{
"./dist/",
"./node_modules/",
},
}), nil
case "git", "http", "https":
default:
return nil, fmt.Errorf("unexpected protocol: %q", protocol)
}

path, ref, _ := strings.Cut(path, "#")
if ref == "" {
ref = "main"
}

var treeOpts dagger.GitRefTreeOpts
if protocol == "git" {
treeOpts.SSHAuthSocket = client.Host().UnixSocket(os.Getenv("SSH_AUTH_SOCK"))
}

return client.Git(protocol + "://" + path).
Branch(ref).
Tree(treeOpts), nil
}

func UI(ctx context.Context, client *dagger.Client, path string) (*dagger.Container, error) {
src, err := parseUIRepoPath(ctx, client, path)
if err != nil {
return nil, err
}
func UI(ctx context.Context, client *dagger.Client) (*dagger.Container, error) {
src := client.Host().Directory("./ui/", dagger.HostDirectoryOpts{
Exclude: []string{
"./dist/",
"./node_modules/",
},
})

contents, err := src.File("package-lock.json").Contents(ctx)
if err != nil {
Expand Down
10 changes: 1 addition & 9 deletions hack/build/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func daggerClient(ctx context.Context) (*dagger.Client, error) {
}

func newRequest(ctx context.Context, client *dagger.Client, platform dagger.Platform) (internal.FliptRequest, error) {
ui, err := internal.UI(ctx, client, uiRepositoryPath())
ui, err := internal.UI(ctx, client)
if err != nil {
return internal.FliptRequest{}, err
}
Expand All @@ -249,14 +249,6 @@ func newRequest(ctx context.Context, client *dagger.Client, platform dagger.Plat
return internal.NewFliptRequest(dist, platform, internal.WithWorkDir(workDir())), nil
}

func uiRepositoryPath() string {
if path := os.Getenv("FLIPT_UI_PATH"); path != "" {
return path
}

return "https:/flipt-io/flipt-ui.git"
}

func workDir() string {
curDir, err := os.Getwd()
if err != nil {
Expand Down
60 changes: 2 additions & 58 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,62 +213,7 @@ func (u UI) Build() error {
fmt.Println("Generating assets...")

cmd := exec.Command("npm", "run", "build")
cmd.Dir = ".build/ui"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to build UI: %w", err)
}

return sh.RunV("mv", ".build/ui/dist", "ui")
}

// Clone clones the UI repo with an optional branch
func (u UI) Clone() error {
if err := os.MkdirAll(".build", 0755); err != nil {
return fmt.Errorf("failed to create dir: %w", err)
}

if _, err := os.Stat(".build/ui/.git"); os.IsNotExist(err) {
if err := sh.RunV("git", "clone", "https:/flipt-io/flipt-ui.git", ".build/ui"); err != nil {
return fmt.Errorf("failed to clone UI repo: %w", err)
}
}

return nil
}

// Sync syncs the UI repo
func (u UI) Sync() error {
mg.Deps(u.Clone)
fmt.Println("Syncing UI repo...")

branch := "main"
if os.Getenv("FLIPT_BUILD_UI_BRANCH") != "" {
branch = os.Getenv("FLIPT_BUILD_UI_BRANCH")
}

cmd := exec.Command("git", "pull", "--all")
cmd.Dir = ".build/ui"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to pull UI repo: %w", err)
}

cmd = exec.Command("git", "checkout", branch)
cmd.Dir = ".build/ui"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to checkout branch %s: %w", branch, err)
}

cmd = exec.Command("git", "pull")
cmd.Dir = ".build/ui"
cmd.Dir = "ui"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand All @@ -277,12 +222,11 @@ func (u UI) Sync() error {

// Deps installs UI deps
func (u UI) Deps() error {
mg.Deps(u.Sync)
fmt.Println("Installing UI deps...")

// TODO: only install if package.json has changed
cmd := exec.Command("npm", "ci")
cmd.Dir = ".build/ui"
cmd.Dir = "ui"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
Expand Down
Loading