GoogleCloudPlatform / ruby-docker

Ruby runtime for Google Cloud Platform
Apache License 2.0
134 stars 56 forks source link

Stop docker build when asset precompile failed #175

Closed leomao10 closed 5 years ago

leomao10 commented 5 years ago

Just want to find out how we can stop the docker build process when rake assets:precompile raise error.

During our GCP deploy, we found that some of the assets were missing, and after a while of digging, I found that it is because it failed during rake assets:precompile. However, when we check the cloud build, it said it is passed. Here is the log:

Step #1: Webpacker is installed ? ?
Step #1: Using /app/config/webpacker.yml file for setting up webpack paths
Step #1: Compiling?
Step #1: Compilation failed:
Step #1: 
Step #1: Hash: c54203bdd559d84de538
Step #1: Version: webpack 3.11.0
Step #1: Time: 6876ms
Step #1:                                                            Asset       Size  Chunks             Chunk Names
Step #1: components/ExternalLink/ExternalLink-63821095eaa9fcaedff1.js.map      13 kB       2  [emitted]  components/ExternalLink/ExternalLink
Step #1:                              application-190b6bceddbacc646e07.js     129 kB       0  [emitted]  application
Step #1:     components/ExternalLink/ExternalLink-63821095eaa9fcaedff1.js     9.7 kB       2  [emitted]  components/ExternalLink/ExternalLink
Step #1:                          application-190b6bceddbacc646e07.js.map     176 kB       0  [emitted]  application
Step #1:     components/PageFooter/PageFooter-873a83e3ca03e85fbef5.js.map    14.4 kB       1  [emitted]  components/PageFooter/PageFooter
Step #1:         components/PageFooter/PageFooter-873a83e3ca03e85fbef5.js    11.8 kB       1  [emitted]  components/PageFooter/PageFooter
Step #1:                                                    manifest.json  636 bytes          [emitted]  
Step #1:      components/PageFooter/PageFooter-873a83e3ca03e85fbef5.js.gz     4.4 kB          [emitted]  
Step #1:  components/ExternalLink/ExternalLink-63821095eaa9fcaedff1.js.gz    3.88 kB          [emitted]  
Step #1:                                                 manifest.json.gz  198 bytes          [emitted]  
Step #1:                           application-190b6bceddbacc646e07.js.gz    40.1 kB          [emitted]  
Step #1:   [43] (webpack)/buildin/module.js 517 bytes {0} [built]
Step #1:   [55] ./app/javascript/application.js 291 bytes {0} [built]
Step #1:   [61] (webpack)/buildin/global.js 509 bytes {0} [built]
Step #1:     + 160 hidden modules
Step #1: 
Step #1: ERROR in ./app/javascript/components/PageFooter/PageFooter.spec.jsx
Step #1: Module not found: Error: Can't resolve 'enzyme-to-json' in '/app/app/javascript/components/PageFooter'
Step #1:  @ ./app/javascript/components/PageFooter/PageFooter.spec.jsx 7:20-45
Step #1: 
Step #1: Removing intermediate container 233cafe5fec7
Step #1:  ---> 52de3c4c7fab
Step #1: Step 16/18 : FROM augmented-base
Step #1:  ---> 54ab2f5a772e
Step #1: Step 17/18 : COPY --from=app-build /app/ /app/
Step #1:  ---> 37df282bafca
Step #1: Step 18/18 : CMD exec bundle exec foreman start --formation $FORMATION
Step #1:  ---> Running in a663ead4542d
Step #1: Removing intermediate container a663ead4542d
Step #1:  ---> a9d7f75ae09c
Step #1: Successfully built a9d7f75ae09c

Wondering if it is possible to fail the docker build when asset precompile is failed so that we can pick it up during deployment, not after deployment and switch traffic to the problematic build?

dazuma commented 5 years ago

Sorry, I missed this. By default, the build process for Ruby on the App Engine flexible environment ignores failures of asset precompilation, on the theory that not all applications actually use the asset pipeline (e.g. running asset precompilation could just fail by design) and we don't want to block those apps from deploying. The runtime does this by setting the default build script to bundle exec rake assets:precompile || true.

If you want failures to cause the deployment to error out, you can override that build script and remove the || true. Do this by adding this to your app.yaml:

runtime_config:
  build:
    - bundle exec rake assets:precompile

(Note that you can do further customizations of the build process in the same way. This capability is not in the official documentation, but it does work.)

leomao10 commented 5 years ago

No worries, and thank you very much for the response @dazuma , It is actually really helpful. Will close this issue now as you already provide the solution 👍