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

Create applications #8

Merged
merged 39 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5518c80
Add cache from hs_hub
seanjparker Aug 25, 2019
e61376e
Fix makefile for hs_application
seanjparker Aug 25, 2019
58e15a3
Add application sections and form flow
seanjparker Aug 26, 2019
07da259
Add dropdown support in application
seanjparker Aug 27, 2019
e51a1ff
Fix country spelling in questions
seanjparker Aug 27, 2019
4cc081a
Add support for radio inputs
seanjparker Aug 27, 2019
dcb7a38
Move material-dashboard.js to external js
seanjparker Aug 28, 2019
80db993
Add required attribute in form
seanjparker Aug 28, 2019
885cc88
Add name to each input for form submission
seanjparker Aug 29, 2019
9287973
Add inversify and typeorm dependency
seanjparker Aug 31, 2019
691cf68
Add dependency injection for routes + controllers
seanjparker Aug 31, 2019
dbcf8bd
Rename route and repository files for applications
seanjparker Sep 3, 2019
a095a29
Add class-validation, typeorm
seanjparker Sep 3, 2019
3977f47
Add di for routes, controllers + services
seanjparker Sep 3, 2019
37d9764
Add ava for tests instead of jest
seanjparker Sep 5, 2019
1207739
Make repositories easier to mock
seanjparker Sep 5, 2019
e2455b6
Add application service test
seanjparker Sep 5, 2019
89124f7
Remove postgres dependency from travis CI
seanjparker Sep 5, 2019
58147de
Move nyc config into package.json
seanjparker Sep 6, 2019
676fa18
Add adapted cache tests from hs_hub
seanjparker Sep 6, 2019
dec4fd9
Add codecov to travis CI script
seanjparker Sep 6, 2019
4dde9da
Cleanup services and controller
seanjparker Sep 6, 2019
ea21070
Add supertest for e2e tests
seanjparker Sep 8, 2019
9983bdd
Move controller tests to integration test folder
seanjparker Sep 8, 2019
6d6f709
Add e2e tests, fix imports in integration tests
seanjparker Sep 8, 2019
a7469fd
Update applicant model with optional annotations
seanjparker Sep 11, 2019
5c604c0
Add file upload support on front-end
seanjparker Sep 11, 2019
5545608
Add support for file uploads and dropbox storage
seanjparker Sep 11, 2019
7deb308
Add controller and service tests for file upload
seanjparker Sep 11, 2019
f7be913
Move comment in .env.example
seanjparker Sep 11, 2019
4aed7c9
Rename applicationService/Repo to applicantService
seanjparker Sep 15, 2019
c309ed2
Update inverify with new applicant naming
seanjparker Sep 15, 2019
81610d7
Add gulp to build process
seanjparker Sep 15, 2019
184574b
Update tests to use new applicant service name
seanjparker Sep 15, 2019
9683a97
Update error handler to print simple message
seanjparker Sep 16, 2019
3231f66
Fix display bug for long input boxes
seanjparker Sep 16, 2019
7af45e8
Add comment to clarify form validation todo
seanjparker Sep 16, 2019
d385409
Update to new ports
seanjparker Sep 17, 2019
b191c32
Fix make up command for production
seanjparker Sep 17, 2019
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.vscode
.git*
.env
.dockerignore
*Dockerfile*
*docker-compose*
Expand Down
26 changes: 16 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Server set up information
PORT=5000
ENVIRONMENT="production"
PORT=8010
ENVIRONMENT=production

# Database connection information
DB_TYPE="mysql"
DB_HOST="mysql_db" # When using docker, use the docker service name for the value of DB_HOST
DB_PORT=3306
DB_USER="root"
DB_PASSWORD="root"
DB_DATABASE="hub"
DB_TYPE=mysql

# When using in production, use the docker DB service name which is "mysql_db"
# Otherwise, in dev, use "localhost"
DB_HOST=mysql_db
DB_PORT=8011
DB_USER=root
DB_PASSWORD=root
DB_DATABASE=hs_application

#Session Secret
SESSION_SECRET="cat"
SESSION_SECRET=cat

# Google Analytics GTAG ID
GOOGLE_ANALYTICS_ID=""
GOOGLE_ANALYTICS_ID=example

# Dropbox API token
DROPBOX_API_TOKEN=example
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dist
node_modules

#Tests coverage reports
.nyc_output
coverage

#OSX directory files
Expand Down
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ node_js:

services:
- mysql
- postgresql

before_install:
- npm i -g npm@6.5.0
- mysql -e 'CREATE DATABASE IF NOT EXISTS hub;'

before_script:
- psql -c 'CREATE DATABASE applications;' -U postgres
- mysql -e 'CREATE DATABASE IF NOT EXISTS applications;'

# Use npm ci to ensure a clean install of dependencies
install:
Expand All @@ -25,5 +21,8 @@ cache: npm
script:
- npm run test:coverage

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false
43 changes: 26 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
prod_docker_compose_file=./docker-compose.yml
dev_docker_compose_file=./docker/dev/docker-compose.yml

prod_docker_file=./docker/prod/Dockerfile

default: build test

# builds the project into the dist folder
Expand All @@ -10,49 +15,53 @@ test:

# builds the docker image
build-docker:
@echo "=============building hs_hub============="
docker build -f docker/prod/Dockerfile -t hs_hub .

# builds the docker image for dev environment
build-docker-dev:
@echo "=============building hs_hub (dev)============="
docker build -f docker/dev/Dockerfile -t hs_hub .
@echo "=============building hs_application============="
docker build -f $(prod_docker_file) -t hs_application .

# sets up the hacker suite docker network
setup-network:
@echo "=============setting up the hacker suite network============="
docker network create --driver bridge hacker_suite || echo "This is most likely fine, it just means that the network has already been created"

# starts the app and MySQL in docker containers
up: export ENVIRONMENT=production
up: build-docker setup-network
@echo "=============starting hs_hub============="
docker-compose up -d
@echo "=============starting hs_application============="
docker-compose -f $(prod_docker_compose_file) up -d

# starts the app and MySQL in docker containers for dev environment
up-dev: build-docker-dev setup-network
@echo "=============starting hs_hub (dev)============="
docker-compose up -d
# starts the app in local environment and DB in container
up-dev: export ENVIRONMENT=dev
up-dev: export DB_HOST=localhost
up-dev: setup-network
@echo "=============starting hs_application (dev)============="
docker-compose -f $(dev_docker_compose_file) up -d
npm i && npm run start:watch

# prints the logs from all containers
logs:
docker-compose logs -f
ifeq ($(ENV), dev)
docker-compose -f $(dev_docker_compose_file) logs -f
else
docker-compose -f $(prod_docker_compose_file) logs -f
endif

# prints the logs only from the go app
logs-app:
docker-compose logs -f hs_hub
docker-compose logs -f hs_application

# prints the logs only from the database
logs-db:
docker-compose logs -f mysql_db

# shuts down the containers
down:
docker-compose down
docker-compose -f $(prod_docker_compose_file) down
docker-compose -f $(dev_docker_compose_file) down

# cleans up unused images, networks and containers
clean: down
@echo "=============cleaning up============="
rm -f hs_hub
rm -f hs_application
docker container prune -f
docker network prune -f
docker system prune -f
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

This file still contains instructions for hs_hub but fixing this isn't urgent tbh

[![Build Status](https://travis-ci.org/unicsmcr/hs_application.svg?branch=master)](https://travis-ci.org/unicsmcr/hs_hub)
![GitHub](https://img.shields.io/github/license/unicsmcr/hs_application.svg)
[![codecov](https://codecov.io/gh/unicsmcr/hs_application/branch/master/graph/badge.svg)](https://codecov.io/gh/unicsmcr/hs_application)

## Dependencies

Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: '2.1'
version: "2.1"
services:
hs_application:
image: hs_application:latest
depends_on:
mysql_db:
condition: service_healthy
env_file:
- ./.env
volumes:
- .:/home/node/app/
- /home/node/app/node_modules
Expand All @@ -18,11 +20,8 @@ services:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password --log_error_verbosity=1
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: hub
ports:
- "${DB_PORT}:${DB_PORT}"
# The healthcheck is used to ensure the database is running before the hub starts
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
# The healthcheck is used to ensure the database is running before hs_application starts
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost --silent"]
timeout: 5s
Expand All @@ -31,14 +30,15 @@ services:
- internal
volumes:
- db_store:/var/lib/mysql
- ./docker/database/:/docker-entrypoint-initdb.d/:ro

# The volume for the database is persistent across launches
volumes:
db_store:

# The network allows multiple containers to connect together
networks:
# internal network for hs_hub services
# internal network for hacker suite services
internal:
driver: bridge
# external network for consumer-facing hacker suite services
Expand Down
1 change: 1 addition & 0 deletions docker/database/initial_db_setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS hs_application;
27 changes: 0 additions & 27 deletions docker/dev/Dockerfile

This file was deleted.

35 changes: 35 additions & 0 deletions docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "2.1"
services:
mysql_db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password --log_error_verbosity=1
env_file:
- ../../.env
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
ports:
- "${DB_PORT}:3306"
# The healthcheck is used to ensure the database is running
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost --silent"]
timeout: 5s
retries: 10
networks:
- internal
volumes:
- db_store:/var/lib/mysql
- ../database/:/docker-entrypoint-initdb.d/:ro

# The volume for the database is persistent across launches
volumes:
db_store:

# The network allows multiple containers to connect together
networks:
# internal network for hs_hub services
internal:
driver: bridge
# external network for consumer-facing hacker suite services
hacker_suite:
external:
name: hacker_suite
2 changes: 1 addition & 1 deletion docker/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
# Before running install, switch to non-root user "node"
USER node


# Define working directory and copy source
WORKDIR /home/node/app
COPY . .
Expand All @@ -32,6 +31,7 @@ ENV NODE_ENV=production

# Install production dependencies only
COPY package*.json ./
COPY .env ./
RUN npm install && \
npm cache clean --force

Expand Down
100 changes: 100 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
var gulp = require('gulp');
var terser = require('gulp-terser');
var rename = require('gulp-rename');
var cleanCSS = require('gulp-clean-css');
var replace = require('gulp-replace');
var parallel = gulp.parallel;

const paths = {
css: {
src: ['src/public/css/**/*.css', '!src/public/css/**/*.min.css'],
dest: 'dist/public/css/'
},
scripts: {
src: ['src/public/js/**/*.js', '!src/public/js/**/*.min.js'],
dest: 'dist/public/js/'
},
scripts_min: {
src: 'src/public/js/**/*.min.js',
dest: 'dist/public/js/'
},
views: {
src: 'src/views/**/*.ejs',
dest: 'dist/views/'
},
images: {
src: ['src/public/img/**/*.jpg', 'src/public/img/**/*.png'],
dest: 'dist/public/img/'
},
publicRoot: {
src: 'src/public/*',
dest: 'dist/public/'
},
hackathonSettings: {
src: 'src/settings/*.json',
dest: 'dist/settings/'
}
};

function css() {
return gulp.src(paths.css.src)
.pipe(cleanCSS())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.css.dest));
}

function scripts() {
return gulp.src(paths.scripts.src, {
sourcemaps: true
})
.pipe(terser())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.scripts.dest))
}

function scriptsCopyMin() {
return gulp.src(paths.scripts_min.src)
.pipe(gulp.dest(paths.scripts_min.dest));
}

function views() {
return gulp.src(paths.views.src)
/* The regex looks complicated but here are the steps:
* 1. Positive lookbehind -- check that the HTML contains src="|', href="|'
* (this remove changing references to remote resources)
* 2. Check for any charater any number of times, this is the uri
* 3. Positive lookahead for the file extension being .js or .css with no other characters after
* Replaces the match with .min.js or .min.css
*/
.pipe(replace(/(?<=(src|href)=['"])[\/a-zA-z-_]+(?=\.(js|css)[^a-z])/gm, '$&.min'))
.pipe(gulp.dest(paths.views.dest));
}

function images() {
return gulp.src(paths.images.src)
.pipe(gulp.dest(paths.images.dest));
}

function copyRemainingPublic() {
return gulp.src(paths.publicRoot.src)
.pipe(gulp.dest(paths.publicRoot.dest));
}

function copyHackathonSettings() {
return gulp.src(paths.hackathonSettings.src)
.pipe(gulp.dest(paths.hackathonSettings.dest));
}

exports.default = parallel(
images,
views,
scripts,
scriptsCopyMin,
css,
copyRemainingPublic,
copyHackathonSettings
);
Loading