Skip to content

Commit

Permalink
Merge pull request #46 from bacpop/bacpop-145
Browse files Browse the repository at this point in the history
bacpop-145 Docker quick run
  • Loading branch information
richfitz authored Feb 12, 2024
2 parents 9a070c0 + f344503 commit 12673ff
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 22 deletions.
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
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: 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"
}
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
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
9 changes: 7 additions & 2 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 @@ -20,7 +25,7 @@ docker run -d --rm --name $NAME_WORKER --network=$NETWORK \
docker run -d --rm --name $NAME_API --network=$NETWORK \
--env=REDIS_HOST="$NAME_REDIS" \
--env=STORAGE_LOCATION="./storage" \
--env=DB_LOCATION="./storage/GPS_v6_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 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

0 comments on commit 12673ff

Please sign in to comment.