Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bacpop-25 use gps v6 db #42

Merged
merged 47 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b803baf
use v6 db
EmmaLRussell Oct 10, 2023
1e74854
pull api image on first run
EmmaLRussell Jan 27, 2024
72d966f
squash lint warning in test file
EmmaLRussell Jan 29, 2024
a0d8b57
correct cache dependency path
EmmaLRussell Jan 29, 2024
44065ef
expect 404 on unexpected sample
EmmaLRussell Jan 29, 2024
8234376
poll more sensibly in test
EmmaLRussell Jan 29, 2024
2405525
debug
EmmaLRussell Jan 29, 2024
5f345a7
bump up timeout
EmmaLRussell Jan 29, 2024
095143d
missing ;
EmmaLRussell Jan 29, 2024
1d46810
add some extra logging to problem test
EmmaLRussell Jan 29, 2024
10e7225
logging fix
EmmaLRussell Jan 30, 2024
790eb67
throw if any error status responses
EmmaLRussell Jan 30, 2024
189cea9
more logging
EmmaLRussell Jan 30, 2024
de3e888
remove previous
EmmaLRussell Jan 30, 2024
97ffd74
comment
EmmaLRussell Jan 30, 2024
000c6da
updates for docker run
EmmaLRussell Feb 5, 2024
f34e7ce
rollback erroneous changes, and revert api branch pin
EmmaLRussell Feb 5, 2024
c6e2223
add github docker env vars
EmmaLRussell Feb 5, 2024
a7bd996
fix broken server container
EmmaLRussell Feb 5, 2024
ab366fd
added docker oauth app for github
EmmaLRussell Feb 5, 2024
0163d1e
add google ids
EmmaLRussell Feb 6, 2024
1883ba5
remove api container on exit
EmmaLRussell Feb 6, 2024
e9da2a9
allow for project hash not yet refistered when check status
EmmaLRussell Feb 6, 2024
e9bdc7c
merge with bacpop-25
EmmaLRussell Feb 6, 2024
d4187f5
npm ci in run scripts, and use db location when run deps
EmmaLRussell Feb 6, 2024
d37f9b3
null check
EmmaLRussell Feb 6, 2024
943648f
polling debug
EmmaLRussell Feb 6, 2024
bda569e
remove debug
EmmaLRussell Feb 6, 2024
2332bae
timeout
EmmaLRussell Feb 6, 2024
0ca15a3
bump up universal timeout but do not allow more than five consecutive…
EmmaLRussell Feb 6, 2024
9a070c0
show details of latest error response when exceed consecutive threshold
EmmaLRussell Feb 6, 2024
f344503
update for latest docker compose
EmmaLRussell Feb 7, 2024
12673ff
Merge pull request #46 from bacpop/bacpop-145
richfitz Feb 12, 2024
9ddfa88
Merge branch 'main' into bacpop-25
richfitz Feb 12, 2024
67a3389
fix smoke test
EmmaLRussell Feb 12, 2024
90c7319
re-add vars to docker-compose
EmmaLRussell Feb 12, 2024
ac27364
use more informative py branch
EmmaLRussell Feb 12, 2024
758e8a5
check assign job id on submit
EmmaLRussell Feb 12, 2024
ae44116
revert api
EmmaLRussell Feb 12, 2024
4bb8a94
use bacpop-151
EmmaLRussell Feb 16, 2024
1036aa3
use debug branch of py and include tmate
EmmaLRussell Feb 19, 2024
2060c5f
try putting tmate on the right workflow...
EmmaLRussell Feb 19, 2024
f5159bb
relax test for specific error string
EmmaLRussell Feb 19, 2024
8a74952
use unique project hash for each test#
EmmaLRussell Feb 19, 2024
12dc93e
use a single worker
EmmaLRussell Feb 19, 2024
248458b
remove allow status failures and target main py branch
EmmaLRussell Feb 19, 2024
c5a050c
remove tmate
EmmaLRussell Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jestCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: ./app/client/package-lock.json
cache-dependency-path: ./app/server/package-lock.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path just seemed to be wrong!

- run: npm ci
- name: get config file
run: |
Expand Down
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# beebop

## Docker Quick Start

Run the dockerised app along with proxy and all dependencies:

```
./scripts/run_docker_decrypt
```

You may need to update your version of Docker and Docker Compose: see [here](https://docs.docker.com/engine/install/ubuntu/) for instructions on updating on Ubuntu.

By default this will configure the nginx proxy for host localhost. To deploy with a different hostname, pass it as an argument, e.g.
```
./scripts/run_docker_decrypt beebop.dide.ic.ac.uk
```

This will also populate app config with secrets from the vault. If you are not running the script for the first time,
or not for the first time since running the app outside docker, you can omit this step by running the `run_docker` script.

Bring down the app with
```
./scripts/stop_docker
```

Docker images are built on CI using `./proxy/docker/build`, `./app/server/docker/build`. If you want
to generate them from changed local sources you can run those same scripts locally to build images.

To target a branch of `beebop_py`, set `API_BRANCH` in `scripts/common`.

When running locally in docker, the backend is serving from `beebop_beebop-server_1`, and the front end from the proxy
container `beebop_proxy_1`.

## Local development

Clone the repository to your computer with
Expand All @@ -15,7 +46,8 @@ docker --version
```


If you run the application for the first time, you need to replace the secrets in the config file in `app/server/src/resources` first.
If you run the application for the first time (or for the first time after running in docker), you need to replace the
secrets in the config file in `app/server/src/resources` first.
Login to the vault:
```
export VAULT_ADDR=https://vault.dide.ic.ac.uk:8200
Expand Down
2 changes: 1 addition & 1 deletion app/client/tests/unit/components/SavedProjects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import EditProjectName from "@/components/projects/EditProjectName.vue";

const { toLocaleString } = Date.prototype;
// eslint-disable-next-line no-extend-native
// eslint-disable-next-line no-extend-native, func-names
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling this rule here to remove lint warning .

Date.prototype.toLocaleString = function (locale: any = undefined, ...args: any) {
const options = args[0];
return toLocaleString.call(this, "en-GB", { ...options, timeZone: "UTC" });
Expand Down
1 change: 1 addition & 0 deletions app/server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ RUN npm ci
COPY . /app
EXPOSE 4000
RUN npm run build
RUN npm install -g ts-node
ENTRYPOINT ["docker/entrypoint.sh"]
2 changes: 1 addition & 1 deletion app/server/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ while [ ! -e $PATH_CONFIG ]; do
sleep 1
done

node dist/index.js --config /app/src/resources
ts-node --transpile-only src/index.ts --config src/resources
3 changes: 2 additions & 1 deletion app/server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 120000
testTimeout: 120000,
maxWorkers: 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...but I think the main issue was that the persistence tests were blitzing redis, and they were potentially running in parallel with the error tests. So limiting to sequential run here...

};
3 changes: 1 addition & 2 deletions app/server/src/resources/config.json.in.development
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"GOOGLE_CLIENT_SECRET": "$GOOGLE_SECRET",
"SESSION_SECRET": "$EXPRESS_SESSION_SECRET",
"GITHUB_CLIENT_ID":"$GITHUB_ID",
"GITHUB_CLIENT_SECRET":"$GITHUB_SECRET",
"skip_auth": false
"GITHUB_CLIENT_SECRET":"$GITHUB_SECRET"
}
11 changes: 5 additions & 6 deletions app/server/src/resources/config.json.in.docker
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"server_port": 4000,
"api_url": "http://beebop-py-api:5000",
"client_url": "http://localhost",
"client_url": "https://localhost",
"server_url": "https://localhost/api",
"redis_url": "redis://beebop-redis:6379",
"GOOGLE_CLIENT_ID": "1234",
"GOOGLE_CLIENT_SECRET": "1234",
"GOOGLE_CLIENT_ID": "$DOCKER_GOOGLE_ID",
"GOOGLE_CLIENT_SECRET": "$DOCKER_GOOGLE_SECRET",
"SESSION_SECRET": "1234",
"GITHUB_CLIENT_ID": "1234",
"GITHUB_CLIENT_SECRET": "1234",
"skip_auth": true
"GITHUB_CLIENT_ID": "$DOCKER_GITHUB_ID",
"GITHUB_CLIENT_SECRET": "$DOCKER_GITHUB_SECRET"
}
3 changes: 1 addition & 2 deletions app/server/src/resources/config.json.in.production
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"GOOGLE_CLIENT_SECRET": "$PROD_GOOGLE_SECRET",
"SESSION_SECRET": "$PROD_EXPRESS_SESSION_SECRET",
"GITHUB_CLIENT_ID":"$PROD_GITHUB_ID",
"GITHUB_CLIENT_SECRET":"$PROD_GITHUB_SECRET",
"skip_auth": false
"GITHUB_CLIENT_SECRET":"$PROD_GITHUB_SECRET"
}
23 changes: 13 additions & 10 deletions app/server/tests/integration/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {flushRedis, get, post, saveRedisHash, saveRedisSet} from "./utils";
import {uid} from "uid";
import {setTimeout} from "timers/promises";
import {testSample} from "./testSample";

describe("Error handling", () => {
Expand All @@ -11,8 +12,9 @@ describe("Error handling", () => {
connectionCookie = response.headers["set-cookie"][0];
});

const sampleHash = Object.keys(testSample.names)[0];
const sampleFileName = testSample.names[sampleHash] ;
const names = testSample("" ,"").names;
const sampleHash = Object.keys(names)[0];
const sampleFileName = names[sampleHash] ;
const sampleId = `${sampleHash}:${sampleFileName}`;

const newProject = async () => {
Expand Down Expand Up @@ -40,22 +42,23 @@ describe("Error handling", () => {
expect(amrRes.status).toBe(200);

// 3. Run poppunk and wait til it finishes
testSample.projectId = projectId;
const poppunkRes = await post(`poppunk`, testSample, connectionCookie);
const fakeProjectHash = `${projectId}ABC`;
const projectData = testSample(fakeProjectHash, projectId);
const poppunkRes = await post(`poppunk`, projectData, connectionCookie);
Comment on lines +45 to +47
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think part of the problem was that we weren't using a unique project hash every time we ran poppunk, so I've changed testSample from an object to a function, and making a new hash for each new project id...

expect(poppunkRes.status).toBe(200);
const counter = 0;
expect(poppunkRes.data.data.assign).not.toBe("")
let counter = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This counter hadn't been counting!

let finished = false;
while (!finished && counter < 100) {
await new Promise(resolve => {
setTimeout(() => {resolve(""), 1000})
});
const statusRes = await post("status", {hash: testSample.projectHash}, connectionCookie);
await setTimeout(2000);
Copy link
Collaborator Author

@EmmaLRussell EmmaLRussell Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous attempt at delays between polling hadn't been working, so we were getting some intermittent test failures, which I think were related to spamming the endpoint. Bumping up the delay as well to avoid intermittent errors on first poll .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use fake timers here instead if possible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, as we're waiting for a popunk job to finish and polling the real beebop_py api.

const statusRes = await post("status", {hash: fakeProjectHash}, connectionCookie);
expect(statusRes.status).toBe(200);
const statusValues = statusRes.data.data;
if (statusValues.assign === "finished" && statusValues.microreact === "finished" && statusValues.network === "finished") {
if (statusValues && statusValues.assign === "finished" && statusValues.microreact === "finished" && statusValues.network === "finished") {
finished = true;
break;
}
counter = counter + 1;
}
expect(finished).toBe(true);
return projectId;
Expand Down
2 changes: 1 addition & 1 deletion app/server/tests/integration/testSample.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ services:
- beebop-py-api
- beebop-redis
beebop-py-api:
image: mrcide/beebop-py:main
image: mrcide/beebop-py:${API_BRANCH}
depends_on:
- beebop-redis
volumes:
- beebop-storage:/beebop/storage
environment:
- REDIS_HOST=beebop-redis
- STORAGE_LOCATION=./storage
- DB_LOCATION=./storage/GPS_v4_references
- DB_LOCATION=${DB_LOCATION}
beebop-redis:
image: redis:5.0
beebop-py-worker:
image: mrcide/beebop-py:main
image: mrcide/beebop-py:${API_BRANCH}
depends_on:
- beebop-redis
command:
Expand Down
2 changes: 2 additions & 0 deletions scripts/common
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export API_BRANCH=main
export DB_LOCATION="./storage/GPS_v6_references"
4 changes: 4 additions & 0 deletions scripts/decrypt_config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ FILE_CLEAR_SERVER=app/server/src/resources/config.json

export GITHUB_ID=$(vault read -field=clientid secret/beebop/auth/github)
export GITHUB_SECRET=$(vault read -field=secret secret/beebop/auth/github)
export DOCKER_GITHUB_ID=$(vault read -field=clientid secret/beebop/auth/devdocker/github)
export DOCKER_GITHUB_SECRET=$(vault read -field=secret secret/beebop/auth/devdocker/github)
export DOCKER_GOOGLE_ID=$(vault read -field=clientid secret/beebop/auth/devdocker/google)
export DOCKER_GOOGLE_SECRET=$(vault read -field=secret secret/beebop/auth/devdocker/google)
export PROD_GITHUB_ID=$(vault read -field=clientid secret/beebop/auth/production/github)
export PROD_GITHUB_SECRET=$(vault read -field=secret secret/beebop/auth/production/github)
export PROD_GOOGLE_ID=$(vault read -field=clientid secret/beebop/auth/production/google)
Expand Down
1 change: 1 addition & 0 deletions scripts/docker_smoke_test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function cleanup() {
}
trap cleanup EXIT

cp app/server/src/resources/config.json.in.docker app/server/src/resources/config.json
$HERE/run_docker

URL=https://localhost
Expand Down
4 changes: 4 additions & 0 deletions scripts/run_client
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#!/usr/bin/env bash
set -ex

npm ci --prefix app/client
npm run --prefix app/client serve
11 changes: 8 additions & 3 deletions scripts/run_dependencies
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env bash
set -ex

HERE=$(realpath "$(dirname $0)")
. $HERE/common

NETWORK=beebop_nw
VOLUME=beebop-storage
NAME_REDIS=beebop-redis
NAME_API=beebop-py-api
API_BRANCH=main
NAME_WORKER=beebop-py-worker
PORT=5000

Expand All @@ -14,13 +19,13 @@ docker network create $NETWORK > /dev/null || /bin/true
docker run -d --rm --name $NAME_REDIS --network=$NETWORK -p 6379:6379 redis:5.0
docker run -d --rm --name $NAME_WORKER --network=$NETWORK \
--env=REDIS_HOST="$NAME_REDIS" \
--pull always \
-v $VOLUME:/beebop/storage \
mrcide/beebop-py:$API_BRANCH rqworker
docker run -d --rm --name $NAME_API --network=$NETWORK \
--pull always \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this pull not be retained? also the --rm?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rm should! I'll re-add that. I've moved the pull to previous docker run, which is for the same image - mrcide/beebop-py:$API_BRANCH

--env=REDIS_HOST="$NAME_REDIS" \
--env=STORAGE_LOCATION="./storage" \
--env=DB_LOCATION="./storage/GPS_v4_references" \
--env=DB_LOCATION="$DB_LOCATION" \
-v $VOLUME:/beebop/storage \
-p $PORT:5000 \
mrcide/beebop-py:$API_BRANCH
18 changes: 11 additions & 7 deletions scripts/run_docker
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -e
set -ex

export GIT_SHA=$(git -C . rev-parse --short=7 HEAD)
HERE=$(realpath "$(dirname $0)")
. $HERE/common

if [ "$#" -eq 1 ]; then
HOST=$1
Expand All @@ -11,10 +12,13 @@ else
SSL_PATH=ssl
fi
export HOST
docker-compose up -d
docker cp app/server/src/resources/config.json.in.docker beebop_beebop-server_1:/app/src/resources/config.json
docker cp proxy/ssl/dhparam.pem beebop_proxy_1:/run/proxy/
docker cp proxy/$SSL_PATH/certificate.pem beebop_proxy_1:/run/proxy/
docker cp proxy/$SSL_PATH/key.pem beebop_proxy_1:/run/proxy/

export GIT_SHA=$(git -C . rev-parse --short=7 HEAD)

docker compose up -d --pull always
docker cp app/server/src/resources/config.json beebop-beebop-server-1:/app/src/resources/config.json
docker cp proxy/ssl/dhparam.pem beebop-proxy-1:/run/proxy/
docker cp proxy/$SSL_PATH/certificate.pem beebop-proxy-1:/run/proxy/
docker cp proxy/$SSL_PATH/key.pem beebop-proxy-1:/run/proxy/
docker run --rm -v beebop_beebop-storage:/beebop/storage mrcide/beebop-py:main \
./scripts/download_db --small storage
6 changes: 6 additions & 0 deletions scripts/run_docker_decrypt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HERE=$(realpath "$(dirname $0)")

export VAULT_ADDR=https://vault.dide.ic.ac.uk:8200
vault login -method=github
. $HERE/decrypt_config docker
. $HERE/run_docker
4 changes: 4 additions & 0 deletions scripts/run_server
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#!/usr/bin/env bash
set -ex

npm ci --prefix app/server
BEEBOP_TEST="true" npm run --prefix app/server express
3 changes: 2 additions & 1 deletion scripts/stop_docker
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e

docker-compose down
docker compose down
docker volume rm beebop_beebop-storage
Loading