Skip to content

Commit

Permalink
fix: Add default file permission (755 for image build)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed May 13, 2024
1 parent 1d6cbea commit 616b77e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 616b77e

Please sign in to comment.