Giter Site home page Giter Site logo

heroku-buildpack-phoenix-static's Introduction

Phoenix Static Buildpack

Purpose

This buildpack is meant to be used with the Heroku Buildpack for Elixir. When deploying Phoenix apps to Heroku, static assets will need to be compiled. This buildpack sees to it that static assets are compiled and that a corresponding asset manifest is generated.

Features

  • Easily customizable to your build needs with its compile hook!
  • Works much like the Heroku Buildpack for Elixir!
  • Easy configuration with phoenix_static_buildpack.config file
  • Automatically sets DATABASE_URL
  • If your app doesn't have a Procfile, default web task mix phx.server will be run
  • Can configure versions for Node and NPM
  • Auto-installs Bower deps if bower.json is in your app's root path
  • Caches Node, NPM modules and Bower components

Usage

# Create a Heroku instance for your project
heroku apps:create my_heroku_app

# Set and add the buildpacks for your Heroku app
heroku buildpacks:set https://github.com/HashNuke/heroku-buildpack-elixir
heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static

# Deploy
git push heroku master

Serve with Sass assets

If your project serves Sass assets, you need the sass binary for sass-brunch via ruby buildpack.

Create a Gemfile to include the sass gem:

source 'https://rubygems.org'
ruby '2.3.1'
gem 'sass'

Then run generate the Gemfile.lock:

bundle install

Finally, add the ruby buildpack.

# Add the ruby buildpack to your Heroku app
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ruby

Configuration

Create a phoenix_static_buildpack.config file in your app's root dir if you want to override the defaults. The file's syntax is bash.

If you don't specify a config option, then the default option from the buildpack's phoenix_static_buildpack.config file will be used.

Here's a full config file with all available options:

# Clean out cache contents from previous deploys
clean_cache=false

# We can change the filename for the compile script with this option
compile="compile"

# We can set the version of Node to use for the app here
node_version=5.3.0

# We can set the version of NPM to use for the app here
npm_version=2.10.1

# We can set the version of Yarn to use for the app here
yarn_version=1.13.0

# We can set the path to phoenix app. E.g. apps/phoenix_app when in umbrella.
phoenix_relative_path=.

# Remove node and node_modules directory to keep slug size down if it is not needed.
remove_node=false

# We can change path that npm dependencies are in relation to phoenix app. E.g. assets for phoenix 1.3 support.
assets_path=.

# We can change phoenix mix namespace tasks. E.g. `phoenix` for phoenix < 1.3 support.
phoenix_ex=phx

Compile

By default, Phoenix uses brunch and recommends you to use mix phx.digest in production. For that, we have a default compile shell script which gets run after building dependencies and just before finalizing the build. The compile file looks like this.

To customize your app's compile hook, just add a compile file to your app's root directory. compile is just a shell script, so you can use any valid bash code. Keep in mind you'll have access to your node_modules and mix. This means that if you're using a Node build tool other than brunch, you can just do something like:

# app_root/compile
cd $phoenix_dir
npm --prefix ./assets run build
mix "${phoenix_ex}.digest" #use the ${phoenix_ex} variable instead of hardcoding phx or phoenix

The above compile overrides the default one. :)

FAQ

  1. When to use?
  • This buildpack is only necessary when you need to compile static assets during deploys. You will not need this buildpack if you are using Phoenix only as a REST API.
  1. Do I need heroku-buildpack-nodejs with this?
  • No, this buildpack installs Node for you. How it differs from the NodeJS buildpack is that it adds mix to the PATH so you can run mix commands like mix phx.digest.
  1. I am getting an error Command "deploy" not found. even though my previous deploys used to work. How to fix?
  • The default compile file, which are a set of commands ran during the buildpack's compile hook, was replaced to be compatible with Phoenix versions 1.4 and above. If using brunch and older versions of Phoenix, you will need to add a custom compile in your app's root directory that looks like:
brunch build --production

cd $phoenix_dir

mix "${phoenix_ex}.digest"

if mix help "${phoenix_ex}.digest.clean" 1>/dev/null 2>&1; then
  mix "${phoenix_ex}.digest.clean"
fi

heroku-buildpack-phoenix-static's People

Contributors

aaronjensen avatar acconrad avatar adsteel avatar asymmetric avatar behe avatar blakewilliams avatar cgorshing avatar chrismccord avatar col avatar ebkh avatar ericmj avatar gjaldon avatar iloveitaly avatar jesseshieh avatar jsmestad avatar nathf avatar rickclare avatar seantanly avatar thewoolleyman avatar tsubery avatar vircung avatar vysogot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-buildpack-phoenix-static's Issues

Loading modules from subdirectories of assets/js/

An error of "Could not load module" is thrown when my app.js file tries to import from files in subdirectories of assets/js/. The full line of the error:

Processing of js/app.js failed. Error: Could not load module './components/Something' from '/tmp/build_a1b2c3da3caa70b06872f08019710b7d/assets/js'. Make sure the file actually exists.

The offending line of code is import Something from "./components/Something".

I'm using brunch, and the error is thrown during brunch build --production.

If I only import from files in the same directory as app.js and comment out imports from subdirectories, the brunch build works fine.

Do not require Brunch

Currently, the readme states that you can use other build tools than Brunch in your postcompile script — but this buildpack is only activated if you do actually have a brunch-config.js file present. This is not necessarily the case, if you switched to Gulp or Webpack or something.

should `default_process_type` pick up my buildpack.config's `phoenix_ex` value?

In the readme says:

# We can change phoenix mix namespace tasks. E.g. phx for phoenix 1.3 support.
phoenix_ex=phoenix

But, even if I put phoenix_ex=phx into my phoenix_static_buildpack.config file,
if im not explicitly creating a Procfile to run web: mix phx.server
will default to run phoenix.server. that confused me for a while...

I guess, it's because of the content of bin/release:

default_process_types:
  web: mix phoenix.server

Then I can see in my logs: app[web.1] mix phoenix.webserver is deprecated. Use phx.server instead.

It's possible to tell the buildpack to catch this phoenix_ex value to insert it into the default line?
or state this behavior on the cited line of the readme?

Don't install node/npm

Is it possible to not install node/npm with this buildpack? I only need to serve static assets.

Error R10 -> Web process failed to bind to $PORT within 60 seconds of launch

Hello guys!
I need serious help here, because I've already tried a lot - a very f lot - of things (including the #23 issue and others the google could find - different of him, my apps never works) to figure this out and got absolutely nothing. I don't even know if here is the right place to put it.

I am trying to deploy an app to heroku. I just create a regular phoenix 1.3 app and before start digging in my production code I like to make all the surrounds (db, acceptance tests, unit tests, deploy...) being ready. So there's almost nothing yet in my code besides what mix phx.new creates.

The few things I've changed was to prepare the app to be deployed to heroku. And I will show you what they are in a minute.

Following the phoenix guide on deploy to heroku I'm always ending up with this:

2018-01-20T13:38:30.289635+00:00 heroku[web.1]: State changed from crashed to starting
2018-01-20T13:38:36.199270+00:00 heroku[web.1]: Starting process with command `MIX_ENV=prod mix phx.server`
2018-01-20T13:39:36.561334+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-01-20T13:39:36.561424+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-01-20T13:39:36.674779+00:00 heroku[web.1]: Process exited with status 137
2018-01-20T13:39:36.689698+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-20T13:39:36.691037+00:00 heroku[web.1]: State changed from crashed to starting
2018-01-20T13:39:43.205253+00:00 heroku[web.1]: Starting process with command `MIX_ENV=prod mix phx.server`
2018-01-20T13:40:43.448578+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-01-20T13:40:43.448702+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-01-20T13:40:43.556983+00:00 heroku[web.1]: Process exited with status 137
2018-01-20T13:40:43.571869+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-20T13:40:45.543186+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=arcane-inlet-84609.herokuapp.com request_id=e4f881fc-714a-44dc-aa7d-1cda1bf3302d fwd="189.5.92.192" dyno= connect= service= status=503 bytes= protocol=https
2018-01-20T13:40:46.095610+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=arcane-inlet-84609.herokuapp.com request_id=73fd7237-8955-402a-9e4c-4935d2b69fcd fwd="189.5.92.192" dyno= connect= service= status=503 bytes= protocol=https

Sometimes, and I don't know why, I get a slightly different output:

2018-01-20T13:25:21.790935+00:00 heroku[web.1]: Starting process with command `MIX_ENV=prod mix phx.server`
2018-01-20T13:25:42.330456+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=arcane-inlet-84609.herokuapp.com request_id=97105890-900c-49fe-83db-2feab6552795 fwd="189.5.92.192" dyno= connect= service= status=503 bytes= protocol=https
2018-01-20T13:26:22.212939+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2018-01-20T13:26:22.281500+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-20T13:26:22.167596+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-01-20T13:26:22.167693+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-01-20T13:26:22.265385+00:00 heroku[web.1]: Process exited with status 22
2018-01-20T13:26:24.369615+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=arcane-inlet-84609.herokuapp.com request_id=005cb8e2-e13d-480b-b1c2-a0f968d38a4b fwd="189.5.92.192" dyno= connect= service= status=503 bytes= protocol=https
2018-01-20T13:26:24.960618+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=arcane-inlet-84609.herokuapp.com request_id=8bec1069-760a-471e-93a8-66a5dc297391 fwd="189.5.92.192" dyno= connect= service= status=503 bytes= protocol=https

I've tried (some of them was just to see if something changed, but no success):

  • Destroy and Create a new app;
  • Set config_vars_to_export;
  • Change Procfile MIX_ENV=prod mix phx.server to:
    • MIX_ENV=prod mix phoenix.server;
    • MIX_ENV=dev mix phx.server;
    • MIX_ENV=dev mix deps.get && mix phx.server
    • mix phx.server;
  • Set always_rebuild=true
  • Remove the elixir-buildpack.config and phoenix-static-buildpack.config¹ ;
  • Init another phoenix app unrelated with the first one;
  • Oh, the list goes on and on... I already forgot the most part of what I did till now;

I just can't figure out what is wrong.

My configuration is:

  • Docker container where elixir, phoenix, node and heroku-cli are installed;
  • Erlang 20.2.2
  • Elixir 1.6.0
  • Phoenix 1.3
  • Node 8.9.4
  • heroku-cli 6.15.17

The mix phx.server works just fine in localhost. That's why I chose here to present my really painful pain.

¹ I've create those *-buildpack.config to use the same version on heroku that my dev environment has - because I saw that the buildpacks works with older versions os erlang, elixir, phoenix, node... But this don't make difference because I removed those files and the error kept happening.

I, in advance, appreciate and thanks all of you who take the time to help.

Node modules cache push rejected

Hi!

I haven't touched my project for some time. I just wanted to push it to heroku with minimal changes but it does not work anymore. I'm not using any node modules in this project / I have no node_modules folder in my project. Any idea on how to get it running? Thanks!

remote:
remote: -----> Building dependencies
remote: Installing and caching node modules
remote: cp: cannot stat ‘/app/tmp/cache/node_modules/*’: No such file or directory
remote: ! Push rejected, failed to compile Phoenix app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:

Install sass

This buildpack should probably install sass as well, because when we import @compass in our scss files, heroku fails to build.

remote:        Running default compile
remote:        You need to have Sass on your system
remote:        Execute `gem install sass`

Register in buildpack registry

My name is Jon Byrum and I’m a product manager at Heroku. Your buildpack is one of the top 200 most popular buildpacks on Heroku!

I would like to invite you to publish your buildpack early in our Buildpack Registry, before it is made available to the general public (expected early July).

To register your buildpack, visit: https://addons-next.heroku.com/buildpacks
Documentation: https://devcenter.heroku.com/articles/buildpack-registry

Why register?

  • By registering early you’ll be able to grab your preferred namespace for the buildpack
  • After registering, your buildpack will be available to all Heroku users when they run heroku buildpacks:search. In the future, we will only display registered buildpacks on elements.heroku.com/buildpacks
  • The Buildpack Registry makes it easy for you to publish a new version of your buildpack, as well as roll back if there are errors

Recommended naming conventions:

  • We recommend that you use the same namespace (e.g., jbyrum) with Buildpack Registry that you use on GitHub
  • In general, avoid using "buildpack" in the name of your registered buildpack
    • For example: If your Github repo is github.com/foobar/heroku-buildpack-elixir, then we recommend a name like "foobar/elixir"

It would be greatly appreciated if you could publish before June 18th, as we prepare to make the feature publicly available. Registering a buildpack should take approximately 5 minutes.

If you have any questions about registering (or run into any issues), please email:
[email protected]

NPM errors when deploying umbrella application

Hi!

I'm trying to deploy a umbrella application to Heroku, but I'm getting error messages:

npm ERR! addLocal Could not install /tmp/build_7b768e9efd1d658613a08beb7fffbf0e/deps/phoenix
npm ERR! addLocal Could not install /tmp/build_7b768e9efd1d658613a08beb7fffbf0e/deps/phoenix_html

phoenix_static_buildpack.config

clean_cache=true
compile="compile phoenix_static_buildpack.compile"
node_version=6.9.2
phoenix_relative_path=apps/web
remove_node=true

phoenix_static_buildpack.compile

info "Building Phoenix static assets"
brunch build --production
mix phoenix.digest

elixir_buildpack.config

erlang_version=19.2
elixir_version=1.4.0
always_rebuild=true

Been googling it for a while, but I can't figure what the issue is. Any ideas?

Thanks!

Both mix and bower are reported missing

remote:        Installing and caching bower components
remote: /tmp/buildpack_ad5f44cd6c8fb01d0c454ac5859d228b/lib/build.sh: line 70: bower: command not found
remote: cp: cannot stat ‘bower_components’: No such file or directory
remote:        Running default compile
remote:               Building Phoenix static assets
remote:        [BABEL] Note: The code generator has deoptimised the styling of "bower_components/angular/angular.js" as it exceeds the max of "100KB".
remote:        [BABEL] Note: The code generator has deoptimised the styling of "bower_components/jquery/dist/jquery.js" as it exceeds the max of "100KB".
remote:        [BABEL] Note: The code generator has deoptimised the styling of "bower_components/angular-bootstrap/ui-bootstrap-tpls.js" as it exceeds the max of "100KB".
remote:        07 Jul 04:43:16 - info: compiled 8 files into 2 files in 27408ms
remote:        /tmp/buildpack_ad5f44cd6c8fb01d0c454ac5859d228b/compile: line 3: mix: command not found
remote:
remote: -----> Finalizing build
remote:        Creating runtime environment
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 21.7MB
remote: -----> Launching... done, v11

npm ERR! missing script: deploy

For information I got this issue when I was trying to build a release on Heroku :

remote:        npm WARN package.json @ No license field.
remote:        Running default compile
remote:        npm ERR! Linux 3.13.0-95-generic
remote:        npm ERR! argv "/tmp/build_f361e7ba77e3cb9/.heroku/node/bin/node" "/tmp/build_f361e7ba77e3cb9b/.heroku/node/bin/npm" "run" "deploy"
remote:        npm ERR! node v5.3.0
remote:        npm ERR! npm  v3.3.12
remote:        
remote:        npm ERR! missing script: deploy
remote:        npm ERR!
remote:        npm ERR! If you need help, you may report this error at:
remote:        npm ERR!     <https://github.com/npm/npm/issues>
remote:        
remote:        npm ERR! Please include the following file with any support request:
remote:        npm ERR!     /tmp/build_f361e7ba77e3cb99262f/npm-debug.log
remote:  !     Push rejected, failed to compile Phoenix app.

UPDATE:
to fix it you need to do the following steps:

  • into your project phoenix
  • open package.json
  • add a new "deploy": "brunch build --production" into scripts (if scripts you can create like the example below)
{
  "scripts": {
    "deploy": "brunch build --production"
  },
  "repository": {
    ...
  },
  "dependencies": {
    ...
  }
}

Support Elm

I think Elm is great and would be happy to support it for people wanting to use Elm with Phoenix.

Error deploying Phoenix under umbrella

I'm having trouble deploying a Phoenix app when it is under an umbrella project. Below are the errors from console. Am I missing something?

If it isn't currently supported, what can we do to support it?

The umbrella app is available at https://github.com/seantanly/elixir-myumbrella

When not using umbrella, the same deployment configurations works. https://github.com/seantanly/elixir-webfront

Errors from console (myumbrella),

=====> Downloading Buildpack: https://github.com/gjaldon/heroku-buildpack-phoenix-static
=====> Detected Framework: Phoenix

-----> Loading configuration and environment
       Loading config...
       Will use the following versions:
       * Node 5.6.0
       Will export the following config vars:
       * Config vars DATABASE_URL
       * MIX_ENV=prod

-----> Installing binaries
       Using cached node 5.6.0...
       Installing node 5.6.0...
       Using default npm version

-----> Building dependencies
       Installing and caching node modules
remote: cp: cannot stat '/cache/node_modules/*': No such file or directory
       npm WARN enoent ENOENT: no such file or directory, open '/tmp/build/package.json'
       npm WARN build No description
       npm WARN build No repository field.
       npm WARN build No README data
       npm WARN build No license field.
       npm ERR! Linux 3.13.0-71-generic
       npm ERR! argv "/tmp/build/.heroku/node/bin/node" "/tmp/build/.heroku/node/bin/npm" "--unsafe-perm" "prune"
       npm ERR! node v5.6.0
       npm ERR! npm  v3.6.0
       npm ERR! path /tmp/build/package.json
       npm ERR! code ENOENT
       npm ERR! errno -2
       npm ERR! syscall open

       npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build/package.json'
       npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build/package.json'
       npm ERR! enoent This is most likely not a problem with npm itself
       npm ERR! enoent and is related to npm not being able to find a file.
       npm ERR! enoent

       npm ERR! Please include the following file with any support request:
       npm ERR!     /tmp/build/npm-debug.log
       Running default compile
       /tmp/buildpackclV6M/compile: line 1: brunch: command not found
       warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)
==> webfront
       The input path "priv/static" does not exist

Error with Phoenix 1.1.2

With the latest version of Phoenix 1.1.2, seem that there are major changes to the way the default Phoenix js/css files are included. CHANGELOG UPGRADE INSTRUCTIONS

I'm getting the following errors even though I have set custom settings for Node, NPM and compile commands. Unfortunately, I'm not too familiar with how the static assets build process works to give more info what went wrong or how to fix it.

phoenix_static_buildpack.config

node_version=5.4.0
npm_version=3.3.12
config_vars_to_export=(DATABASE_URL)
compile="phoenix_static_buildpack.compile"

phoenix_static_buildpack.compile

info "Building Phoenix static assets"
brunch build --production
mkdir -p priv/static
mix phoenix.digest

Errors from console,

-----> Loading configuration and environment
       Loading config...
       Will use the following versions:
       * Node 5.4.0
       Will export the following config vars:
       * Config vars DATABASE_URL
       * MIX_ENV=prod

-----> Installing binaries
       Downloading node 5.4.0...
       Installing node 5.4.0...
       Using default npm version

-----> Building dependencies
       Installing and caching node modules
       npm ERR! addLocal Could not install /cache/deps/phoenix
       npm ERR! addLocal Could not install /cache/deps/phoenix_html
       npm ERR! Linux 3.13.0-71-generic
       npm ERR! argv "/tmp/build/.heroku/node/bin/node" "/tmp/build/.heroku/node/bin/npm" "install" "--quiet" "--unsafe-perm" "--userconfig" "/tmp/build/npmrc"
       npm ERR! node v5.4.0
       npm ERR! npm  v3.3.12
       npm ERR! path /cache/deps/phoenix
       npm ERR! code ENOENT
       npm ERR! errno -2
       npm ERR! syscall open

       npm ERR! enoent ENOENT: no such file or directory, open '/cache/deps/phoenix'
       npm ERR! enoent This is most likely not a problem with npm itself
       npm ERR! enoent and is related to npm not being able to find a file.
       npm ERR! enoent

       npm ERR! Please include the following file with any support request:
       npm ERR!     /cache/npm-debug.log
       npm WARN package.json @ No description
       npm WARN package.json @ No README data
       npm WARN package.json @ No license field.
remote: cp: cannot stat ‘node_modules’: No such file or directory

Sometimes problem binding to Heroku's port

I ran into Heroku's R10 error twice; once deleting the heroku instance and recreating it fixed it, the second time I was able to fix it by deleting the buildpacks, reinstalling them, and pushing an empty commit.

https://stackoverflow.com/questions/36229118/phoenix-on-heroku-error-r10

I don't know if this buildpack is the root of the problem, but it was part of the fix process both times; I'm hoping that you have enough knowledge to point me in the right direction so I can help make sure this gets fixed for everyone.

Stop the deploy if asset building fails?

I have a small non-production app I'm building and the assets failed to compile on deploy when using this buildpack, but the deploy continued on anyways leading to a deploy with broken assets.

Could this be fixed by adding set -e to prevent the scripts from advancing when a command fails?

Error during install node modules

Hello! I'm using this buildpack with compile file containing

clean_cache=false
node_version=8.2.1
npm_verion=8.3.0

And getting the error:

remote: -----> Building dependencies
remote:        Installing and caching node modules
remote: npm ERR! May not delete: /tmp/build_64d71392f6c23caa02fdbb7eb310ea89/node_modules/.bin
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /app/.npm/_logs/2017-07-28T01_57_28_739Z-debug.log
remote:  !     Push rejected, failed to compile Phoenix app.

Can you help me realise what is going wrong. Thanks!

Delete node after compile

Similar to #34 most projects won't need node after compile so there's no reason to keep it around. It can at least be an option.

I'm happy to contribute either or both of these if you think they'd be good additions.

Error during npm package install, node_modules directory not found

I'm using an npm script... to generate my production assets (not brunch) and I was consistently getting a stat indicating the node_modules directory did not exist. The error is happening on this line: https://github.com/gjaldon/heroku-buildpack-phoenix-static/blob/master/lib/build.sh#L91

I fixed the error by prepending the $build_dir to the directory name as shown here: https://github.com/ntilwalli/heroku-buildpack-phoenix-static/blob/master/lib/build.sh#L111

I dunno if this only surfaces for people not using brunch or webpack, but since no one else has complained it seems that way. Any thoughts? Does this merit a PR?

Specifying node_version causes build to fail

Hi. Thanks for providing this tool! When I tried specifying a node_version=6.9.1 in my phoenix_static_buildpack.config I consistently go errors like:

-----> Creating .profile.d with env vars
-----> Writing export for multi-buildpack support
-----> Phoenix app detected
-----> Loading configuration and environment
       Loading config...
       Will use the following versions:
       * Node 6.9.1
       Will export the following config vars:
       * Config vars DATABASE_URL
       * MIX_ENV=prod
-----> Installing binaries
       Downloading node 6.9.1
 !     Push rejected, failed to compile Phoenix app.
 !     Push failed

When I did not specify a node_version the build proceeded properly.

getting No such file or directory error

assets build failed during heroku deployment,any idea on how to fix this?

remote: -----> Creating .profile.d with env vars
remote: -----> Writing export for multi-buildpack support
remote: -----> Phoenix app detected
remote:
remote: -----> Loading configuration and environment
remote:        Loading config...
remote:        Detecting assets directory
remote:        WARNING: no package.json detected in root nor custom directory
remote:        * assuming phoenix 1.3.x and later, please check config file
remote:        Will use phoenix configuration:
remote:        * assets path assets
remote:        * mix tasks namespace phx
remote:        Will use the following versions:
remote:        * Node 5.3.0
remote:        Will export the following config vars:
remote: BUILDPACK_URL
remote: DATABASE_URL
remote: MIX_ENV
remote: POOL_SIZE
remote: SECRET_KEY_BASE
remote:        * MIX_ENV=prod
remote:
remote: -----> Installing binaries
remote:        Downloading node 5.3.0...
remote:        Installing Node 5.3.0...
remote:        Using default npm version
remote:
remote: -----> Building dependencies
remote:        Installing and caching node modules
remote: /app/tmp/buildpacks/abc8fb9e8be131ec2574c4ba9e31b81540d97b3bbce47d96e05959c4f81404ac71605dd35ebbcf7a1abe958c346d8ee266ff035de9254424eb54e8b9480059be/lib/build.sh: line 105: cd: /tmp/build_aba384b288d92ff204dc221530cb9e9d/./assets: No such file or directory
remote:  !     Push rejected, failed to compile Phoenix app.
remote:
remote:  !     Push failed
remote: Verifying deploy...

phoenix_static_buildpack.config present but not seen

Hi,

I have an umbrella phoenix app, following phoenix 1.3 conventions.

remote: -----> Creating .profile.d with env vars
remote: -----> Writing export for multi-buildpack support
remote: -----> Phoenix app detected
remote:
remote: -----> Loading configuration and environment
remote:        Loading config...
remote:        WARNING: phoenix_static_buildpack.config wasn't found in the app
remote:        Using default config from Phoenix static buildpack
remote:        Detecting assets directory
remote:        WARNING: no package.json detected in root nor custom directory
remote:        * assuming phoenix 1.3.x and later, please check config file
remote:        Will use phoenix configuration:
remote:        * assets path assets
remote:        * mix tasks namespace phx
remote:        Will use the following versions:
remote:        * Node 6.9.2
remote:        Will export the following config vars:

phoenix_static_buildpack.config wasn't found in the app but i have created this file at the root of my app

\apps
\config
.gitignore
mix.exs
phoenix_static_buildpack.config
Procfile
README.md

I don't understand

any help ?

Support for Phoenix 1.3

As from version 1.3 phoenix moved it's node dependencies to assets directory which invalidates current build process.

Delete node_modules after compile

There usually isn't any reason to include node_modules in your slug, so they should be nuked or it should at least be optional. It looks like compile runs after caching, so I'm going to add it to my compile step for now.

deployment to heroku failed

remote: -----> Phoenix app detected
remote: 
remote: -----> Loading configuration and environment
remote:        Loading config...
remote:        WARNING: phoenix_static_buildpack.config wasn't found in the app
remote:        Using default config from Phoenix static buildpack
remote:        Will use the following versions:
remote:        * Node 5.3.0
remote:        Will export the following config vars:
remote:        * Config vars DATABASE_URL
remote:        * MIX_ENV=prod
remote: 
remote: -----> Installing binaries
remote:        Downloading node 5.3.0...
remote:        Installing Node 5.3.0...
remote:        Using default npm version
remote: 
remote: -----> Building dependencies
remote:        Installing and caching node modules
remote:        npm ERR! addLocal Could not install /tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/deps/phoenix
remote:        npm ERR! addLocal Could not install /tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/deps/phoenix_html
remote:        npm ERR! Linux 3.13.0-95-generic
remote:        npm ERR! argv "/tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/.heroku/node/bin/node" "/tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/.heroku/node/bin/npm" "install" "--quiet" "--unsafe-perm" "--userconfig" "/tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/npmrc"
remote:        npm ERR! node v5.3.0
remote:        npm ERR! npm  v3.3.12
remote:        npm ERR! path /tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/deps/phoenix
remote:        npm ERR! code ENOENT
remote:        npm ERR! errno -2
remote:        npm ERR! syscall open
remote:        
remote:        npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/deps/phoenix'
remote:        npm ERR! enoent This is most likely not a problem with npm itself
remote:        npm ERR! enoent and is related to npm not being able to find a file.
remote:        npm ERR! enoent
remote:        
remote:        npm ERR! Please include the following file with any support request:
remote:        npm ERR!     /tmp/build_5aa4e14fed9e18b8bc7ab9aa45593848/npm-debug.log
remote:  !     Push rejected, failed to compile Phoenix app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to guarded-inlet-14629.
remote: 
To https://git.heroku.com/guarded-inlet-14629.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/guarded-inlet-14629.git'

I tried an answer in the issues to change package.json but still got the same error!

Node version error

Sorry if I am misjudging the issue but I will try and provide as much information as I can.
-I have attempted to increase my node version through the buildpack to 10.10.0/8.11.2 as I have some
nested javascript files that need to be running a higher version.(Being done through buildpacks config)

-When I push to Heroku and it does it's CI test's I get this error while in test setup

 cp: cannot overwrite directory '/tmp/cache050174931/node_modules/phoenix' with non-directory
 cp: cannot overwrite directory '/tmp/cache050174931/node_modules/phoenix_html' with non-directory

(which error's out the CI test)
-This issue appears to be coming from within the install_and_cache_deps function of the lib/build.sh file

install_and_cache_deps() {
  info "Installing and caching node modules"
  cd $assets_dir
  if [ -d $cache_dir/node_modules ]; then
    mkdir -p node_modules
    cp -r $cache_dir/node_modules/* node_modules/
  fi

 if [ -f "$assets_dir/yarn.lock" ]; then
   install_yarn_deps
 else
   install_npm_deps
 fi

 cp -r node_modules $cache_dir
 PATH=$assets_dir/node_modules/.bin:$PATH
 install_bower_deps
}

-The code will make it through the first cp command of the app without complication but when it reaches time to do the second cp command this issue occurs.

Am I missing something obvious or is this an issue with the buildpack and current versions of node?

If you need any more information please let me know and thank you in advance for any help you can provide

Include assets from previous build(s)

At the moment, if you deploy a new version of a site with newly fingerprinted assets, the old assets will no longer be available.

This is not a problem if:

  1. They're cached on a CDN (not guaranteed, even if you have a CDN)
  2. You're not doing any dynamic loading of assets (theoretically even a regular page load could break if one of its assets it required became unavailable)

For other cases, especially SPAs with dynamic code loading this is a big problem.

I believe the rails build pack includes assets from past builds, though I'm not sure of the specifics. Ideally we could configure the number of old builds to maintain or a max age (I don't know if heroku's cache maintains file ages).

Thoughts on something like this? Thanks!

Support for multiple phoenix applications under an Umbrella App

So, I run multiple phoenix applications and each have their own assets.

To get around cd'ing into all the different applications and running the npm deploy script in each..

I just have a custom compile script that looks like this:

cd $build_dir
mix cmd "npm install || true"
mix cmd "npm run deploy || true"
mix phoenix.digest

You can run mix cmd which will run the command in each of all the child applications.

mix phoenix.digest also does run in all of the phoenix applications as well.

I feel like you can use these same commands in a single application, and even in umbrella applications.

how do I disable assets?

I have a socket/channel only app, so I don't have any sockets. Currently, when I try to deploy, I get the following error:

remote: -----> Building dependencies
remote:        Installing and caching node modules
remote: /app/tmp/buildpacks/9c47a362692688524e86000de35251234726449a19851f29f82387b8d8b2da550db082b36e99243f82a708aff896040ed9c7dc1c8d5bc89a74e6c0d234c486ad/lib/build.sh: line 105: cd: /tmp/build_6556d2d319c05df4d700e85466a5c262/./assets: No such file or directory
remote:  !     Push rejected, failed to compile Phoenix app.

here is my phoenix_static_buildpack.config

# Clean out cache contents from previous deploys
clean_cache=false

# We can change the filename for the compile script with this option
compile="compile"

# Remove node and node_modules directory to keep slug size down if it is not needed.
remove_node=true

# We can set the path to phoenix app. E.g. apps/phoenix_app when in umbrella.
phoenix_relative_path=.

# We can change phoenix mix namespace tasks. E.g. phx for phoenix 1.3 support.
phoenix_ex=phoenix

only install js production dependencies

Currently the buildpack will install all dependencies including devDependencies.
Is it possible to just install production dependencies ?
for yarn it's a matter of supplying --production flag for npm it's --only=production if I remember well.

Complains about missing Brunch, but I am using Webpack

remote:        Running default compile
remote:        /app/tmp/buildpacks/9c47a362692688524e86000de35251234726449a19851f29f82387b8d8b2da550db082b36e99243f82a708aff896040ed9c7dc1c8d5bc89a74e6c0d234c486ad/compile: line 1: brunch: command not found
remote:  !     Push rejected, failed to compile Phoenix app.
remote:
remote:  !     Push failed

Any ideas?

Not necessary npm or ecto

Just curios 😄 I tried deployment on heroku after generating a Phoenix app by mix phoenix.new app_name --no-brunch --no-ecto 😃 but I saw it's still installing node by the default config. How can I config not to have it? 😄 Thank you

Assets are not compiled in an umbrella project

Hi,

I have a similar problem like in #22 and in #21. I tried these described fixes there, but that didn't help :(.

So this is the log from the console:

    remote: -----> Creating .profile.d with env vars
    remote: -----> Writing export for multi-buildpack support
    remote: -----> Fetching set buildpack https://github.com/gjaldon/heroku-buildpack-phoenix-static.git... done
    remote: -----> Phoenix app detected
    remote:
    remote: -----> Loading configuration and environment
    remote:        Loading config...
    remote:        Will use the following versions:
    remote:        * Node 5.3.0
    remote:        Will export the following config vars:
    remote:        * Config vars DATABASE_URL
    remote:        * MIX_ENV=prod
    remote:
    remote: -----> Installing binaries
    remote:        Downloading node 5.3.0...
    remote:        Installing node 5.3.0...
    remote:        Using default npm version
    remote:
    remote: -----> Building dependencies
    remote:        Installing and caching node modules
    remote:        npm ERR! addLocal Could not install /tmp/build_66b1378fa026372e48b85ad01cd87044/apps/my_phoenix_app/deps/phoenix
    remote:        npm ERR! addLocal Could not install /tmp/build_66b1378fa026372e48b85ad01cd87044/apps/my_phoenix_app/deps/phoenix_html
    remote:        npm ERR! Linux 3.13.0-85-generic
    remote:        npm ERR! argv "/tmp/build_66b1378fa026372e48b85ad01cd87044/.heroku/node/bin/node" "/tmp/build_66b1378fa026372e48b85ad01cd87044/.heroku/node/bin/npm" "install" "--quiet" "--unsafe-perm" "--userconfig" "/tmp/build_66b1378fa026372e48b85ad01cd87044/npmrc"
    remote:        npm ERR! node v5.3.0
    remote:        npm ERR! npm  v3.3.12
    remote:        npm ERR! path /tmp/build_66b1378fa026372e48b85ad01cd87044/apps/my_phoenix_app/deps/phoenix
    remote:        npm ERR! code ENOENT
    remote:        npm ERR! errno -2
    remote:        npm ERR! syscall open
    remote:
    remote:        npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_66b1378fa026372e48b85ad01cd87044/apps/my_phoenix_app/deps/phoenix'
    remote:        npm ERR! enoent This is most likely not a problem with npm itself
    remote:        npm ERR! enoent and is related to npm not being able to find a file.
    remote:        npm ERR! enoent
    remote:
    remote:        npm ERR! Please include the following file with any support request:
    remote:        npm ERR!     /tmp/build_66b1378fa026372e48b85ad01cd87044/apps/my_phoenix_app/npm-debug.log
    remote:        npm WARN package.json @ No license field.
    remote: cp: cannot stat ‘node_modules’: No such file or directory
    remote:        Running default compile
    remote:        /tmp/buildpack20160516-166-kt4k5o/compile: line 1: brunch: command not found
    remote:        ==> data_manager
    remote:        Compiled lib/data_manager/hashing.ex
    remote:        Compiled lib/data_manager.ex
    remote:        Compiled lib/data_manager/read.ex
    remote:        Generated data_manager app
    remote:        The input path "priv/static" does not exist
    remote:        ==> my_phoenix_app
    remote:
    remote: -----> Finalizing build
    remote:        Creating runtime environment
    remote:
    remote: -----> Discovering process types
    remote:        Procfile declares types     -> (none)
    remote:        Default types for buildpack -> web
    remote:
    remote: -----> Compressing...
    remote:        Done: 86.5M
    remote: -----> Launching...
    remote:        Released v13

Phoenix buildpack does not seem to defer to MIX_ENV set in Heroku.

Hello, thanks for all your hard work with this buildpack!

I'm using the multi-buildpack solution outlined in the README and I'd like to set up a staging server on Heroku.

I set MIX_ENV to beta using heroku config:set MIX_ENV=beta --app tsf-pix-beta.

The Elixir buildpack recognizes this:

remote: -----> Multipack app detected
remote: -----> Fetching custom git buildpack... done
remote: -----> elixir app detected
remote: -----> Checking Erlang and Elixir versions
remote:        Will use the following versions:
remote:        * Stack cedar-14
remote:        * Erlang 17.5
remote:        * Elixir 1.0.5
remote:        Will export the following config vars:
remote:        * Config vars MIX_ENV DATABASE_URL
remote:        * MIX_ENV=beta

But, later on down the build, the Phoenix buildpack reports otherwise:

remote: Generated tsf_pix app
remote: -----> Creating .profile.d with env vars
remote: -----> Fetching custom git buildpack... done
remote: -----> Phoenix app detected
remote:
remote: -----> Loading configuration and environment
remote:        Loading config...
remote:        Will use the following versions:
remote:        * Node 0.12.4
remote:        Will export the following config vars:
remote:        * Config vars MIX_ENV DATABASE_URL
remote:        * MIX_ENV=prod
remote:
remote: -----> Installing binaries
remote:        Downloading node 0.12.4...
remote:        Installing node 0.12.4...
remote:        Using default npm version

This is preventing me from setting up a different environment config file with alternate settings for staging. Any ideas?

Thanks!

Conditionally install Ruby

If a version of Ruby is specified in config, then install that version of ruby. Sometimes sass will need the Ruby SASS gem instead of libsass.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.