Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Allow buffalo build to extract assets and put them into a zip file #180

Merged
merged 13 commits into from
Feb 1, 2017
Merged

Allow buffalo build to extract assets and put them into a zip file #180

merged 13 commits into from
Feb 1, 2017

Conversation

stanislas-m
Copy link
Member

@stanislas-m stanislas-m commented Jan 26, 2017

This PR implements issue #170.

Signed-off-by: Stanislas Michalak <stanislas.michalak@gmail.com>
Signed-off-by: Stanislas Michalak <stanislas.michalak@gmail.com>
@stanislas-m
Copy link
Member Author

stanislas-m commented Jan 28, 2017

This PR added a "-e" flag to the build command. This flag extracts assets and put them into a zip file, in the bin directory (next to the executable). The bin directory is also cleaned before build.

The flag also disable the route handling for assets. You can catch "/assets" queries with NGINX, Apache... and serve them from another location (even from CDN, using a redirect).

Further improvements can include a custom function in templates to prefix assets with a custom location, or a default "/assets" path.

@stanislas-m stanislas-m changed the title WIP: Allow buffalo build to extract assets and put them into a zip file Allow buffalo build to extract assets and put them into a zip file Jan 28, 2017
@markbates
Copy link
Member

Thanks. I'll pull this down and play with it when I get to my computer. In the mean time @philipithomas did a great PR yesterday fixing some linting issues. I think there a few things that will need to be fixed in here. Can you please run 'docker build .' to make sure everything is good? Thanks.

@stanislas-m
Copy link
Member Author

stanislas-m commented Jan 28, 2017

Sure. The Docker build succeed:

Step 23/23 : RUN buffalo build
 ---> Running in 7650b2612edc
Buffalo version 0.7.1

--> cleaning up target dir
--> running node_modules/.bin/webpack
Hash: 05d30489a12e5b644c7a
Version: webpack 1.14.0
Time: 3051ms
                                 Asset     Size  Chunks             Chunk Names
af7ae505a9eed503f8b8e6982036873e.woff2  77.2 kB          [emitted]  
  f4769f9bdb7466be65088239c12046d1.eot  20.1 kB          [emitted]  
 fa2772327f55d8198301fdb8bcfc8158.woff  23.4 kB          [emitted]  
  e18bbf611f2a2e43afc071aa2f4e1512.ttf  45.4 kB          [emitted]  
  89889688147bd7575d6327160d64e760.svg   109 kB          [emitted]  
  674f50d287a8c48dc19ba404d20fe713.eot   166 kB          [emitted]  
448c34a56d699c29117adc64c43affeb.woff2    18 kB          [emitted]  
 fee66e712a8a08eef5805a46892932ad.woff    98 kB          [emitted]  
  b06871f281fee6b241d60582ae9369b9.ttf   166 kB          [emitted]  
  912ec66d7572ff821749319396470bde.svg   444 kB          [emitted]  
                        application.js   372 kB       0  [emitted]  main
                       application.css   183 kB       0  [emitted]  main
                       images/logo.svg    66 kB          [emitted]  
   [0] multi main 52 bytes {0} [built]
    + 21 hidden modules
Child extract-text-webpack-plugin:
        + 15 hidden modules
--> running go build -v -o bin/hello_world -ldflags -X main.version="2017-01-28T09:20:15Z" -X main.buildTime="2017-01-28T09:20:15Z"
hello_world/a
hello_world/actions
hello_world
--> cleaning up build
----> cleaning up buffalo_build_main.go
----> cleaning up a
----> cleaning up a/a.go
----> cleaning up a/database.go
----> cleaning up buffalo_build_main.go
 ---> b2c8f7408451
Removing intermediate container 7650b2612edc
Successfully built b2c8f7408451

@stanislas-m
Copy link
Member Author

And if I add a new RUN command to test the new option:

Step 24/24 : RUN buffalo build -e
 ---> Running in d04df7e438c6
Buffalo version 0.7.1

--> cleaning up target dir
----> cleaning up hello_world
--> running node_modules/.bin/webpack
Hash: 05d30489a12e5b644c7a
Version: webpack 1.14.0
Time: 3029ms
                                 Asset     Size  Chunks             Chunk Names
af7ae505a9eed503f8b8e6982036873e.woff2  77.2 kB          [emitted]  
  f4769f9bdb7466be65088239c12046d1.eot  20.1 kB          [emitted]  
 fa2772327f55d8198301fdb8bcfc8158.woff  23.4 kB          [emitted]  
  e18bbf611f2a2e43afc071aa2f4e1512.ttf  45.4 kB          [emitted]  
  89889688147bd7575d6327160d64e760.svg   109 kB          [emitted]  
  674f50d287a8c48dc19ba404d20fe713.eot   166 kB          [emitted]  
448c34a56d699c29117adc64c43affeb.woff2    18 kB          [emitted]  
 fee66e712a8a08eef5805a46892932ad.woff    98 kB          [emitted]  
  b06871f281fee6b241d60582ae9369b9.ttf   166 kB          [emitted]  
  912ec66d7572ff821749319396470bde.svg   444 kB          [emitted]  
                        application.js   372 kB       0  [emitted]  main
                       application.css   183 kB       0  [emitted]  main
                       images/logo.svg    66 kB          [emitted]  
   [0] multi main 52 bytes {0} [built]
    + 21 hidden modules
Child extract-text-webpack-plugin:
        + 15 hidden modules
--> build assets archive
--> disable self assets handling
--> running go build -v -o bin/hello_world -ldflags -X main.version="2017-01-28T09:33:04Z" -X main.buildTime="2017-01-28T09:33:04Z"
hello_world/a
hello_world/actions
hello_world
--> cleaning up build
----> cleaning up buffalo_build_main.go
----> cleaning up a
----> cleaning up a/a.go
----> cleaning up a/database.go
----> cleaning up buffalo_build_main.go
 ---> b88388ea9c65
Removing intermediate container d04df7e438c6
Successfully built b88388ea9c65

@markbates
Copy link
Member

Ah yes, that is because #189 hasn't been merged yet. There's still 1 outstanding issue with it. I'm waiting for that to be merged before merging other PRs. I'll pull this down and play with it on the plane.

@markbates
Copy link
Member

markbates commented Jan 28, 2017

I got an error:

$ buffalo build -e
Buffalo version 0.7.1

--> cleaning up target dir
--> running node_modules/.bin/webpack
Hash: c3e73e81c3f1e1d2d97e
Version: webpack 1.14.0
Time: 3006ms
                                 Asset     Size  Chunks             Chunk Names
         fonts/fontawesome-webfont.ttf   166 kB          [emitted]  
  f4769f9bdb7466be65088239c12046d1.eot  20.1 kB          [emitted]  
 fa2772327f55d8198301fdb8bcfc8158.woff  23.4 kB          [emitted]  
  e18bbf611f2a2e43afc071aa2f4e1512.ttf  45.4 kB          [emitted]  
  89889688147bd7575d6327160d64e760.svg   109 kB          [emitted]  
  674f50d287a8c48dc19ba404d20fe713.eot   166 kB          [emitted]  
af7ae505a9eed503f8b8e6982036873e.woff2  77.2 kB          [emitted]  
 fee66e712a8a08eef5805a46892932ad.woff    98 kB          [emitted]  
  b06871f281fee6b241d60582ae9369b9.ttf   166 kB          [emitted]  
  912ec66d7572ff821749319396470bde.svg   444 kB          [emitted]  
                        application.js   372 kB       0  [emitted]  main
                       application.css   335 kB       0  [emitted]  main
         fonts/fontawesome-webfont.eot   166 kB          [emitted]  
448c34a56d699c29117adc64c43affeb.woff2    18 kB          [emitted]  
        fonts/fontawesome-webfont.woff    98 kB          [emitted]  
         fonts/fontawesome-webfont.svg   444 kB          [emitted]  
       fonts/fontawesome-webfont.woff2  77.2 kB          [emitted]  
                 fonts/FontAwesome.otf   135 kB          [emitted]  
                images/404_example.png   120 kB          [emitted]  
                images/500_example.png   411 kB          [emitted]  
                   images/logo_med.png   157 kB          [emitted]  
                       images/logo.png   366 kB          [emitted]  
                       images/logo.svg    66 kB          [emitted]  
           images/gophertrain_logo.svg  1.22 MB          [emitted]  
                  images/uncle_sam.jpg  20.5 kB          [emitted]  
                       images/repl.gif  6.15 MB          [emitted]  
   [0] multi main 52 bytes {0} [built]
    + 23 hidden modules
Child extract-text-webpack-plugin:
        + 17 hidden modules
--> build assets archive
--> cleaning up build
----> cleaning up buffalo_build_main.go
----> cleaning up a
----> cleaning up a/a.go
----> cleaning up a/database.go
----> cleaning up buffalo_build_main.go
Error: open bin/gobuffalo-assets.zip: no such file or directory

@markbates
Copy link
Member

It works if I already have a bin directory, which might always be the case.

@stanislas-m
Copy link
Member Author

Then we can ensure the bin directory existence. I just looked at the -o option which "set the name of the binary". In fact, this option allows to generate the binary wherever you want: is this option provided to change only the name of the executable? (then, we will have to fix the -o behavior to put the result in the bin dir, with the given name)

If it's not the case, maybe we must put the assets archive in the same location and ensure its existence.

@markbates
Copy link
Member

@stanislas-m there are some conflicts with main, can you resolve them so i can merge? thanks.

@markbates
Copy link
Member

Just saw your questions about the -o flag. That's being passed to the go build tool, but this PR should respect that flag and put the assets in wherever that flag points to. That would mean creating that directory, if it doesn't exist.

@stanislas-m
Copy link
Member Author

Okay! Then I'm going to fix that.

@stanislas-m
Copy link
Member Author

Hum, I forgot something. Please wait for the merge. :)

@stanislas-m
Copy link
Member Author

stanislas-m commented Jan 29, 2017

@markbates Seems ok now.

@markbates markbates merged commit 1cf5cf2 into gobuffalo:master Feb 1, 2017
@markbates
Copy link
Member

Great work on this! Sorry it took so long to get merged!

@stanislas-m stanislas-m deleted the 170-allow-assets-split-on-build branch February 4, 2017 12:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants