mars / create-react-app-buildpack

⚛️ Heroku Buildpack for create-react-app: static hosting for React.js web apps
MIT License
3.29k stars 653 forks source link

Doesn't work on Dokku #54

Closed thomasjonas closed 7 years ago

thomasjonas commented 7 years ago

I understand this build pack is meant for Heroku, not Dokku. But since I found more Dokku issues here I though I might as well add another one.

The first problem I ran into was a missing Procfile (like here: https://github.com/mars/create-react-app-inner-buildpack/issues/5) which I solved by adding a completely empty Procfile. I have no idea if that's the right solution, but I would know what command to run (npm start? or should I add serve as a dependency and run serve -s build?).

Then I ran into a new problem:

remote: App container failed to start!!
=====> ysp-frontend-staging web container output:
       Injecting runtime env into /app/build/static/js/main.0c045b2b.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.0c045b2b.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.0c045b2b.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.0c045b2b.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
=====> end ysp-frontend-staging web container output

This problem I fixed by adjusting scaling the process and worker both to 0. The logs show the application is successfully deployed but it's not running. When I run dokku ls it outputs the following:

App Name                  Container Type            Container Id              Status
ysp-frontend-staging      NOT_DEPLOYED              NOT_DEPLOYED              NOT_DEPLOYED

Hopefully anybody has an idea of where it's going wrong. I have the feeling it has something to do with the Procfile...

Full deploy/build log for completeness:

-----> Cleaning up...
-----> Building ysp-dokku from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Checking deploymentkeys Plugin sanity ...
-----> Installing shared SSH keys in build environment ...
-----> Checking Hostkeys Plugin sanity ...
-----> Installing Hostkeys in build environment ...
       No app keys available.
       Adding shared keys.
-----> Done Installing Hostkeys in build environment ...
       Added the following keys:
       |1|DYiRGBSBQHw93GSvYPUyZfzOuqU=|5bu9kV9UhbxRtddsh477m6bTIbw= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9
|1|4LuwcR2ZEbXkXAnb5wXyhidWBMY=|uDnQCyZrDxBLshNjuU9q4hycnj4= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=
|1|5ad70KLvVrvKbWbruqUzvGP9Cr0=|yYMu2jwzdnPC/FUAcUc2Uh2MPR4= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf
-----> Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
       Detected buildpacks: multi nodejs
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/mars/create-react-app-buildpack.git
=====> Detected Framework: React.js (create-react-app) multi
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
=====> Detected Framework: Multipack
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=false
       NODE_VERBOSE=false
       NODE_ENV=development
       NODE_MODULES_CACHE=true

-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  unspecified (use default)

       Resolving node version 6.x via semver.io...
       Downloading and installing node 6.11.0...
       Using default npm version: 3.10.10
       Resolving yarn version (latest) via semver.io...
       Downloading and installing yarn (0.24.5)...
       Installed yarn 0.24.5

-----> Restoring cache
       Loading 2 from cacheDirectories (default):
       - node_modules
       - bower_components (not cached - skipping)

-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v0.24.5
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       warning fsevents@1.0.17: The platform "linux" is incompatible with this module.
       info "fsevents@1.0.17" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       [4/4] Building fresh packages...
       Done in 112.26s.

-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)

-----> Build succeeded!
=====> Downloading Buildpack: https://github.com/mars/create-react-app-inner-buildpack.git
=====> Detected Framework: React.js (create-react-app)
       Writing `static.json` to support create-react-app
       Enabling runtime environment variables

       > ysp-dokku@0.1.0 build /tmp/build
       > react-scripts build

       Creating an optimized production build...
       Compiled successfully.

       File sizes after gzip:

       48.03 KB  build/static/js/main.7fb8d6ba.js
       289 B     build/static/css/main.9a0fe4f1.css

       The project was built assuming it is hosted at the server root.
       To override this, specify the homepage in your package.json.
       For example, add this to build it for GitHub Pages:

       "homepage" : "http://myname.github.io/myapp",

       The build folder is ready to be deployed.
       You may serve it with a static server:

       yarn global add serve
       serve -s build

=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-static.git
=====> Detected Framework: Static HTML
remote:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
remote:                                  Dload  Upload   Total   Spent    Left  Speed
remote:   0     0    0     0    0     0      0      0 --:--:-- --:remote:   6  838k    6 51874    0     0  81531      0  0:00:10 --:remote:  64  838k   64  542k    0     0   334k      0  0:00:02  0:remote: 100  838k  100  838k    0     0   374k      0  0:00:02  0:00:02 --:--:--  374k
-----> Installed directory to /app/bin
       Using release configuration from last framework (Static HTML).
remote: cat: /tmp/build/last_pack_release.out: input file is output file
-----> Discovering process types
       Procfile declares types ->
-----> Releasing ysp-dokku (dokku/ysp-dokku:latest)...
-----> Deploying ysp-dokku (dokku/ysp-dokku:latest)...
-----> Attempting to run scripts.dokku.predeploy from app.json (if defined)
-----> App Procfile file found (/home/dokku/ysp-dokku/DOKKU_PROCFILE)
-----> DOKKU_SCALE file found (/home/dokku/ysp-dokku/DOKKU_SCALE)
=====> web=1
-----> Attempting pre-flight checks
       For more efficient zero downtime deployments, create a file CHECKS.
       See http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ for examples
       CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
37f231005d627c76d67c0d2081593d7fb6cae4112127f010d96f175b308c1702
remote: App container failed to start!!
=====> ysp-dokku web container output:
       Injecting runtime env into /app/build/static/js/main.7fb8d6ba.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.7fb8d6ba.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.7fb8d6ba.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.7fb8d6ba.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
       Injecting runtime env into /app/build/static/js/main.7fb8d6ba.js (from .profile.d/inject_react_app_env.sh)
       setuidgid: usage: setuidgid account child
=====> end ysp-dokku web container output
To moniker.dokku.me:ysp-dokku
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'dokku@moniker.dokku.me:ysp-dokku'
mars commented 7 years ago

The default web process for create-react-app-buildpack is from the static-site buildpack. If Dokku requires an explicit Procfile, then it should contain:

web: bin/boot
thomasjonas commented 7 years ago

That seemed to do the trick! Thanks so much :) Maybe it's a bug with Dokku + multiple build packs + no Procfile... I might open an issue over at Dokku later.

thomasjonas commented 7 years ago

and we can consider this closed of course...

mars commented 7 years ago

🏁 Just updated the docs with info about the Procfile.

shsunmoonlee commented 5 years ago

@thomasjonas @mars Thanks guys for the tip. It still doesn't work on my end. Do you know the solution on this? I'm just trying to deploy create react app using dokku.

Enumerating objects: 18, done. Counting objects: 100% (18/18), done. Delta compression using up to 12 threads Compressing objects: 100% (10/10), done. Writing objects: 100% (11/11), 958 bytes | 958.00 KiB/s, done. Total 11 (delta 6), reused 0 (delta 0) -----> Cleaning up... -----> Building MYAPP from herokuish... -----> Adding BUILD_ENV to build environment... -----> Fetching custom buildpack To MYIPADDRESS:APPNAME ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'dokku@MYIPADDRESS:APPNAME'

thomasjonas commented 5 years ago

@SeunghunSunmoonLee I'm currently using a Dockerfile based deployment strategy with Dokku, but you might be able to solve the problem by doing a git push YOUR_REMOTE --force. I noticed that I needed to --force it sometimes. It might also be worth it to look into using a Dockerfile with Dokku as in my experience it's a bit faster.

shsunmoonlee commented 5 years ago

Ah nice! @thomasjonas Could you share the tutorial for dokku Dockerfile approach for create react app production deployment?

thomasjonas commented 5 years ago

You can find my current configuration here

I'm sure this is not the best way to do it, but it seems to work for me.

shsunmoonlee commented 5 years ago

@thomasjonas When you were not using Dockerfile, how did you deploy using this buildpack?

I did //.buildpacks https://github.com/mars/create-react-app-buildpack.git

//Procfile web: bin/boot

//jsconfig.json for absolute import like import Button from 'components/Button' { "compilerOptions": { "baseUrl": "src" }, "include": ["src"] }

// static.json

{
    "root": "build/",
    "routes": {
        "/**": "index.html"
    },
    "https_only": true
}

//package.json
  "scripts": {
    "dokku": {
      "predeploy": "",
      "postdeploy": ""
    },
    "start": "react-scripts start",
    "start-dev": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "start:staging": "REACT_APP_NODE_ENV=staging npm start",
    "send:translation_specification": "npm run build:translations && node scripts/sendUpdatedKeys.js",
    "build:messages": "NODE_ENV=production babel ./src >/dev/null",
    "build:translations": "npm run build:messages && node scripts/mergeMessages.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      [
        "babel-plugin-react-intl",
        {
          "messagesDir": "./build/messages/",
          "enforceDescriptions": false
        }
      ]
    ]
  },

and I get

-----> Build
       Running build

       > fusion-software@0.1.0 build /tmp/build
       > react-scripts build

       Creating an optimized production build...
       Failed to compile.

       ./src/components/PricingCards/index.js
       Cannot find module: 'assets/img/Enterprise.svg'. Make sure this package is installed.

       You can install this package by running: npm install assets/img/Enterprise.svg.

remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
thomasjonas commented 5 years ago

seems like you're right with jsconfig.json/absolute imports causing problems... Without that I can just use the buildpack. I think this buildpack only supports version 2 of CRA so it probably needs updating to be used with the new version.