From 75ea5c6d60898e7489598b82b374b89423543849 Mon Sep 17 00:00:00 2001 From: Malcolm Landon Date: Thu, 12 Mar 2020 15:03:07 +0000 Subject: [PATCH] Update to run against persona.talis.local when running locally. (#15) --- Dockerfile | 2 +- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++-- docker-compose.yml | 10 +++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65ae7fb..3bddb31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ RUN apt-get -y autoremove && apt-get clean && apt-get autoclean && \ RUN mkdir -p /var/talis-php COPY . /var/talis-php -RUN echo "export PERSONA_TEST_HOST='https://staging-users.talis.com'" >> /etc/profile.d/test.sh \ +RUN echo "export PERSONA_TEST_HOST='http://persona.talis.local'" >> /etc/profile.d/test.sh \ && echo "export PERSONA_TEST_OAUTH_CLIENT='$persona_oauth_client'" >> /etc/profile.d/test.sh \ && echo "export PERSONA_TEST_OAUTH_SECRET='$persona_oauth_secret'" >> /etc/profile.d/test.sh \ && chmod 775 /etc/profile.d/test.sh diff --git a/README.md b/README.md index 4fa024a..a11fa5f 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,47 @@ git clone https://github.com/talis/talis-php.git cd talis-php ``` +# Run Persona Locally + +Integration tests run locally will make requests to Persona at `http://persona.talis.local`. + +Before you begin, ensure you have established `DEVELOPMENT_WORK_DIR` and the `infra` repository, as per [the shared project instructions](https://github.com/talis/infra/wiki). + +Manually run persona locally: + +```bash +./docker-compose-dev.sh persona-server +``` + +# Create an OAuth Client and Secret + +To build the talis-php docker container, you need to specify an oauth client and secret to use. This client should have `su` scope. It's not possibe to create a client with `su` scope via the API. + +First - create a client: + +```bash +curl -v -H "Authorization:Bearer $LOCAL_TOKEN" -d "{\"scope\":[\"su@test\"]}" http://persona.talis.local/clients +``` + +This will return a client: + +```json +{"client_id":"BXLmKR79","client_secret":"zdlbESLEFGvxBw8k"} +``` + +Then connect to the mongo database the local persona is using and manually give the client `su` scope. + +# Build talis-php Docker Container + Manually run a docker build: ```bash docker build -t "talis/talis-php" --network=host --build-arg persona_oauth_client= --build-arg persona_oauth_secret= . ``` -`persona_oauth_client` = the persona user you want to use. +`persona_oauth_client` = the persona user you want to use, "BXLmKR79" from the above example. -`persona_oauth_secret` = the password to the user specified. +`persona_oauth_secret` = the password to the user specified, "zdlbESLEFGvxBw8k" from the above example. Initialise the environment. Run the following command which will download the required libraries. @@ -57,3 +89,22 @@ docker-compose run test docker-compose run unittest docker-compose run integrationtest ``` + +To create a docker container where you can run commands directly, for example to run individual tests: + +```bash +docker-compose run local-dev +``` + +When connected run: + +```bash +service redis-server start +source /etc/profile.d/* +``` + +You can the bun ant commands individually or run individual tests: + +```bash +/vendor/bin/phpunit --filter testCreateUserThenPatchOAuthClientAddScope test/integration/ +``` diff --git a/docker-compose.yml b/docker-compose.yml index f413ba8..1eeba7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,21 +23,31 @@ services: command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant code-check" test: image: talis/talis-php + network_mode: host volumes: - ".:/var/talis-php" command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant test" unittest: image: talis/talis-php + network_mode: host volumes: - ".:/var/talis-php" command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant unittest" integrationtest: image: talis/talis-php + network_mode: host volumes: - ".:/var/talis-php" command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant integrationtest" + local-dev: + image: talis/talis-php + network_mode: host + volumes: + - ".:/var/talis-php" + command: /bin/bash coverage: image: talis/talis-php + network_mode: host volumes: - ".:/var/talis-php" command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant coverage"