diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d07717..d2e84e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,9 @@ env: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + packages: read steps: - uses: actions/checkout@master @@ -29,14 +32,14 @@ jobs: - name: Build Docker image run: docker build . -t ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} - - name: Test Docker image - run: cd tests && sudo gradle test --info -Ddocker_image_tag=${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} + - name: Docker version + run: docker --version - - name: Scan with Phonito Security - uses: phonito/phonito-scanner-action@master - with: - image: ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} - phonito-token: '${{ secrets.PHONITO_TOKEN }}' + - name: Test Docker image + run: cd tests && gradle test --info -Ddocker_image_tag=${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} + env: # To allow downloading packages + GITHUB_USERNAME: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Scan with Snyk uses: snyk/actions/docker@0.1.1 diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 32801ec..d7aa9d7 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -10,6 +10,9 @@ env: jobs: build: runs-on: ubuntu-latest + permissions: + contents: write + packages: write steps: - uses: actions/checkout@master @@ -40,14 +43,10 @@ jobs: - name: Test Docker image if: env.RELEASE_VERSION != '' - run: cd tests && sudo gradle test -Ddocker_image_tag=${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} - - - name: Scan with Phonito Security - if: env.RELEASE_VERSION != '' - uses: phonito/phonito-scanner-action@master - with: - image: ${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} - phonito-token: '${{ secrets.PHONITO_TOKEN }}' + run: cd tests && sudo --preserve-env gradle test -Ddocker_image_tag=${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} + env: # To allow downloading packages + GITHUB_USERNAME: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Scan with Snyk if: env.RELEASE_VERSION != '' diff --git a/Dockerfile b/Dockerfile index 5b13767..3d82997 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM homecentr/base:2.4.3-alpine +FROM homecentr/base:3.4.2-alpine ENV DHCP_ARGS="" RUN apk add --no-cache \ - dhcp=4.4.2-r1 \ - libcap=2.27-r0 && \ + dhcp=4.4.3-r0 \ + libcap=2.64-r0 && \ rm /etc/dhcp/dhcpd.conf.example && \ mkdir /leases && \ chmod 0777 /leases && \ diff --git a/docker-compose.yml b/docker-compose.yml index 5911e3c..2a80e6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,4 +18,4 @@ networks: ipam: driver: default config: - - subnet: "172.18.250.0/24" \ No newline at end of file + - subnet: "172.19.250.0/24" \ No newline at end of file diff --git a/example/dhcpd.conf b/example/dhcpd.conf index 392ff69..bab8118 100644 --- a/example/dhcpd.conf +++ b/example/dhcpd.conf @@ -2,7 +2,7 @@ authoritative; option client-arch code 93 = unsigned integer 16; -subnet 172.18.250.0 netmask 255.255.255.0 { - range 172.18.250.50 172.18.250.60; - option routers 172.18.250.1; +subnet 172.19.250.0 netmask 255.255.255.0 { + range 172.19.250.50 172.19.250.60; + option routers 172.19.250.1; } \ No newline at end of file diff --git a/tests/.idea/compiler.xml b/tests/.idea/compiler.xml index 90485a7..4256222 100644 --- a/tests/.idea/compiler.xml +++ b/tests/.idea/compiler.xml @@ -1,7 +1,7 @@ - + diff --git a/tests/.idea/jarRepositories.xml b/tests/.idea/jarRepositories.xml index 5060e6b..a4db249 100644 --- a/tests/.idea/jarRepositories.xml +++ b/tests/.idea/jarRepositories.xml @@ -21,5 +21,10 @@ \ No newline at end of file diff --git a/tests/.idea/misc.xml b/tests/.idea/misc.xml index 29af3ee..8ecd2fe 100644 --- a/tests/.idea/misc.xml +++ b/tests/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/tests/build.gradle b/tests/build.gradle index 9e7da0d..06f36d8 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -10,14 +10,19 @@ sourceCompatibility = 1.8 repositories { mavenCentral() maven { - url "https://dl.bintray.com/homecentr/maven" + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/homecentr/testcontainers-extensions") + credentials { + username = System.getenv("GITHUB_USERNAME") + password = System.getenv("GITHUB_TOKEN") + } } } dependencies { testImplementation group: 'junit', name: 'junit', version: '4.13' - testImplementation 'org.testcontainers:testcontainers:1.14.3' - testImplementation 'io.homecentr:testcontainers-extensions:1.4.0' + testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.16.0' + testImplementation group: 'io.homecentr', name: 'testcontainers-extensions', version: '1.6.0' testImplementation group: 'commons-net', name: 'commons-net', version: '3.6' testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30' diff --git a/tests/src/test/java/DhcpContainerShould.java b/tests/src/test/java/DhcpContainerShould.java index 5e7e796..5bbc5aa 100644 --- a/tests/src/test/java/DhcpContainerShould.java +++ b/tests/src/test/java/DhcpContainerShould.java @@ -26,16 +26,24 @@ public class DhcpContainerShould { @BeforeClass public static void setUp() throws IOException { - Network network = Network.builder().build(); + Network network = Network.builder() + .driver("bridge") + .build(); + DhcpdConfig config = DhcpdConfig.createFromNetwork(network); _serverContainer = new GenericContainerEx<>(new DockerImageTagResolver()) .withNetwork(network) + .withNetworkAliases("dhcp-server.docker") + //.withEnv("PUID", "0") + //.withEnv("PGID", "0") .withFileSystemBind(config.getAbsolutePath(), "/config/dhcpd.conf") - .waitingFor(WaitEx.forLogMessage("(.*)Socket/fallback/fallback-net(.*)", 1)); + .waitingFor(WaitEx.forLogMessage("(.*)fallback-net(.*)", 1)); _clientContainer = new GenericContainerEx<>(HelperImages.DhcpClient()) .withCommand("sleep", "1000h") + //.withEnv("PUID", "0") + //.withEnv("PGID", "0") .withNetwork(network); _serverContainer.start(); @@ -53,9 +61,24 @@ public static void cleanUp() { @Test public void respondToDhcpDiscovery() throws IOException, InterruptedException { - Container.ExecResult result = _clientContainer.executeShellCommand("nmap --script broadcast-dhcp-discover"); + int retryCounter = 0; + int retryLimit = 10; + Container.ExecResult result = null; + + while(retryCounter < retryLimit) { + System.out.println("Attempting DHCP discovery..."); + + result = _clientContainer.executeShellCommand("nmap -p 67 --script broadcast-dhcp-discover"); + + if(result.getStdout().contains("IP Offered:")){ + break; + } + + retryCounter++; + + Thread.sleep(2000); + } - assertEquals(0, result.getExitCode()); assertTrue(result.getStdout().contains("IP Offered:")); } }