From 7cc5f83da1e79f20ae43e8a5ce6dfb59f167fd1a Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 12:29:49 -0500 Subject: [PATCH 01/11] Convert to Github Action --- .github/workflows/pull-request.yaml | 23 ++++++++ Dockerfile | 8 +++ README.md | 85 +++++++---------------------- action.yaml | 35 ++++++++++++ 4 files changed, 85 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/pull-request.yaml create mode 100644 Dockerfile create mode 100644 action.yaml diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml new file mode 100644 index 0000000..7b66486 --- /dev/null +++ b/.github/workflows/pull-request.yaml @@ -0,0 +1,23 @@ +on: + pull_request: + branches: + - main + +jobs: + wait_for_it: + runs-on: ubuntu-latest + name: Ensure action works + steps: + - name: Start local server on port 80 + run: python -m SimpleHTTPServer 80 + - name: Start local server on port 3000 + run: python -m SimpleHTTPServer 80 + - name: Defaults + uses: actions/wait-for-it@v1 + with: + host: localhost + - name: Non-default port + uses: actions/wait-for-it@v1 + with: + host: localhost + port: 3000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..339b8c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# Container image that runs your code +FROM alpine:3.15 + +# Copies your code file from your action repository to the filesystem path `/` of the container +COPY wait-for-it.sh /wait-for-it.sh + +# Code file to execute when the docker container starts up (`entrypoint.sh`) +ENTRYPOINT ["/wait-for-it.sh"] \ No newline at end of file diff --git a/README.md b/README.md index d08d5a2..472ad00 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,28 @@ -# wait-for-it +# wait-for-it.sh Github Action -`wait-for-it.sh` is a pure bash script that will wait on the availability of a -host and TCP port. It is useful for synchronizing the spin-up of -interdependent services, such as linked docker containers. Since it is a pure -bash script, it does not have any external dependencies. - -## Usage +`wait-for-it.sh` is a pure bash script to wait on the availability of a host and TCP port. -```text -wait-for-it.sh host:port [-s] [-t timeout] [-- command args] --h HOST | --host=HOST Host or IP under test --p PORT | --port=PORT TCP port under test - Alternatively, you specify the host and port as host:port --s | --strict Only execute subcommand if the test succeeds --q | --quiet Don't output any status messages --t TIMEOUT | --timeout=TIMEOUT - Timeout in seconds, zero for no timeout --- COMMAND ARGS Execute command with args after the test finishes -``` - -## Examples +Since it is a pure +bash script, it does not have any external dependencies. -For example, let's test to see if we can access port 80 on `www.google.com`, -and if it is available, echo the message `google is up`. +This Github Action is based on a fork of the original [wait-for-it.sh](https://github.com/vishnubob/wait-for-it), and simply adds the `Dockerfile` and `action.yaml` needed to configure the shell script for use. -```text -$ ./wait-for-it.sh www.google.com:80 -- echo "google is up" -wait-for-it.sh: waiting 15 seconds for www.google.com:80 -wait-for-it.sh: www.google.com:80 is available after 0 seconds -google is up +## Usage ``` - -You can set your own timeout with the `-t` or `--timeout=` option. Setting -the timeout value to 0 will disable the timeout: - -```text -$ ./wait-for-it.sh -t 0 www.google.com:80 -- echo "google is up" -wait-for-it.sh: waiting for www.google.com:80 without a timeout -wait-for-it.sh: www.google.com:80 is available after 0 seconds -google is up +- id: wait-for-it + runs: elijahboston/wait-for-it + with: + host: localhost + port: 80 + timeout: 60 + strict: false + quiet: false ``` -The subcommand will be executed regardless if the service is up or not. If you -wish to execute the subcommand only if the service is up, add the `--strict` -argument. In this example, we will test port 81 on `www.google.com` which will -fail: - -```text -$ ./wait-for-it.sh www.google.com:81 --timeout=1 --strict -- echo "google is up" -wait-for-it.sh: waiting 1 seconds for www.google.com:81 -wait-for-it.sh: timeout occurred after waiting 1 seconds for www.google.com:81 -wait-for-it.sh: strict mode, refusing to execute subprocess +Most parameters are optional, only the host is required: ``` - -If you don't want to execute a subcommand, leave off the `--` argument. This -way, you can test the exit condition of `wait-for-it.sh` in your own scripts, -and determine how to proceed: - -```text -$ ./wait-for-it.sh www.google.com:80 -wait-for-it.sh: waiting 15 seconds for www.google.com:80 -wait-for-it.sh: www.google.com:80 is available after 0 seconds -$ echo $? -0 -$ ./wait-for-it.sh www.google.com:81 -wait-for-it.sh: waiting 15 seconds for www.google.com:81 -wait-for-it.sh: timeout occurred after waiting 15 seconds for www.google.com:81 -$ echo $? -124 +- id: wait-for-it + runs: elijahboston/wait-for-it + with: + host: localhost ``` - -## Community - -*Debian*: There is a [Debian package](https://tracker.debian.org/pkg/wait-for-it). diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..64ab24a --- /dev/null +++ b/action.yaml @@ -0,0 +1,35 @@ +name: 'wait-for-it' +description: 'Wait for a response' +inputs: + host: + description: 'Host or IP under test' + required: true + port: + description: 'TCP port under test, default: 80' + required: false + default: '80' + strict: + description: 'Only execute subcommand if the test succeeds' + required: false + default: 'false' + timeout: + description: 'Timeout in seconds, zero for no timeout' + required: true + default: '60' + command: + description: 'Execute command after the test has completed' + required: false + quiet: + description: "Don't output any status messages" + required: false + default: 'false' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - --host ${{ inputs.host }} + - --port ${{ inputs.port }} + - --strict ${{ inputs.strict }} + - --timeout ${{ inputs.timeout }} + - --quiet ${{ inputs.quiet }} + - -- ${{ inputs.command }} \ No newline at end of file From ccd8874b6655c01f567adc8fed6bd243f28b148e Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 12:51:18 -0500 Subject: [PATCH 02/11] use local action --- .github/workflows/pull-request.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 7b66486..ec863c5 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -13,11 +13,11 @@ jobs: - name: Start local server on port 3000 run: python -m SimpleHTTPServer 80 - name: Defaults - uses: actions/wait-for-it@v1 + uses: ./ with: host: localhost - name: Non-default port - uses: actions/wait-for-it@v1 + uses: ./ with: host: localhost port: 3000 From d695acb5d90a1c0d700da3188120fa65b665802a Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 12:52:48 -0500 Subject: [PATCH 03/11] checkout first --- .github/workflows/pull-request.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index ec863c5..aa7b9d1 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -8,6 +8,8 @@ jobs: runs-on: ubuntu-latest name: Ensure action works steps: + - name: Checkout + uses: actions/checkout@v2 - name: Start local server on port 80 run: python -m SimpleHTTPServer 80 - name: Start local server on port 3000 From 7862761f132a43d9da07f362e23857a6c4f9ff44 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 12:54:49 -0500 Subject: [PATCH 04/11] make executable --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 339b8c8..b8259e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM alpine:3.15 # Copies your code file from your action repository to the filesystem path `/` of the container COPY wait-for-it.sh /wait-for-it.sh +RUN chmod +x wait-for-it.sh # Code file to execute when the docker container starts up (`entrypoint.sh`) ENTRYPOINT ["/wait-for-it.sh"] \ No newline at end of file From c40d175b7c93187ee7f51dbe449f24b97e520d82 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 13:00:53 -0500 Subject: [PATCH 05/11] fix branch name --- .github/workflows/pull-request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index aa7b9d1..c19ec0d 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -1,7 +1,7 @@ on: pull_request: branches: - - main + - master jobs: wait_for_it: From 8eb2a13bc79a59599d8c16d2a316021d154713eb Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 13:03:09 -0500 Subject: [PATCH 06/11] use mini_httpd --- .github/workflows/pull-request.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index c19ec0d..4c9cc09 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -11,9 +11,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Start local server on port 80 - run: python -m SimpleHTTPServer 80 + run: mini_httpd & - name: Start local server on port 3000 - run: python -m SimpleHTTPServer 80 + run: mini_httpd -p 3000 & - name: Defaults uses: ./ with: From 8102ecb617db607cf41ee650916398d1d7a88bbb Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 13:08:17 -0500 Subject: [PATCH 07/11] use bash --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b8259e3..d573b61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ COPY wait-for-it.sh /wait-for-it.sh RUN chmod +x wait-for-it.sh # Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/wait-for-it.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "-c", "/wait-for-it.sh"] \ No newline at end of file From bd5c38d9489433dc95ff4ffc46966c57c1ebd7ed Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 13:12:27 -0500 Subject: [PATCH 08/11] install bash --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d573b61..68377d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Container image that runs your code FROM alpine:3.15 - +RUN apk add bash # Copies your code file from your action repository to the filesystem path `/` of the container COPY wait-for-it.sh /wait-for-it.sh RUN chmod +x wait-for-it.sh From 68ca9ef6cd4b70348d09fd15e3ce132d0a02c0b8 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 13:27:56 -0500 Subject: [PATCH 09/11] format --- action.yaml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/action.yaml b/action.yaml index 64ab24a..d48c974 100644 --- a/action.yaml +++ b/action.yaml @@ -14,7 +14,7 @@ inputs: default: 'false' timeout: description: 'Timeout in seconds, zero for no timeout' - required: true + required: false default: '60' command: description: 'Execute command after the test has completed' @@ -27,9 +27,15 @@ runs: using: 'docker' image: 'Dockerfile' args: - - --host ${{ inputs.host }} - - --port ${{ inputs.port }} - - --strict ${{ inputs.strict }} - - --timeout ${{ inputs.timeout }} - - --quiet ${{ inputs.quiet }} - - -- ${{ inputs.command }} \ No newline at end of file + - --host + - ${{ inputs.host }} + - --port + - ${{ inputs.port }} + - --strict + - ${{ inputs.strict }} + - --timeout + - ${{ inputs.timeout }} + - --quiet + - ${{ inputs.quiet }} + - -- + - ${{ inputs.command }} \ No newline at end of file From 02bdf147b48cb7f57a1f258a045ececc1ce0702d Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 25 Feb 2022 13:30:21 -0500 Subject: [PATCH 10/11] format --- action.yaml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/action.yaml b/action.yaml index d48c974..ebda214 100644 --- a/action.yaml +++ b/action.yaml @@ -27,15 +27,9 @@ runs: using: 'docker' image: 'Dockerfile' args: - - --host - - ${{ inputs.host }} - - --port - - ${{ inputs.port }} - - --strict - - ${{ inputs.strict }} - - --timeout - - ${{ inputs.timeout }} - - --quiet - - ${{ inputs.quiet }} - - -- - - ${{ inputs.command }} \ No newline at end of file + - --host=${{ inputs.host }} + - --port=${{ inputs.port }} + - --strict=${{ inputs.strict }} + - --timeout=${{ inputs.timeout }} + - --quiet=${{ inputs.quiet }} + - -- ${{ inputs.command }} \ No newline at end of file From ad1b8f2747f6f9854e8be3798475e79994742532 Mon Sep 17 00:00:00 2001 From: Elijah Date: Tue, 1 Mar 2022 14:54:42 -0500 Subject: [PATCH 11/11] use httpd service --- .github/workflows/pull-request.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 4c9cc09..c4e9e8b 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -7,19 +7,24 @@ jobs: wait_for_it: runs-on: ubuntu-latest name: Ensure action works + services: + test-site-80: + image: httpd + options: >- + -p 3000 + test-site-3000: + image: httpd + options: >- + -p 3000 steps: - name: Checkout uses: actions/checkout@v2 - - name: Start local server on port 80 - run: mini_httpd & - - name: Start local server on port 3000 - run: mini_httpd -p 3000 & - name: Defaults uses: ./ with: - host: localhost + host: test-site-80 - name: Non-default port uses: ./ with: - host: localhost + host: test-site-3000 port: 3000