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

Config: Build with docker #6

Open
trykovyura opened this issue Feb 16, 2025 · 7 comments
Open

Config: Build with docker #6

trykovyura opened this issue Feb 16, 2025 · 7 comments
Labels
enhancement New feature or request

Comments

@trykovyura
Copy link

Hi, thanks for great tool! Trying to customise build configuration, but found some issues and i need some help.

Use cases

  • Build monorepo with nextjs
  • Respository structure is classic for turborepo
  • Have several apps to build with docker and deploy with serverless container
Image

Build config

name: example

deployment:
  type: [email protected]

containers:
  example-docs:
    src: ./apps/example-docs
    routing:
      domain: dev-docs.example.com
      pathPattern: /*
      pathHealthCheck: /api/health
    environment:
      HELLO: world
    compute:
      type: awsFargateEcs
  example-web:
    src: ./apps/example-web
    compute:
      type: awsFargateEcs
      awsFargateEcs:
        cpu: 256
        memory: 512
    build:
      args: # Optional: Arguments to pass to the build, as a map of key-value pairs. This is useful for passing in build arguments to the Dockerfile, like ssh keys to fetch private dependencies, etc.
        key: value # Example: ARG key=value
      dockerFileString: ./apps/example-web/Dockerfile
    routing:
      domain: dev-web.example.com
      pathPattern: /*
      pathHealthCheck: /api/health
    environment:
      HELLO: world

Build error

When i try to deploy this config - it errors with on serverless deploy

  • Unrecognized key(s): build
{
    "source": "sfcore.analysis.generated.v1",
    "event": {
      "actionSucceeded": false,
      "operatingSystem": "linux",
      "architecture": "x64",
      "cicd": true,
      ...
      "isCompose": false,
      "projectType": "containers",
      "cliOptions": [
        "stage",
        "debug"
      ],
      "source": "[email protected]",
      "actionName": "deploy",
      "configurationFileName": "serverless.containers.yml",
      "resolvers": [],
      "error": {
        "name": "Error",
        "message": "Invalid configuration:\n\n  - Unrecognized key(s): build\n\n",
        "code": "INVALID_CONFIGURATION"
      }
    }
  }

Build error analysis

containers:
  my-container:
    src: ./path/to/container # Required: Path to the container source code.
    compute: # Required: Compute configuration.
    build: # Optional: Build configuration.
    environment: # Optional: Environment variables to pass to the container.
    routing: # Required: Routing configuration.
    dev: # Optional: Development mode configuration
  • Actual
example-web:
    src: ./apps/example-web
    compute:
    build:
      args: # Optional: Arguments to pass to the build, as a map of key-value pairs. This is useful for passing in build arguments to the Dockerfile, like ssh keys to fetch private dependencies, etc.
        key: value # Example: ARG key=value
      dockerFileString: ./apps/example-web/Dockerfile
  • Could not find source code to check - is it opensoured?
  • Main hypothesis - looks like a bug 🐛

Docker examples?

More bugs?

  • hypothesis that dockerFileString -> supposed to be dockerFile as is see in serverless configuration

Proposual for configuration update

Add build context to separate src and context

build:
  args: # Optional: Arguments to pass to the build, as a map of key-value pairs. This is useful for passing in build arguments to the Dockerfile, like ssh keys to fetch private dependencies, etc.
    key: value # Example: ARG key=value
  dockerFileString: # Optional: Dockerfile as a string to use for the container (not recommended, prefer
  context: # Optional: Build context for docker file```
@austencollins
Copy link
Member

@trykovyura This is our fault for pushing out docs before the new release that features the "build" property. We are shipping this release on Monday and this feature will be available then.

@austencollins austencollins added the enhancement New feature or request label Feb 17, 2025
@trykovyura
Copy link
Author

@austencollins no problem. If you know estimated version, it would be great to track release.
Lastest release 5 days ago https://github.com/serverless/serverless/releases/tag/v4.6.3 - suppose waiting for 4.6.4 or 4.7.0?

@Mmarzex
Copy link

Mmarzex commented Feb 18, 2025

@trykovyura 4.6.3 was releases yesterday and adds the build args support.

@trykovyura
Copy link
Author

trykovyura commented Feb 18, 2025

Nice.
Tried 4.6.3

  • Fixed "message": "Invalid configuration:\n\n - Unrecognized key(s): build\n\n"
  • But error on parsing path ERROR: failed to solve: dockerfile parse error on line 1: unknown instruction: ./apps/example-app/Dockerfile

Config

example-app:
    src: .
    compute:
      type: awsFargateEcs
      awsFargateEcs:
        cpu: 256
        memory: 512
    build:
      dockerFileString: ./apps/example-app/Dockerfile
    routing:
      domain: dev-app.example.com
      pathPattern: /*
      pathHealthCheck: /api/health

@trykovyura
Copy link
Author

trykovyura commented Feb 18, 2025

Provided turbo example based on container-examples:

@austencollins
Copy link
Member

Hi @trykovyura, the dockerFileString isn't where you specify your Dockerfile path. As long is the Dockerfile is within the src location, it will be picked up.

dockerFileString is for other, rare use-cases where Dockerfile content needs to be provided as a string within the YAML. It's unlikely users need this, but future projects soon to be released use SCF behind the scenes, and dynamically generate Dockerfiles, so they need this.

In short, remove dockerFileString

@trykovyura
Copy link
Author

@austencollins okey.
A little strange at point of configuration Dockerfile that missing Dockerfile path:

  • Default - src files wrapped by Docker from containers framework. Suppose under hood creates Dockerfile (templated)
  • dockerFileString - write Dockerfile content at yaml. Suppose under hood creates Dockerfile with content from yaml.
  • But no config provided for dockerFile path - just copy/create DockerFile from filesystem. (in my case will be more prefered by developers to write Dockerfile as separate file and run instead of write yaml Dockerfile content)

How to do with this ticket?

  • Close as 4.6.3 released and config available
  • Open proposal for Dockerfile path and build context? - PS: Is it possible to extend config for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants