Skip to content

Comments

Reduce publish slug size#20

Open
karlwancl wants to merge 1 commit intojincod:masterfrom
karlwancl:feature_reduce_slug_size
Open

Reduce publish slug size#20
karlwancl wants to merge 1 commit intojincod:masterfrom
karlwancl:feature_reduce_slug_size

Conversation

@karlwancl
Copy link
Contributor

@jincod As I am also having an issue of large slug size similar to #19 , I have implemented logic to reduce the slug size when publish to heroku. In my case, the slug size is reduced from 470MB to 81MB.

It is done by publishing a self-contained dotnet app instead of embedding the whole dotnet core runtime into the slug, hence the great reduction in size. See if you could accept this PR, thanks 😄

@stavro
Copy link

stavro commented Sep 6, 2017

Thank you for working on this! Slug size has been an issue for me as well.

bin/compile Outdated
PROJECT_NAME=$(basename ${PROJECT_FILE%.*})

echo "restore ${PROJECT_FILE}"
dotnet restore $PROJECT_FILE --runtime linux-x64
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed dotnet restore here because dotnet restore is now an implicit command, dotnet publish internally calls dotnet restore, no needs explicit call anymore.

Reference: dotnet/announcements#23


cat << EOT >> ${BUILD_DIR}/Procfile
web: cd \$HOME/heroku_output && ASPNETCORE_URLS='http://+:\$PORT' dotnet "./${PROJECT_NAME}.dll" --server.urls http://+:\$PORT
web: cd \$HOME/heroku_output && chmod +x ${PROJECT_NAME} && ASPNETCORE_URLS='http://+:\$PORT' ./${PROJECT_NAME} --server.urls http://+:\$PORT
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add chmod +x here because the executable generated from dotnet publish does not have "x" permission

Reference: dotnet/sdk#1331

@jincod
Copy link
Owner

jincod commented Sep 10, 2017

Hi @lppkarl

Many thanks for your contribution!

I'll review it.

@chrisanderton
Copy link

@lppkarl I've tried this but it still outputs a .dll (which can't be executed) - is there some additional config i need to change in my project?

@karlwancl
Copy link
Contributor Author

@chrisanderton Maybe you have targeted a wrong framework? The publish command generates executable (with no extension) only when you're targeting netcoreapp instead of netstandard

@chrisanderton
Copy link

hmm @lppkarl i'm targeting netcoreapp1.1 - but tbh i'm not so strong on dotnet - does this only work with 2.0?

@karlwancl
Copy link
Contributor Author

karlwancl commented Sep 16, 2017

@chrisanderton As I see it, --self-contained tag only works for netcoreapp2.0, you may migrate your project from 1.1 to 2.0. See https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/ 😄

@toannguyen83
Copy link

@lppkarl , I'm currently using your pull request link for buildpack and it reduces my heroku app slug size from 430MB to 40MB. My app is .net core app 2.0. Great works!

@jincod
Copy link
Owner

jincod commented Nov 12, 2017

Hi @lppkarl

Would be great to do this feature optional export SELF_CONTAINED=${SELF_CONTAINED:-false} for example. Could you please implement it?

Also I've added env var DOTNET_SKIP_FIRST_TIME_EXPERIENCE (https://github.com/jincod/dotnetcore-buildpack/blob/master/bin/compile#L28) which helps to reduce slug size.

@karlwancl
Copy link
Contributor Author

karlwancl commented Nov 12, 2017

@jincod ya, I could help implement it.

I'm interested in how DOTNET_SKIP_FIRST_TIME_EXPERIENCE help reduces slug size? Is there a mechanism for heroku to cache its installation files or restored file so that the process is not done again for second time onwards?

@jincod
Copy link
Owner

jincod commented Nov 12, 2017

Hi @lppkarl

Thanka a lot! Ping me if you have any questions.

DOTNET_SKIP_FIRST_TIME_EXPERIENCE dotnet core cli option. You can find more info here http://www.erikschierboom.com/2017/03/21/continuous-integration-of-dotnet-core-applications/

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.

5 participants