This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
generated from homecentr/docker-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactoring, re-creating secondary groups fixed (#78)
Creating groups refactored to a reusable function Issue when secondary groups were not correctly re-created upon container restart is fixed
- Loading branch information
Showing
14 changed files
with
233 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
* text=auto | ||
*.sh eol=lf | ||
**/sbin/** eol=lf | ||
**/run eol=lf | ||
*/services.d/* eol=lf | ||
**/run eol=lf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"files.eol": "\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/with-contenv ash | ||
|
||
homecentr_create_group() { | ||
# $1 = Group name | ||
# $2 = Group ID | ||
|
||
# Check if the group exists already | ||
cat /etc/group | grep "^$1:" > /dev/null | ||
|
||
if [ $? == 0 ] | ||
then | ||
# Group already exists, delete it | ||
delgroup "$1" | ||
fi | ||
|
||
addgroup -g "$2" "$1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/with-contenv ash | ||
|
||
homecentr_print_banner() { | ||
|
||
echo ' | ||
__ __ __ | ||
/ / / /___ ____ ___ ___ ________ ____ / /______ | ||
/ /_/ / __ \/ __ `__ \/ _ \/ ___/ _ \/ __ \/ __/ ___/ | ||
/ __ / /_/ / / / / / / __/ /__/ __/ / / / /_/ / | ||
/_/ /_/\____/_/ /_/ /_/\___/\___/\___/_/ /_/\__/_/ | ||
' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/with-contenv ash | ||
|
||
homecentr_print_context() { | ||
|
||
# The gids script filters out the primary group so it matches the structure of the env vars passed to the container | ||
|
||
echo " | ||
------------------------------------- | ||
User uid: $(id -u $EXEC_USER) | ||
User gid: $(id -g $EXEC_USER) | ||
User additional gids: $(id -G $EXEC_USER | tr ' ' '\n' | grep -v "^$(id -g $EXEC_USER)$" | tr '\n' ',' | sed 's/,*$//g') | ||
------------------------------------- | ||
" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/with-contenv ash | ||
|
||
homecentr_set_s6_env_var() { | ||
# $1 = Variable name | ||
# $2 = Variable value | ||
|
||
echo "$2" > "/var/run/s6/container_environment/$1" | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/src/test/java/BaseRunningWithInvalidSecondaryGroupsAsNonRootShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import helpers.BaseDockerImageTagResolver; | ||
import helpers.Image; | ||
import io.homecentr.testcontainers.containers.GenericContainerEx; | ||
import io.homecentr.testcontainers.containers.wait.strategy.WaitEx; | ||
import io.homecentr.testcontainers.images.PullPolicyEx; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.ContainerLaunchException; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
|
||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
|
||
import static io.homecentr.testcontainers.WaitLoop.waitFor; | ||
|
||
public class BaseRunningWithInvalidSecondaryGroupsAsNonRootShould { | ||
private static final Logger logger = LoggerFactory.getLogger(BaseRunningAsRootShould.class); | ||
|
||
private static GenericContainerEx _container; | ||
|
||
@BeforeClass | ||
public static void before(){ | ||
_container = new GenericContainerEx<>(new BaseDockerImageTagResolver()) | ||
.withEnv("PUID", "7000") | ||
.withEnv("PGID", "8000") | ||
.withEnv("PUID_ADDITIONAL_GROUPS", "8005=grp1") // valid delimiter is : | ||
.withRelativeFileSystemBind(Paths.get(Image.getExamplesDir(), "loop").toString(), "/usr/sbin/loop") | ||
.withRelativeFileSystemBind(Paths.get(Image.getExamplesDir(), "run").toString(), "/etc/services.d/env-test/run") | ||
.withImagePullPolicy(PullPolicyEx.never()) | ||
.waitingFor(WaitEx.forS6OverlayStart()); | ||
|
||
try | ||
{ | ||
_container.start(); | ||
} | ||
catch (ContainerLaunchException ex) { | ||
// Expected | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void after() { | ||
_container.close(); | ||
} | ||
|
||
@Test | ||
public void printErrorMessage() throws Exception { | ||
waitFor(Duration.ofSeconds(10), () -> _container.getLogsAnalyzer().matches(".*Valid format is <gid1>:<group-name1>,<gid2>:<group-name2>.*")); | ||
} | ||
|
||
@Test | ||
public void exitFromInitScript() throws Exception { | ||
// This checks the container stopped on the init script and not because of other failure | ||
waitFor(Duration.ofSeconds(10), () -> _container.getLogsAnalyzer().matches(".*\\[cont\\-init\\.d\\] 10-init\\.sh: exited.*")); | ||
} | ||
|
||
@Test | ||
public void exit() throws Exception { | ||
waitFor(Duration.ofSeconds(5), () -> !_container.isRunning()); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tests/src/test/java/BaseRunningWithInvalidSecondaryGroupsAsRootShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import helpers.BaseDockerImageTagResolver; | ||
import helpers.Image; | ||
import io.homecentr.testcontainers.containers.GenericContainerEx; | ||
import io.homecentr.testcontainers.containers.wait.strategy.WaitEx; | ||
import io.homecentr.testcontainers.images.PullPolicyEx; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.ContainerLaunchException; | ||
|
||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
|
||
import static io.homecentr.testcontainers.WaitLoop.waitFor; | ||
|
||
public class BaseRunningWithInvalidSecondaryGroupsAsRootShould { | ||
private static final Logger logger = LoggerFactory.getLogger(BaseRunningAsRootShould.class); | ||
|
||
private static GenericContainerEx _container; | ||
|
||
@BeforeClass | ||
public static void before(){ | ||
_container = new GenericContainerEx<>(new BaseDockerImageTagResolver()) | ||
.withEnv("PUID", "0") | ||
.withEnv("PGID", "0") | ||
.withEnv("PUID_ADDITIONAL_GROUPS", "8005=grp1") // valid delimiter is : | ||
.withRelativeFileSystemBind(Paths.get(Image.getExamplesDir(), "loop").toString(), "/usr/sbin/loop") | ||
.withRelativeFileSystemBind(Paths.get(Image.getExamplesDir(), "run").toString(), "/etc/services.d/env-test/run") | ||
.withImagePullPolicy(PullPolicyEx.never()) | ||
.waitingFor(WaitEx.forS6OverlayStart()); | ||
|
||
try | ||
{ | ||
_container.start(); | ||
} | ||
catch (ContainerLaunchException ex) { | ||
// Expected | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void after() { | ||
_container.close(); | ||
} | ||
|
||
@Test | ||
public void printErrorMessage() throws Exception { | ||
waitFor(Duration.ofSeconds(10), () -> _container.getLogsAnalyzer().matches(".*Valid format is <gid1>:<group-name1>,<gid2>:<group-name2>.*")); | ||
} | ||
|
||
@Test | ||
public void exitFromInitScript() throws Exception { | ||
// This checks the container stopped on the init script and not because of other failure | ||
waitFor(Duration.ofSeconds(10), () -> _container.getLogsAnalyzer().matches(".*\\[cont\\-init\\.d\\] 10-init\\.sh: exited.*")); | ||
} | ||
|
||
@Test | ||
public void exit() throws Exception { | ||
waitFor(Duration.ofSeconds(5), () -> !_container.isRunning()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters