Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think v1.3.0 not working with command starts with NODE_ENV= #296

Closed
ensia96 opened this issue May 8, 2024 · 3 comments
Closed

I think v1.3.0 not working with command starts with NODE_ENV= #296

ensia96 opened this issue May 8, 2024 · 3 comments

Comments

@ensia96
Copy link

ensia96 commented May 8, 2024

Github actions runs well, but on ECS, container exits with error

Error: Cannot find module '/usr/src/app/NODE_ENV=dev'

The code below is the code of my project.

      - name: Fill in the new image ID in the Amazon ECS task definition
        id: task-def
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          task-definition: ${{ env.ECS_TASK_DEFINITION }}
          container-name: ${{ env.CONTAINER_NAME }}
          image: ${{ steps.build-image.outputs.image }}
          environment-variables: |
            # envs
          command: NODE_ENV=${{ env.ENV }} node dist/app.local.js

So, I fixed code above to below, and now the container works well.

      - name: Fill in the new image ID in the Amazon ECS task definition
        id: task-def
        # before 'support command override' update
        # https://github.com/aws-actions/amazon-ecs-render-task-definition/blob/v1.3.0/CHANGELOG.md
        uses: aws-actions/amazon-ecs-render-task-definition@v1.2.0
        with:
          task-definition: ${{ env.ECS_TASK_DEFINITION }}
          container-name: ${{ env.CONTAINER_NAME }}
          image: ${{ steps.build-image.outputs.image }}
          environment-variables: |
            # envs
          command: NODE_ENV=${{ env.ENV }} node dist/app.local.js

I saw your update changelog.

And found this

image

@ensia96 ensia96 changed the title I think v1.3.0 not working with command starts with NODE_ENV= I think v1.3.0 not working with command starts with NODE_ENV= May 8, 2024
@amazreech
Copy link
Contributor

Hi @ensia96,

Here is what I was able to find, hope this helps.

Command field was not supported in earlier versions of ecs-render-task-definition. This field recently got supported as part of the latest release v1.3.0 and PR 284

Passing in the Command in earlier versions of ecs-render-task-def, I believe would do nothing. This field, I think would not be passed on to ECS Task definition at all.

However, starting v1.3.0 the Command field is being read and passed on to ECS task definition.

Why the command field you passed not be working:

Here is ECS documentation explaining how Command is used in ECS: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html.

As per the documentation the command field maps to COMMAND parameter on docker run. Below is the relevant paragraph from the documentation:

The command that's passed to the container. This parameter maps to Cmd in the Create a container section of the Docker Remote API and the COMMAND parameter to docker run. For more information about the Docker CMD parameter, see https://docs.docker.com/engine/reference/builder/#cmd. If there are multiple arguments, make sure that each argument is a separated string in the array.

I tested by trying to pass in a command like you mentioned when running a docker image:
docker run -it <Image-Id> NODE_ENV=dev node index.js

Looks like we get a similar error here from docker when trying to run above command:

internal/modules/cjs/loader.js:638
    throw err;
    ^
Error: Cannot find module '/home/node/app/NODE_ENV=dev'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

What might work:

To get around this issue, I was able to set the Environment variable in my docker file with something like:
ENV NODE_ENV=dev

And then pass node dist/app.local.js as command to the github workflow.

...
environment-variables: |
  # env vars
command: node dist/app.local.js
...

Let me know if this helps.

@ensia96
Copy link
Author

ensia96 commented May 9, 2024

I will reflect your recommendations into my code in next deployment, and then share the result.

      - name: Fill in the new image ID in the Amazon ECS task definition
        id: task-def
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          task-definition: ${{ env.ECS_TASK_DEFINITION }}
          container-name: ${{ env.CONTAINER_NAME }}
          image: ${{ steps.build-image.outputs.image }}
          environment-variables: |
          environment-variables: |
            NODE_ENV=${{ env.ENV }}
            # envs
          command: node dist/app.local.js

Thank you!

@ensia96
Copy link
Author

ensia96 commented May 9, 2024

It works!

I will close this issue. Thank you for your fast reply!

@ensia96 ensia96 closed this as completed May 9, 2024
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

No branches or pull requests

2 participants