superfly / flyctl-actions

:octocat: GitHub Action that wraps the flyctl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heroku buildpack and NODE_ENV issue

anri-asaturov opened this issue · comments

When deploying from github actions I get
[Warning: Skip pruning because NODE_ENV is not 'production'.]
from node.js heroku buildpack 20
It doesn't happen when deploying from local machine. I tried setting NODE_ENV everywhere I could think of, but no luck :(

Some artefacts:
workflow.yml

name: Deploy
on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      NODE_ENV: production

    steps:
      - uses: actions/checkout@v2

      - uses: superfly/flyctl-actions@master
        env:
          NODE_ENV: production
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
        with:
          args: 'deploy'

relevant deploy log parts

===> ANALYZING
Previous image with name "registry.fly.io/rtcl-api-server:cache" not found
===> RESTORING
===> BUILDING
[INFO] Node.js Buildpack
[INFO] Setting NODE_ENV to production
[INFO] Installing toolbox
[INFO] - yj

[Installing Node]
[INFO] Getting Node version
[INFO] Resolving Node version
[INFO] Downloading and extracting Node v16.13.1

[Parsing package.json]
[INFO] Parsing package.json
[INFO] No file to start server
[INFO] either use 'docker run' to start container or add index.js or server.js
[INFO] Using npm v8.1.2 from Node
[INFO] Installing node modules from ./package-lock.json
..........................
<cut>
..........................
> NODE_ENV=production node ace build --production

[ info ]  cleaning up "./build" directory
[ info ]  compiling typescript source files
[ info ]  copy { ace,package.json,package-lock.json => build }
[ info ]  copy { .adonisrc.json => build }
CREATE: ace-manifest.json file
[ success ]  built successfully

[Warning: Skip pruning because NODE_ENV is not 'production'.]

[INFO] Discovering process types
[INFO] Procfile declares types -> web, release

fly.toml

# fly.toml file generated for rtcl-api-server on 2022-01-01T21:15:52+02:00

app = "rtcl-api-server"

kill_signal = "SIGINT"
kill_timeout = 10
processes = []

[build]
builder = "heroku/buildpacks:20"

[env]
DRIVE_DISK = "local"
HOST = "0.0.0.0"
NODE_ENV = "production"
PORT = "8080"

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

It's not causing me problems, but curious how to address it.

You would have to use [build.args], see #5

Thanks @backflip setting node_env in build args indeed removes this warning.

Any solutions here? I think I might have the same issue.
I'm containeraizing a React app application with Dockerfile and Nginx and when I deploy from vscode with flyctl deploy, it seems to take in consideration the env variables stored in .env so the build for npm run build in the Dockerfile successfully uses the environment variables. But when I run it from the Github Action the variables are not injected.
I've been searching a lot on that, a lot of Dockerfile posts with topics about ARG & ENV and flyctl command with cross-env arguments from github actions and Dockefile and some others but it doesn't work. WHat am I missing? Or the problem is just that the .env file is not committed since is in the .gitignore so in the Dockerfile from github action is not taken and so not injected?

This issue only applies to the heroku builders, not docker apps if I understand correctly. Generally though, I would avoid baking in dotenv files into your containers.

Hi, I am building a Expressjs based application and recently exploring fly.io . I am having blocker on how to pass environment variable during build time and I have tried --build-args but not working. The env is still not available for my runtime.

Here's a sample Dockerfile

ARG NODE_VERSION=16.18.1
ARG DB_HOST
FROM node:${NODE_VERSION}-slim as base

ENV DB_HOST=$DB_HOST

// ... Remaining dockerfile

My deploy command

flyctl deploy --build-arg DB_HOST=https://abc.com

What am I missing here?

Build args are only available during build time. Use flyctl secret set DB_HOST=... to get runtime access. If you need more help, please use the community forum, thanks!