Skip to content

Zip file created with a default (file) mode causes corrupted Azure function #802

Closed
@romanofski

Description

@romanofski

Disclaimer: I'm not sure whether this is a bug in rules_pkg or really a problem in Azure. However I thought I better file it regardless in case others stumble over this since the "workaround" is easy. So feel free to close.

We're using the packaging rules to package up Azure Function Apps. The mode used to create a zipfile.ZipInfo object in the zip file created, causes a broken Azure Function App deployment. The main problem seems to be the file mode which differs significantly when used zipfile.ZipInfo.from_file:

Env details

OS: GNU/Linux - Ubuntu 22.04 running in WSL2
Python: 3.11.0

Problem description

The filemode set with the current code:

> <ZipInfo filename='dist/main.js' filemode='?rw-r--r--' file_size=3408 compress_size=0>
> entry_info.external_attr
27525120
> oct(entry_info.external_attr >> 16)
'0o644'

The filemode when the info is constructed with zipfile.ZipInfo.from_file:

> <ZipInfo filename='dist/main.js' filemode='-rw-r--r--' file_size=3408 compress_size=0>
> oct(info.external_attr >> 16)
'0o100644'

You'll notice the ? at the beginning of the zipinfo for the file if constructed with the current default mode.

Reproducer

I can reproduce this 100% with access to deploying a function app. I see if I can file a bug somewhere in Azure too. A minimal reproducer is to create a zip file with the make_zipinfo method from build_zip.py using a 16bit? file mode (0o644).

Workaround

The workaround I currently use is to set an explicit file mode:

pkg_files(
    name = "pkg_zip_contents",
    srcs = [
        ":zip_contents",
    ],
    strip_prefix = strip_prefix.from_pkg(),
    attributes = pkg_attributes(
        mode = '100644',
    ),
)

It seems using a 32bit file mode (sorry only stumbled over it in a Stackoverflow post about git file modes is not causing this confusing behaviour in deployment.

Metadata

Metadata

Assignees

Labels

P2An issue that should be worked on when time is available

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions