Skip to content

Use go-bindata to embed public and templates files into binary #5920

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

Merged
merged 17 commits into from
Feb 17, 2020

Conversation

alimy
Copy link

@alimy alimy commented Feb 12, 2020

  1. use go-bindata pack up public and templates files into gogs binary then no need public/templates file in gogs work directory.
  2. after this patch will make gogs update more convenience.
  3. after make relealse the package will just contain files below:
% tree -L  1 gogs
gogs
├── LICENSE
├── README.md
├── README_ZH.md
├── gogs
└── scripts

@alimy
Copy link
Author

alimy commented Feb 12, 2020

To install the newest go-bindata, use the following:

% go get -u github.com/go-bindata/go-bindata/...

@unknwon
Copy link
Member

unknwon commented Feb 12, 2020

Thanks for the PR!

According to https://github.com/gogs/gogs/blob/master/conf/README.md, you should use https://github.com/kevinburke/go-bindata. Can you verify the result is the same? Or re-generate if necessary.

@unknwon unknwon added the status: needs feedback Tell me more about it label Feb 12, 2020
@alimy
Copy link
Author

alimy commented Feb 12, 2020

sorry, I don't notice the go-bindata need use github.com/kevinburke/go-bindata. Compare github.com/go-bindata/go-bindata, the github.com/kevinburke/go-bindata not support generate create http.FileSystem instance code by go-bindata -fs ... that PR supported by github.com/go-bindata/go-bindata.

This patch depend go-bindata generate a function to returan a http.FileSystem in internal/assets/public so have 3 solutions fix this patch:

  1. use github.com/go-bindata/go-bindata to generate static files.
  2. commit a PR to github.com/kevinburke/go-bindata to support generate create http.FileSystem instance code like PR.I will do this later but need github.com/kevinburke/go-bindata to merge.
  3. add a custom function in native to create a http.FileSystem instance from generated static public files code.

I think github.com/go-bindata/go-bindata is good same as github.com/kevinburke/go-bindata so how about use github.com/go-bindata/go-bindata as our generate tool.

@unknwon
Copy link
Member

unknwon commented Feb 12, 2020

I think github.com/go-bindata/go-bindata is good same as github.com/kevinburke/go-bindata so how about use github.com/go-bindata/go-bindata as our generate tool.

Gogs used to use github.com/go-bindata/go-bindata but has changed to use github.com/kevinburke/go-bindata because that's the one installed by brew install go-bindata.

3. add a custom function in native to create a http.FileSystem instance from generated static public files code.

I think this is my preferred solution.

Besides, (I haven't looked at code in detail), it would be nice to have:

  1. In dev mode, it reads directly from the file system.
  2. In non-dev mode, it reads from what's been embedded.

@alimy
Copy link
Author

alimy commented Feb 12, 2020

Had optimize patch:

  1. use github.com/kevinburke/go-bindata as generate tool.
  2. add a custom function to instance a http.FileSystem from generated static public assets code.
  3. add ENABLE_ASSETS = true item in configure file to support either enable use embedded public and templates assets (not use RUN_MODE item because sometimes we just test enable embedded public assets feature in dev mode and other scenes).

@unknwon unknwon changed the title optimize use go-bindata pack up public and templates files into gogs binary Use go-bindata to embed public and templates files into binary Feb 12, 2020
@unknwon unknwon added status: waits for review It is waiting to be reviewed by maintainers and removed status: needs feedback Tell me more about it labels Feb 12, 2020
@unknwon
Copy link
Member

unknwon commented Feb 16, 2020

Thanks again for the contribution!

PS: If you think you don't have bandwidth work on this in the coming week, LMK! I'll push changes to this PR. I want to get this merged :)

@alimy
Copy link
Author

alimy commented Feb 17, 2020

Thanks your suggestions. I had update the patch and welcome optimize the code :)

@unknwon unknwon self-requested a review February 17, 2020 11:28
@unknwon unknwon added status: waits for QA The changes looks good, just need some sanity check from maintainers status: reviewed It has been reviewed by maintainers and removed status: waits for review It is waiting to be reviewed by maintainers labels Feb 17, 2020
@unknwon
Copy link
Member

unknwon commented Feb 17, 2020

OK, I think I'm happy with the current state, merging!

@unknwon unknwon merged commit 4d83fd4 into gogs:master Feb 17, 2020
@ozzi-
Copy link

ozzi- commented Sep 2, 2020

Is there any possibility to edit the templates without recompiling?
Background, we used a custom home template adding a logo and different text.

@unknwon
Copy link
Member

unknwon commented Sep 3, 2020

@ozzi- A restart of Gogs is all you need if you are editing files under custom/ directory.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: reviewed It has been reviewed by maintainers status: waits for QA The changes looks good, just need some sanity check from maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants