aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
90 stars 77 forks source link

Container API does not respect `env_file` description in docker-compose.yml #1459

Open fossamagna opened 1 year ago

fossamagna commented 1 year ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v18.15.0

Amplify CLI Version

11.1.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Describe the bug

In the documentation, env_file is included in the list of supported configurations in Docker compose file. However, the value set for env_file in docker-compose.yml is ignored. https://docs.amplify.aws/cli/usage/containers/#supported-configurations

Expected behavior

The description in the env_file must be respected; it must be reflected in EnvironmentFiles of ContainerDefinition.

Reproduction steps

  1. Run amplify configure project. Enable container-based deployments.
  2. Run amplify add api.
    1. Respond as follows:
      ? Select from one of the below mentioned services: REST
      ? Which service would you like to use API Gateway + AWS Fargate (Container-based)
      ? Provide a friendly name for your resource to be used as a label for this category in the project: app
      ? What image would you like to use Docker Compose - ExpressJS + Flask template
      ? When do you want to build & deploy the Fargate task On every "amplify push" (Fully managed container source)
      ? Do you want to access other resources in this project from your api? No
      ? Do you want to restrict API access Yes
  3. Create an express.env file with the following contents as . /express.env.
    1. FOO=foo
  4. Specify env_file in docker-compose.yml as . /express.env.
  5. Run amplify push

Project Identifier

Project Identifier: a2b1a21124c9682206af329de433af89

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

josefaidt commented 1 year ago

Hey @fossamagna :wave: thanks for raising this! I was able to reproduce this by deploying the base docker-compose with Express.js template. To reproduce:

  1. amplify init -y
  2. amplify configure project > Enable container-based deployments
  3. amplify add api > REST > Docker Compose/Fargate/Express + Flask
  4. optionally remove the Flask container to help speed up the deployment
  5. copy the following to docker-compose.yml
    version: '3.8'
    services:
      express:
        build:
          context: ./express
          dockerfile: Dockerfile
        ports:
          - '8080:8080'
        networks:
          - public
          - private
        environment:
          - MY_ENV_VAR=hello
        env_file:
          - .env
    networks:
      public:
      private:
  6. create a sample .env file relative to the docker-compose file
    MY_DOTENV_VAR=hello
  7. push with amplify push -y
  8. observe environmentFiles is not populated in the task definition image

Additionally, I can see the sample dotenv file in the source artifact zip archive and in a few other places in my deployment bucket: image image

Marking as a bug 🙂