Skip to content

Commit

Permalink
make docker container interactive so that e.g. ctrl-c works
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehesluke committed Mar 28, 2024
1 parent e37f1e3 commit 09cb364
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 66 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/code-tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Code Tests

on:
push:
branches: [ feature/docker-and-package-upgrades-new ]
# This does not run on push to master, as tests will instead be run there as
# part of the docker.yml workflow.
# push:
# branches: [ master ]
pull_request:
branches: [ master ]

Expand Down
24 changes: 20 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: Docker Publish
on:
push:
branches: [ feature/docker-and-package-upgrades-new ]
# branches: [ master ]

jobs:
# Publish to GitHub Container Registry
build-and-push-docker-image:
# Publish to GitHub Container Registry
# Master branch only
# Master branch only - extra checks
# if: ${{ github.ref == 'refs/heads/master' }}
# needs:
# - tests
needs: code-tests
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -47,3 +47,19 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Copied from code-tests.yml, TODO: Remove this duplication
code-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout OpenActive Test Suite
uses: actions/checkout@v2
- name: Setup Node.js 18.17.1
uses: actions/setup-node@v1
with:
node-version: 18.17.1
- name: Install OpenActive Test Suite
run: npm install
- name: Run Checks on the Code (Test the Tests!)
run: npm test

86 changes: 43 additions & 43 deletions .github/workflows/reference-implementation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Reference Implementation

on:
push:
branches: [ feature/docker-and-package-upgrades-new ]
branches: [ master ]
pull_request:
branches: [ master ]

Expand Down Expand Up @@ -125,45 +125,45 @@ jobs:
force_orphan: true
enable_jekyll: true

build-and-push-docker-image:
# Publish to GitHub Container Registry
# Master branch only
# if: ${{ github.ref == 'refs/heads/master' }}
# needs:
# - tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for OpenActive Test Suite
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/openactive/test-suite
labels: |
org.opencontainers.image.title=OpenActive Test Suite
org.opencontainers.image.description=Test suite for OpenActive data publishing and Open Booking API implementations
org.opencontainers.image.vendor=OpenActive
tags: |
latest
- name: Build and push Docker image for OpenActive Test Suite
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# build-and-push-docker-image:
# # Publish to GitHub Container Registry
# # Master branch only
# # if: ${{ github.ref == 'refs/heads/master' }}
# # needs:
# # - tests
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# env:
# REGISTRY: ghcr.io
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Log in to the Container registry
# uses: docker/login-action@v2
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Extract metadata (tags, labels) for OpenActive Test Suite
# id: meta
# uses: docker/metadata-action@v4
# with:
# images: ${{ env.REGISTRY }}/openactive/test-suite
# labels: |
# org.opencontainers.image.title=OpenActive Test Suite
# org.opencontainers.image.description=Test suite for OpenActive data publishing and Open Booking API implementations
# org.opencontainers.image.vendor=OpenActive
# tags: |
# latest

# - name: Build and push Docker image for OpenActive Test Suite
# uses: docker/build-push-action@v4
# with:
# context: .
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ COPY --chown=node:node . /openactive-test-suite/

# Expose port 3000 for openactive-broker-microservice
EXPOSE 3000
## Specify the working directory explicitly as GitHub Actions will overwrite it
## Copy any config file specified by `INPUT_CONFIG` to the config directory (used by GitHub Actions)
ENTRYPOINT ( [ -f "${INPUT_CONFIG}" ] && cp "${INPUT_CONFIG}" /openactive-test-suite/config/ ) ; cd /openactive-test-suite && npm start -- "$@"
# ENTRYPOINT rc-status; rc-service sshd start; echo 'IP Address:'; hostname -i; echo 'Hostname:'; hostname; echo 'Hostname (full):'; hostname -f; echo 'Hostname (short):'; hostname -s; echo 'Starting...'; ( [ -f "${INPUT_CONFIG}" ] && cp "${INPUT_CONFIG}" /openactive-test-suite/config/ ) ; cd /openactive-test-suite && npm start ; sleep 60m

RUN chmod +x /openactive-test-suite/docker-entrypoint.sh
ENTRYPOINT ["/openactive-test-suite/docker-entrypoint.sh"]
# ## Specify the working directory explicitly as GitHub Actions will overwrite it
# ## Copy any config file specified by `INPUT_CONFIG` to the config directory (used by GitHub Actions)
# ENTRYPOINT ( [ -f "${INPUT_CONFIG}" ] && cp "${INPUT_CONFIG}" /openactive-test-suite/config/ ) ; cd /openactive-test-suite && npm start -- "$@"
# # ENTRYPOINT rc-status; rc-service sshd start; echo 'IP Address:'; hostname -i; echo 'Hostname:'; hostname; echo 'Hostname (full):'; hostname -f; echo 'Hostname (short):'; hostname -s; echo 'Starting...'; ( [ -f "${INPUT_CONFIG}" ] && cp "${INPUT_CONFIG}" /openactive-test-suite/config/ ) ; cd /openactive-test-suite && npm start ; sleep 60m
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,11 @@ npm start

Note that running `npm start` in the root `openactive-test-suite` directory will override [`waitForHarvestCompletion`](https://github.com/openactive/openactive-test-suite/tree/feature/project-start-script/packages/openactive-broker-microservice#waitforharvestcompletion) to `true` in `default.json`, so that the `openactive-integration-tests` will wait for the `openactive-broker-microservice` to be ready before it begins the test run.

### GitHub Actions

TODO: Improve README

When using GitHub Actions, setting output directories to `/github/workspace/output` in `NODE_ENV` allows these files to be accessed by subsequent actions.

### Docker

TODO: Improve README
When using `docker run` locally, ensure that you specify `-it` to get the full interactive test suite experience.

When using `docker run` locally, ensure that you specify `-t` to get the full interactive test suite experience.

For example: `docker run -t ghcr.io/openactive/test-suite:latest -- core` is the equivalent of `npm start -- core`.
For example: `docker run -it ghcr.io/openactive/test-suite:latest -- core` is the equivalent of `npm start -- core`.

When using Docker in CI, ensure that `"ci": true`.

Expand All @@ -283,9 +275,7 @@ When using a hostname other than `localhost` for your booking system, it must in

If your config is `./config/dev.json` and there's an output dir `./output/`, then the following will run test suite for "core" tests:

`docker run -t -e INPUT_CONFIG=/config/dev.json -e NODE_ENV=dev -p 3000:3000 -v ${PWD}/config:/config -v ${PWD}/output:/output ghcr.io/openactive/test-suite:latest -- core`


`docker run -it -e INPUT_CONFIG=/config/dev.json -e NODE_ENV=dev -p 3000:3000 -v ${PWD}/config:/config -v ${PWD}/output:/output ghcr.io/openactive/test-suite:latest -- core`

## Test Data Requirements

Expand Down
10 changes: 10 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

## Specify the working directory explicitly as GitHub Actions will overwrite it
## Copy any config file specified by `INPUT_CONFIG` to the config directory (used by GitHub Actions)
if [ -f "${INPUT_CONFIG}" ]; then
cp "${INPUT_CONFIG}" /openactive-test-suite/config/
fi

# Change directory and start the app
cd /openactive-test-suite && exec npm start -- "$@"
1 change: 1 addition & 0 deletions packages/openactive-integration-tests/test/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ module.exports = async () => {
try {
console.log('Purging test dataset cache within local broker microservice...');
await purgeCache();
console.log('...purged');
} catch (error) {
throw new Error(`The broker microservice is unreachable. This is a pre-requisite for the test suite. \n${error}`);
}
Expand Down

0 comments on commit 09cb364

Please sign in to comment.