Skip to content

Commit

Permalink
chore: makes docker build produce a runnable wait-for image (#2) Than…
Browse files Browse the repository at this point in the history
…ks to @gesellix

This change alters the Dockerfile used in this project. Now, it is a multi-stage Dockerfile with one stage which can be used to run the tests and one stage which is a runnable image including the wait-for script.

In this way, we run the tests in a similar-ish* environment as what the script runs in when distributed as a container image.

*The tests are setup and ran using Node and npm. The final image doesn't include those two dependencies to create a more slim image.

Co-authored-by: Adriaan Knapen <[email protected]>
  • Loading branch information
gesellix and Addono authored Jan 9, 2023
1 parent 0603278 commit a93c5f7
Show file tree
Hide file tree
Showing 7 changed files with 6,554 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Build the test Docker image
run: docker build --tag wait-for .
run: docker build --no-cache --target test-env --tag wait-for-test .

- name: Run the tests
run: docker run --tty wait-for
run: docker run wait-for-test

release:
name: Release
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

# Node
node_modules

delay
32 changes: 25 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
FROM node:16-alpine@sha256:a9b9cb880fa429b0bea899cd3b1bc081ab7277cc97e6d2dcd84bd9753b2027e1
#################
# Base layer #
#################
FROM alpine:edge as runtime-base

# Install bash
RUN apk add --no-cache bash
# Install all dependencies
RUN apk add --no-cache bash nmap-ncat wget

# Create working directory
RUN mkdir -p /app
WORKDIR /app

#################
# Test image #
#################
FROM runtime-base as test-env

# Install Node.js
RUN apk add --no-cache nodejs npm

# Install all Node dependencies
COPY package.json /app/
COPY package-lock.json /app/

RUN npm ci

# Copy source code
COPY . /app/

# Define default command
# Perform tests when running this test-env container
CMD npm test

#################
# Runtime image #
#################
FROM runtime-base as runtime

COPY ./wait-for .

ENTRYPOINT ["./wait-for"]
CMD ["--help"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ services:
Testing is done using [bats](https://github.com/bats-core/bats-core), which we install using [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
For reproducability, we run our tests inside Docker, such that we have control over the version of [bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>) we're testing against.
For reproducibility, we run our tests inside Docker, such that we have control over the version of [bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>) we're testing against.
```bash
docker build -t wait-for .
docker build --target test-env --tag wait-for .
docker run --rm -t wait-for
```

Expand Down
Loading

0 comments on commit a93c5f7

Please sign in to comment.