From 4b731f37098ca35d63dc181d65af955080b11175 Mon Sep 17 00:00:00 2001 From: Abdud Dayan Adeeb Date: Mon, 15 Feb 2021 15:58:29 -0500 Subject: [PATCH 1/6] tests: setup tests --- .github/workflows/1-tests.yml | 22 +++++++++++++++++++++ .github/workflows/2-private-docker-test.yml | 9 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 .github/workflows/1-tests.yml create mode 100644 .github/workflows/2-private-docker-test.yml diff --git a/.github/workflows/1-tests.yml b/.github/workflows/1-tests.yml new file mode 100644 index 0000000..cdeee24 --- /dev/null +++ b/.github/workflows/1-tests.yml @@ -0,0 +1,22 @@ +name: Docker Run Action Tests + +on: + push: + branches: + - main + pull_request: + +jobs: + smoke-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + image: docker:20.10.3 + run: | + echo "::set-output name=image_name::`uname -r`" + - uses: actions/github-script@v3 + with: + script: | + console.log(core.getOutput('image_name')) diff --git a/.github/workflows/2-private-docker-test.yml b/.github/workflows/2-private-docker-test.yml new file mode 100644 index 0000000..114a50f --- /dev/null +++ b/.github/workflows/2-private-docker-test.yml @@ -0,0 +1,9 @@ +name: Private Docker Run Test + +on: + push: + branches: + - main + +jobs: + run-private-docker: From 6321bad333382861021f9ce774e4eaf769b70458 Mon Sep 17 00:00:00 2001 From: Abdud Dayan Adeeb Date: Mon, 15 Feb 2021 15:59:37 -0500 Subject: [PATCH 2/6] fix: remove unused workflow --- .github/workflows/2-private-docker-test.yml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .github/workflows/2-private-docker-test.yml diff --git a/.github/workflows/2-private-docker-test.yml b/.github/workflows/2-private-docker-test.yml deleted file mode 100644 index 114a50f..0000000 --- a/.github/workflows/2-private-docker-test.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: Private Docker Run Test - -on: - push: - branches: - - main - -jobs: - run-private-docker: From f451fad6790fb9d93e75a1749dc999fdf723e937 Mon Sep 17 00:00:00 2001 From: Abdud Dayan Adeeb Date: Mon, 15 Feb 2021 16:21:09 -0500 Subject: [PATCH 3/6] fix: check if network exists --- README.md | 3 +-- entrypoint.sh | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 11f1921..dc5792d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # Docker Run Action -- run a privately-owned image. -- run an image built by a previous step. - run a specific step in docker. +- run an image built by a previous step. - See https://github.com/addnab/docker-run-action/blob/main/action.yml for all the available inputs. #### Typical Use Case diff --git a/entrypoint.sh b/entrypoint.sh index cb62a39..e07cdbe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,4 +6,8 @@ fi echo "$INPUT_RUN" | sed -e 's/\\n/;/g' > semicolon_delimited_script -exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" --network=$INPUT_DOCKER_NETWORK $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`" +if [ ! -z $INPUT_DOCKER_NETWORK ]; +then INPUT_OPTIONS="$INPUT_OPTIONS --network $INPUT_DOCKER_NETWORK" +fi + +exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`" From f9c1c286e0c041248e793202e857ce21190fcc21 Mon Sep 17 00:00:00 2001 From: Abdud Dayan Adeeb Date: Mon, 15 Feb 2021 16:28:52 -0500 Subject: [PATCH 4/6] test: test docker version --- .github/workflows/1-tests.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/1-tests.yml b/.github/workflows/1-tests.yml index cdeee24..4479f2e 100644 --- a/.github/workflows/1-tests.yml +++ b/.github/workflows/1-tests.yml @@ -12,11 +12,15 @@ jobs: steps: - uses: actions/checkout@v2 - uses: ./ + id: run-docker with: image: docker:20.10.3 run: | - echo "::set-output name=image_name::`uname -r`" + echo "::set-output name=docker-version::`echo $DOCKER_VERSION`" - uses: actions/github-script@v3 with: script: | - console.log(core.getOutput('image_name')) + const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}'; + if (dockerVersion !== '20.10.4') { + core.setFailed(`Smoke Test Failed`); + } From a34de162064bf288811120d75228ce77fa900225 Mon Sep 17 00:00:00 2001 From: Abdud Dayan Adeeb Date: Mon, 15 Feb 2021 16:52:12 -0500 Subject: [PATCH 5/6] test: adding volume mount test --- .github/workflows/1-tests.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/1-tests.yml b/.github/workflows/1-tests.yml index 4479f2e..1851b20 100644 --- a/.github/workflows/1-tests.yml +++ b/.github/workflows/1-tests.yml @@ -21,6 +21,25 @@ jobs: with: script: | const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}'; - if (dockerVersion !== '20.10.4') { + if (dockerVersion !== '20.10.3') { core.setFailed(`Smoke Test Failed`); } + volume-mount-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: echo "some text" > someFile + - uses: ./ + id: run-docker + with: + image: docker + options: -v ${{ github.workspace }}:/work + run: | + echo "::set-output name=file-contents::`cat /work/someFile`" + - uses: actions/github-script@v3 + with: + script: | + const fileContents = '${{ steps.run-docker.outputs.file-contents }}'; + if (fileContents !== 'some text') { + core.setFailed(`Unable to mount workspace volume`); + } From 8279676ac55babf906e0e2b5009e041514b8da23 Mon Sep 17 00:00:00 2001 From: Abdud Dayan Adeeb Date: Mon, 15 Feb 2021 17:06:32 -0500 Subject: [PATCH 6/6] test: add container network test --- .github/workflows/{1-tests.yml => tests.yml} | 37 +++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) rename .github/workflows/{1-tests.yml => tests.yml} (51%) diff --git a/.github/workflows/1-tests.yml b/.github/workflows/tests.yml similarity index 51% rename from .github/workflows/1-tests.yml rename to .github/workflows/tests.yml index 1851b20..66589bc 100644 --- a/.github/workflows/1-tests.yml +++ b/.github/workflows/tests.yml @@ -11,13 +11,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: ./ + - name: Run docker action and set output for testing + uses: ./ id: run-docker with: image: docker:20.10.3 run: | echo "::set-output name=docker-version::`echo $DOCKER_VERSION`" - - uses: actions/github-script@v3 + - name: Test the output + uses: actions/github-script@v3 with: script: | const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}'; @@ -28,18 +30,43 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: echo "some text" > someFile - - uses: ./ + - name: Create File to be mounted + run: echo "some text" > someFile + - name: Run docker action with mounted workspace + uses: ./ id: run-docker with: image: docker options: -v ${{ github.workspace }}:/work run: | echo "::set-output name=file-contents::`cat /work/someFile`" - - uses: actions/github-script@v3 + - name: Check if file contents match + uses: actions/github-script@v3 with: script: | const fileContents = '${{ steps.run-docker.outputs.file-contents }}'; if (fileContents !== 'some text') { core.setFailed(`Unable to mount workspace volume`); } + container-network-test: + runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: test + POSTGRES_USER: test + POSTGRES_DB: test + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 + steps: + - uses: actions/checkout@v2 + - name: Run docker action and test network connection + uses: ./ + with: + image: postgres + run: > + pg_isready -d test -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} + options: > + -e PGPASSWORD=test