Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions .github/workflows/deploy-to-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
port: 22
script: |
cd optimism
echo ${{ secrets.EMAIL_USER }} > email_user
echo ${{ secrets.EMAIL_PASS }} > email_pass
git pull
docker-compose build --build-arg OPTIMISM_API_CLIENT_SIDE_URL=${{ secrets.API_BASE_URL }}
docker-compose down
docker-compose up -d
docker compose down
docker compose up -d
rm email_user
rm email_pass
23 changes: 23 additions & 0 deletions .github/workflows/test-on-new-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run the tests whenever there's a new checkin to develop

on:
push:
branches: [ develop ]

# Allow it to be run manually from the Github Actions tab
workflow_dispatch:

jobs:
# We should add a job to run the tests first...

test:
name: Run the API tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build the Docker image
run: docker build --build-arg=NODE_ENVIRONMENT=testing --build-arg=TEST_FOLDER=test -t test-api ./api
- name: Run the tests
run: docker run --rm=true -t test-api /home/node/app/node_modules/mocha/bin/mocha --recursive --exit --timeout 3500
11 changes: 9 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ FROM node:20

EXPOSE 3001

# Arguments to allow us to run production or test from the same Dockerfile
ARG NODE_ENVIRONMENT=production
ARG TEST_FOLDER=no-test

# This might be handy during debugging
ENV NPM_CONFIG_LOGLEVEL info
ENV NPM_CONFIG_LOGLEVEL=info

ENV NODE_ENV=production
ENV NODE_ENV=$NODE_ENVIRONMENT

# Install global npm modules to the non-root user (called `node` in the default Node container)
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
Expand All @@ -31,8 +35,11 @@ COPY routes routes
COPY migrations migrations
COPY seeds seeds
COPY knexfile.js knexfile.js
COPY $TEST_FOLDER test

# How we want to start the server
# Default to just starting the server, for the test build we'll override this
# see https://github.com/DoESLiverpool/optimism/issues/32 for details
CMD ["node", "/home/node/app/app.js"]

# Now we're at the end, set the user we want to run as
Expand Down
15 changes: 15 additions & 0 deletions api/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
const express = require('express');
const cors = require('cors');
const app = express();
const fs = require('fs');

require('dotenv').config();
const port = process.env.OPTIMISM_API_PORT || 3001;

// Read in the email config from the secrets
var email_user = "NEED TO SET EMAIL USER";
var email_pass = "NEED TO SET EMAIL PASS";
const email_user_path = "/run/secrets/email_user";
const email_pass_path = "/run/secrets/email_pass";
if (fs.existsSync(email_user_path))
{
email_user = fs.readFileSync(email_user_path, { encoding: 'utf8' }).trim();
}
if (fs.existsSync(email_pass_path))
{
email_pass = fs.readFileSync(email_pass_path, { encoding: 'utf8' }).trim();
}

const resourceRoutes = require('./routes/resources');
const resourceTypeRoutes = require('./routes/resourceTypes');
const bookingRoutes = require('./routes/bookings');
Expand Down
Empty file added api/no-test/.keep
Empty file.
27 changes: 25 additions & 2 deletions api/package-lock.json

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

2 changes: 2 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"homepage": "https://github.com/DoESLiverpool/optimism#readme",
"dependencies": {
"@vscode/sqlite3": "^5.0.8",
"axios": "^0.21.1",
"better-sqlite3": "^11.10.0",
"chai": "^4.3.4",
Expand All @@ -30,6 +31,7 @@
"mocha": "^8.4.0",
"moment": "^2.27.0",
"mustache-express": "^1.3.0",
"nodemailer": "^6.8.0",
"nunjucks": "^3.2.2",
"pg": "^8.6.0",
"supertest": "^6.1.3"
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ services:
- 127.0.0.1:3001:3001
links:
- db
secrets:
- email_user
- email_pass
restart: always
website:
build:
Expand All @@ -26,3 +29,9 @@ services:
links:
- api
restart: always
secrets:
email_user:
file: email_user
email_pass:
file: email_pass

2 changes: 1 addition & 1 deletion website/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM node:16
EXPOSE 3001

# This might be handy during debugging
ENV NPM_CONFIG_LOGLEVEL info
ENV NPM_CONFIG_LOGLEVEL=info

ENV NODE_ENV=production
# FIXME Get this from a better place rather than hard-coded
Expand Down