Skip to content

feat: Bundle UI into coderd; add ./develop.sh script - #28

Merged
bryphe-coder merged 36 commits into
mainfrom
bryphe/feat/bundle-ui
Jan 18, 2022
Merged

bryphe-coder merged 36 commits into
mainfrom
bryphe/feat/bundle-ui

Conversation

@bryphe-coder

@bryphe-coder bryphe-coder commented Jan 15, 2022 •

Copy link
Copy Markdown
Contributor

This change bundles the static assets like we have for v1 - using the embed go package. Fixes #22

In addition, it sets up a development script that runs coderd locally and serves the front-end, with hot-reloading. The script used is v2-dev, which is in a devbin folder:

2022-01-14 17 30 14

NOTE: Like coder/m, recommend adding ~/coder/devbin to the PATH

NOTE: The UI is still placeholder, of course. Need to start testing out a simple, placeholder flow for the new v2 world as a next step

Summary of changes:

  • Add build steps for go in the Makefile
    • Add a step for production build, in which we use the embed tag
    • Add a step for development, which doesn't need the embed tag - so we don't need to build the front-end twice
  • Add next export build step to output front-end artifacts in out
  • Add a site package for go
    • Add embed_static.go and embed.go. This is mostly brought in as-is from v1, except removing some intercom/sentry CSP entries that we aren't using.
  • Add a next development server
  • Add a v2-dev script, that runs coderd and the next dev server side-by-side
  • Use the site package as the fallback handler.
  • Add .gitignore entries for additional build collateral

@bryphe-coder bryphe-coder self-assigned this Jan 15, 2022
Comment thread site/embed_static.go Outdated
Comment on lines +27 to +33
// The `embed` package ignores recursively including directories
// that prefix with `_`. Wildcarding nested is janky, but seems to
// work quite well for edge-cases.
//go:embed out/_next/*/*/*/*
//go:embed out/_next/*/*/*
//go:embed out
var site embed.FS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylecarbs - are you OK with using this same strategy for v2?

This is brought in mostly as-is from v1's embed_static.go , except for removing unnecessary CSP entries for sentry/intercom which aren't integrated yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we create a single .gitkeep in out/_next/static/chunks/pages/app. Then we don't need to do the build flag!

Apart from that, this looks great!

@codecov

codecov Bot commented Jan 15, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #28 (5441d0c) into main (5c49f1f) will decrease coverage by 0.40%.
The diff coverage is 70.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   72.00%   71.60%   -0.41%     
==========================================
  Files          37       38       +1     
  Lines        1304     1486     +182     
  Branches        7        7              
==========================================
+ Hits          939     1064     +125     
- Misses        293      340      +47     
- Partials       72       82      +10     
Flag Coverage Δ
unittest-go-macos-latest 65.16% <70.32%> (+0.92%) ⬆️
unittest-go-ubuntu-latest 70.54% <70.32%> (-1.15%) ⬇️
unittest-go-windows-latest 65.16% <70.32%> (+1.61%) ⬆️
unittest-js 71.01% <ø> (ø)
Impacted Files Coverage Δ
site/embed.go 70.32% <70.32%> (ø)
peer/conn.go 76.14% <0.00%> (-0.92%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c49f1f...5441d0c. Read the comment docs.

Comment thread site/embed_static.go Resolved
Comment thread site/scripts/dev.ts Resolved
Comment thread Makefile Resolved
Comment thread Makefile Resolved
Comment thread Makefile Resolved
Comment thread site/embed_static.go Resolved
Comment thread site/embed_static.go Outdated
Comment on lines +27 to +33
// The `embed` package ignores recursively including directories
// that prefix with `_`. Wildcarding nested is janky, but seems to
// work quite well for edge-cases.
//go:embed out/_next/*/*/*/*
//go:embed out/_next/*/*/*
//go:embed out
var site embed.FS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we create a single .gitkeep in out/_next/static/chunks/pages/app. Then we don't need to do the build flag!

Apart from that, this looks great!

Comment thread site/embed_static.go Resolved
Comment thread site/embed_static.go Resolved
Comment thread site/embed_static.go Resolved
Comment thread site/scripts/dev.ts Resolved
Comment thread site/scripts/dev.ts Resolved
Comment thread site/scripts/dev.ts Resolved
Comment thread Makefile Resolved
Comment thread Makefile Resolved
Comment thread site/embed.go Resolved
Comment thread .github/workflows/coder.yaml Resolved
Comment thread .github/workflows/coder.yaml Resolved
Comment thread site/embed.go Resolved
Comment thread devbin/v2-dev
# Do initial build - a dev build for coderd.
# It's OK that we don't build the front-end before - because the front-end
# assets are handled by the `yarn dev` devserver.
make bin/coderd

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to promote the devbin workflow in v2 until we need it. It became really unmaintainable in v1 due to poor scoping, so I'd prefer to punt this as long as possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just have CODERV2_HOST default to :3000

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty useful for developing the front-end - because you get a hot-reload on top of a live instance. I can just keep it local for now, though.

The main thing I want is to have a simple workflow for front-end developers jumping in - would your expectation be that they just run make bin/coderd; bin/coderd; and then open up yarn dev in a separate terminal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed up the change to default the port to 3000 here: d9c6aeb

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I commented on this, but I guess not!

Thoughts on having develop.sh at the root instead? It's required to contribute anyways, and then is very obvious to users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great to me! Moved devbin/v2-dev -> develop.sh in 237f83e

@kylecarbs kylecarbs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor nits!

Comment thread .gitignore Outdated

# Build
bin/
out/ No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be site/out/?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch - indeed it should: 65d0145

Comment thread Makefile Outdated
Comment on lines +38 to +39
build: site/out bin/coderd
.PHONY: build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep these sorted in alphabetical order. I'll see if there's a Makefile linter we can use!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the change locally for now in 8902599

Comment thread devbin/v2-dev
# Do initial build - a dev build for coderd.
# It's OK that we don't build the front-end before - because the front-end
# assets are handled by the `yarn dev` devserver.
make bin/coderd

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I commented on this, but I guess not!

Thoughts on having develop.sh at the root instead? It's required to contribute anyways, and then is very obvious to users.

Comment thread site/scripts/dev.ts Resolved
@bryphe-coder bryphe-coder changed the title feat: Bundle UI into coderd; add v2-dev script feat: Bundle UI into coderd; add ./develop.sh script Jan 18, 2022
@bryphe-coder
bryphe-coder merged commit 4dc6e35 into main Jan 18, 2022
@bryphe-coder
bryphe-coder deleted the bryphe/feat/bundle-ui branch January 18, 2022 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package v2 UI into coderd with go embed

2 participants