7

I'm trying to copy an executable initialization bash script init.sh to the Localstack Docker container created with Testcontainers (1.13.0) using the JUnit 5 module:

@Container
static LocalStackContainer localStack = new LocalStackContainer("0.10.0")
  .withServices(S3)
  .withCopyFileToContainer(MountableFile.forClasspathResource("init.sh"), "/docker-entrypoint-initaws.d/init.sh");

But inside the created Docker container the file lacks the execute permission (checked with looking at the file permission using docker exec -it ID /bin/sh).

On my machine the file has the following permission:

$ ls -al
total 16
drwxr-xr-x  4 xyz  staff  128 Apr 16 20:51 .
drwxr-xr-x  4 xyz  staff  128 Apr 16 08:43 ..
-rw-r--r--  1 xyz  staff  135 Apr 16 20:14 application.yml
-rwxr-xr-x  1 xyz  staff  121 Apr 16 20:51 init.sh

I also tried copying this file with .withClasspathResourceMapping() but this takes a binding mode which only offers READ_ONLY or READ_WRITE.

rieckpil
  • 10,470
  • 3
  • 32
  • 56

1 Answers1

7

You can use another builder of MountableFile class, which takes the mode argument with a posix file mode value to change permission. For example, making the script executable only for the owner:

...
.withCopyFileToContainer(MountableFile.forClasspathResource("init.sh", 0744), "/docker-entrypoint-initaws.d/init.sh");

0744 is an octal file mode literal which corresponds to -rwxr--r-- permission.

However I tried the same configuration with Localstack 0.10.8 and initialisation works without even making the script executable.

yuppie-flu
  • 1,270
  • 9
  • 13