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

fix: Add default file permission (755 for image build) #1176

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/api/create_docker_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ _ = new ImageFromDockerfileBuilder()
!!!tip

Testcontainers for .NET detects your Docker host configuration. You do **not** have to set the Docker daemon socket.

## Known issues

- When building an image using Testcontainers for .NET and switching the user's context (`USER` statement) in a Dockerfile, the user won't automatically become the [owner](https://github.com/testcontainers/testcontainers-dotnet/issues/1171#issuecomment-2099197840) of the working directory, which seems to be the case when building the image from the CLI. If the running process requires write access to the working directory, it is necessary to set the permissions explicitly (the base image in this example already contains the user `app`):

```Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:8.0
WORKDIR /app
RUN chown app:app .
USER app
```
8 changes: 7 additions & 1 deletion src/Testcontainers/Images/DockerfileArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace DotNet.Testcontainers.Images
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -148,7 +149,12 @@ public async Task<string> Tar(CancellationToken ct = default)
using (var inputStream = new FileStream(absoluteFilePath, FileMode.Open, FileAccess.Read))
{
var entry = TarEntry.CreateTarEntry(relativeFilePath);
entry.Size = inputStream.Length;
entry.TarHeader.Size = inputStream.Length;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
entry.TarHeader.Mode = (int)Unix.FileMode755;
}

await tarOutputStream.PutNextEntryAsync(entry, ct)
.ConfigureAwait(false);
Expand Down
Loading