Skip to content

Conversation

@norbjd
Copy link
Contributor

@norbjd norbjd commented Jun 27, 2025

Summary

What's changed?

When building a container, honor .dockerignore present at the root of the build context.

Also bumping the version in the same PR (0.4.15 => 0.4.16 since it's a bug fix).

Bonus: we don't need tar-fs library anymore!

Why do we need this?

Today, .dockerignore file at the root of the build context is ignored. Whatever file you list inside it, it will be present in the built image if you do COPY . . for example.

The library used under the hood (dockerode) supports this, but not if we pass a tar stream when building. We need to pass a list of files so files in .dockerignore can be excluded.

So, the only way seems to be to list all the files in the build context, and pass them to dockerode so it can filter afterwards.

How have you tested it?

Pretty simple example:

serverless.yml:

service: test
configValidationMode: off
provider:
  name: scaleway

plugins:
  - serverless-scaleway-functions

package:
  patterns:
    - "!node_modules/**"
    - "!.gitignore"
    - "!.git/**"

custom:
  containers:
    test:
      directory: container
      port: 8000
      memoryLimit: 1000
      cpuLimit: 1000

The container/ folder looks like:

container/
  |-- .dockerignore
  |-- Dockerfile
  |-- dir1
       |-- dir2
            |-- test1
            |-- test2
  |-- hello
  |-- world

Dockerfile is:

FROM python:3.13-alpine

WORKDIR /app

COPY . .

CMD ["python3", "-m", "http.server"]

And .dockerignore contains:

world
dir1/dir2/test2

Once deployed (serverless deploy), the files shown are just: hello and dir1/dir2/test. Other files have been excluded. This can also be checked in the built image.

Checklist

  • I have reviewed this myself
  • There is a unit test covering every change in this PR
  • I have updated the relevant documentation

Details

@norbjd norbjd requested a review from Bemilie June 27, 2025 13:45
@norbjd norbjd merged commit affa499 into scaleway:master Aug 19, 2025
9 of 22 checks passed
@norbjd norbjd deleted the fix/honor-dockerignore-building-container branch August 19, 2025 16:45
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

Successfully merging this pull request may close these issues.

2 participants