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

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

Merged
merged 36 commits into from
Jan 18, 2022

Conversation

bryphe-coder
Copy link
Contributor

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

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 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
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
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
Copy link

codecov bot commented Jan 15, 2022

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.

site/embed_static.go Outdated Show resolved Hide resolved
site/scripts/dev.ts Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
site/embed_static.go Outdated Show resolved Hide resolved
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
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!

site/embed_static.go Outdated Show resolved Hide resolved
site/embed_static.go Outdated Show resolved Hide resolved
site/embed_static.go Outdated Show resolved Hide resolved
site/scripts/dev.ts Outdated Show resolved Hide resolved
site/scripts/dev.ts Outdated Show resolved Hide resolved
site/scripts/dev.ts Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
site/embed.go Outdated Show resolved Hide resolved
.github/workflows/coder.yaml Outdated Show resolved Hide resolved
.github/workflows/coder.yaml Outdated Show resolved Hide resolved
site/embed.go Show resolved Hide resolved
devbin/v2-dev Outdated
# 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
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
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
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
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
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
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

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

A few minor nits!

.gitignore Outdated
# Build
bin/
out/
Copy link
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
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

Makefile Outdated
Comment on lines 38 to 39
build: site/out bin/coderd
.PHONY: build
Copy link
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
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

devbin/v2-dev Outdated
# 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
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.

site/scripts/dev.ts Outdated Show resolved Hide 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