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

Update to allow K8s deployment #77

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
441ab57
refactor: Update Dockerfile to remove unnecessary code and comments
absternator Jul 23, 2024
eb18aa4
refactor: Update Dockerfile to include npm serve for serving the buil…
absternator Jul 23, 2024
56d5c51
refactor: Update Dockerfile to include npm serve and expose port 3000…
absternator Jul 23, 2024
6a4041f
chore: Update environment variable configuration
absternator Jul 24, 2024
9caecc4
refactor: Update SESSION_SECRET configuration
absternator Jul 24, 2024
c5a8a2e
chore: Update environment variable configuration
absternator Jul 24, 2024
cb0e1ab
refactor: Remove unused code and comments from environment variable c…
absternator Jul 24, 2024
73e7848
refactor: Remove unused code and comments from environment variable c…
absternator Jul 24, 2024
7be7eb6
refactor: Remove unused code and comments from environment variable c…
absternator Jul 24, 2024
4f9f2b2
refactor: Update environment variable configuration
absternator Jul 24, 2024
c86db56
refactor: Remove unused code and comments from environment variable c…
absternator Jul 24, 2024
40ddccc
chore: Update environment variable configuration
absternator Jul 24, 2024
795b7a7
refactor: Update dotenv configuration to use .env.development file
absternator Jul 24, 2024
b448c11
refactor: Update dotenv dependency to version 16.4.5
absternator Jul 24, 2024
c33d377
refactor: Remove commented out code and unnecessary sleep in entrypoi…
absternator Jul 24, 2024
3fda0c8
refactor: Remove commented out code and unnecessary sleep in entrypoi…
absternator Sep 3, 2024
9737f55
refactor: Remove unnecessary code and comments in entrypoint.sh and e…
absternator Sep 3, 2024
3d4bdb8
refactor: Remove unnecessary code and comments in entrypoint.sh and e…
absternator Sep 3, 2024
6a1429c
refactor: Remove unnecessary code and comments in entrypoint.sh and e…
absternator Sep 3, 2024
bd36282
refactor: Update buildConfig to use environment variables for configu…
absternator Sep 3, 2024
82f6e79
fix: tests
absternator Sep 3, 2024
c32b7fd
refactor: Update buildConfig to use environment variables for configu…
absternator Sep 4, 2024
f0b1817
refactor: Configure environment variables in CI workflows
absternator Sep 4, 2024
a6628ad
refactor: Update CI workflows to use environment variables for config…
absternator Sep 4, 2024
24ce1d3
refactor: Update CI workflows to use environment variables for config…
absternator Sep 4, 2024
03658d4
refactor: Update CI workflows to use environment variables for config…
absternator Sep 4, 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
11 changes: 7 additions & 4 deletions .github/workflows/jestCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ on:
- main
- "bacpop-*"

env:
GITHUB_CLIENT_ID: ${{ secrets.CLIENT_ID_GITHUB }}
GITHUB_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET_GITHUB }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}

jobs:
unit_frontend:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -56,10 +63,6 @@ jobs:
cache: "npm"
cache-dependency-path: ./app/server/package-lock.json
- run: npm ci
- name: get config file
run: |
pwd
cp ./src/resources/config.json.in.development ./src/resources/config.json
- name: run all components
working-directory: .
run: ./scripts/run_test server-only
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/playwrightCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ on:
- main
- "bacpop-*"

env:
GITHUB_CLIENT_ID: ${{ secrets.CLIENT_ID_GITHUB }}
GITHUB_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET_GITHUB }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}

jobs:
playwright-tests:
timeout-minutes: 60
Expand All @@ -26,19 +33,13 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: ./app/client-v2/package-lock.json
- name: get config file
run: |
pwd
cp ./app/server/src/resources/config.json.in.development ./app/server/src/resources/config.json
- name: Run all components
working-directory: .
run: ./scripts/run_test
- name: Install playwright
working-directory: ./app/client-v2
run: npx playwright install --with-deps
- name: Run e2e tests
env:
MICROREACT_TOKEN: ${{ secrets.MICROREACT_TOKEN }}
working-directory: ./app/client-v2
run: npm run test:e2e:${{ matrix.browser}}
- name: Stop all components
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ app/server/coverage
.idea
proxy/ssl/production
.vscode
.env

21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ docker --version
```


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.
If you run the application for the first time in development you need to env variables into `.env`.

Login to the vault:
```
export VAULT_ADDR=https://vault.dide.ic.ac.uk:8200
Expand Down Expand Up @@ -78,28 +78,13 @@ You can also run everything outside pm2, by separately running:
- `./scripts/run_client`

## Config
Config for the front-end lives in `./app/client/src/settings` and by default webpack (via the vue-cli) will use the config
defined in `./app/client/src/settings/development`; this gets overriden by setting an env var called `BUILD_TARGET` - see `./proxy/Dockerfile`.

Config for the back-end lives in `./app/server/src/resources`. When deploying using a docker image this file has to be
copied into the running container before the app will start - see `./app/server/docker/entrypoint.sh`.
Config for the back-end should be done via env variables. All needed variables can be found at `./app/server/src/buildConfig.ts`. In development, these are set in `./app/server/.env` which can be set by running `./scripts/decrypt_config`.

## Deploying with 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.

Generate the correct server config file with
```
./scripts/decrypt_config docker
```

Then run the dockerised app with

```
./scripts/run_docker
```

By default this will configure the nginx proxy for host `localhost`. To deploy with a different hostname, pass
it as an argument, e.g.

Expand Down
1 change: 1 addition & 0 deletions app/server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
/dist
.env
2 changes: 1 addition & 1 deletion app/server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ COPY . /app
EXPOSE 4000
RUN npm run build
RUN npm install -g ts-node
ENTRYPOINT ["docker/entrypoint.sh"]
ENTRYPOINT ["ts-node", "--transpile-only", "src/index.ts"]
10 changes: 0 additions & 10 deletions app/server/docker/entrypoint.sh

This file was deleted.

17 changes: 17 additions & 0 deletions app/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.ts",
"scripts": {
"express": "ts-node src/index.ts --config src/resources",
"express": "ts-node src/index.ts",
"test": "jest",
"test:dev": "jest --watch",
"eslint": "eslint src tests --ext .js,.jsx,.ts,.tsx",
Expand All @@ -21,6 +21,7 @@
"axios-mock-adapter": "^1.20.0",
"body-parser": "^1.19.2",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.17.3",
"express-session": "^1.17.2",
"ioredis": "^5.2.4",
Expand Down
14 changes: 0 additions & 14 deletions app/server/src/args.ts

This file was deleted.

13 changes: 13 additions & 0 deletions app/server/src/buildConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// These environment variables can override the default values in the .env file
export const buildConfig = () => ({
server_port: process.env.PORT || 4000,
api_url: process.env.API_URL || "http://localhost:5000",
client_url: process.env.CLIENT_URL || "http://localhost:5173",
server_url: process.env.SERVER_URL || "http://localhost:4000",
redis_url: process.env.REDIS_URL || "redis://localhost:6379",
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
SESSION_SECRET: process.env.SESSION_SECRET,
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID,
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
});
42 changes: 16 additions & 26 deletions app/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import express from "express";
import MockStrategy from 'passport-mock-strategy';
import passport from 'passport';
import passport from "passport";
import MockStrategy from "passport-mock-strategy";

import { configureApp } from './configureApp';
import { router } from './routes/routes';
import { configureApp } from "./configureApp";
import { router } from "./routes/routes";

import fs from "fs";
import path from "path";

import configPath from "./args";
import dotenv from "dotenv";
import { redisConnection } from "./db/redis";
import {initialiseLogging} from "./logging";
import {handleError} from "./errors/handleError";
import { handleError } from "./errors/handleError";
import { initialiseLogging } from "./logging";
import { buildConfig } from "./buildConfig";

const filename = path.join(configPath, "config.json");
dotenv.config();

if (!fs.existsSync(filename)) {
throw new Error(`File ${configPath} does not exist`);
}
const config = buildConfig();

const configText = fs.readFileSync(filename, { encoding: "utf-8" });
const config = JSON.parse(configText);
if (!fs.existsSync(filename)) {
throw new Error(`File ${configPath} does not exist`);
}
const app = express();
initialiseLogging(app);

Expand All @@ -33,20 +24,19 @@ router(app, config);

if (process.env.BEEBOP_TEST === "true") {
passport.use(new MockStrategy());
app.get('/login/mock', passport.authenticate('mock'), (req, res) => {
res.send({ status: 'ok' });
app.get("/login/mock", passport.authenticate("mock"), (req, res) => {
res.send({ status: "ok" });
});
}

const port = process.env.PORT || config.server_port;
app.listen(port, () => {
console.log(`listening on ${port}`);
});

const redis = redisConnection(
config.redis_url,
() => { throw Error(`Failed to connect to redis server ${config.redis_url}`); }
);
const redis = redisConnection(config.redis_url, () => {
throw Error(`Failed to connect to redis server ${config.redis_url}`);
});
app.locals.redis = redis;

app.use(handleError);
12 changes: 0 additions & 12 deletions app/server/src/resources/config.json.in.development

This file was deleted.

12 changes: 0 additions & 12 deletions app/server/src/resources/config.json.in.docker

This file was deleted.

12 changes: 0 additions & 12 deletions app/server/src/resources/config.json.in.production

This file was deleted.

Loading
Loading