Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbradley committed Jan 22, 2017
1 parent 4454007 commit 097fd5e
Show file tree
Hide file tree
Showing 14 changed files with 537 additions and 183 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Directories
dbdata
node_modules
.nyc_output
coverage
typings
scratch
Expand Down
1 change: 1 addition & 0 deletions dbconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ curl -X PUT ${DB_INSTANCE}/results/_design/grades -u ${DB_ADMIN_USERNAME}:${DB_A
-H "Content-Type: application/json" \
-d @./database/results/views/grades/byTeamDeliverableCommit.json


# Create users
printf "Creating user ${DB_APP_USERNAME} "
curl -X PUT ${DB_INSTANCE}/_users/org.couchdb.user:${DB_APP_USERNAME} -u ${DB_ADMIN_USERNAME}:${DB_ADMIN_PASSWORD} \
Expand Down
8 changes: 5 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
scriptDir=$(dirname $BASH_SOURCE)

# Create Redis container
docker create \
--name autotest-redis \
Expand All @@ -6,12 +8,12 @@ redis

# Create CouchDB container
docker create \
--name autotest-db1 \
--name autotest-db \
--publish 11312:5984 \
--env COUCHDB_USER="${DB_ADMIN_USERNAME}" \
--env COUCHDB_PASSWORD="${DB_ADMIN_PASSWORD}" \
--volume /home/nickbradley/autotest/dbdata:/usr/local/var/lib/couchdb \
--volume /home/nickbradley/autotest/dbconfig:/usr/local/etc/couchdb/local.d \
--volume "${scriptDir}/.data/dbdata":/usr/local/var/lib/couchdb \
--volume "${scriptDir}/.data/dbconfig":/usr/local/etc/couchdb/local.d \
couchdb


Expand Down
8 changes: 5 additions & 3 deletions docker/tester/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN apt-get update
RUN apt-get -y install iptables
RUN apt-get -y install zip
RUN apt-get -y install yarn
RUN apt-get -y install python-pip
RUN pip install requests
#RUN yarn global add nyc


Expand All @@ -23,14 +25,14 @@ RUN chmod +x /pull-repo.sh
RUN chmod +x /run-tests.sh


RUN /pull-repo.sh $testsuiteRepoUrl $testsuiteCommit /testsuite
RUN cd /testsuite && yarn run configure
RUN /pull-repo.sh $testsuiteUrl $testsuiteCommit /testsuite
RUN cd /testsuite && yarn run configure && ./generator.py $deliverable


ENV MOCHAWESOME_REPORTDIR=/cpsc310project/mocha_output
ENV ALLOW_DNS=$allowDNS
ENV WHITELISTED_SERVERS=$externalServers
ENV TESTSUITE_VERSION=$testsuiteCommit
ENV TS=deliverable
ENV TS=$deliverable

CMD timeout 5m /run-tests.sh $PROJECT_URL $PROJECT_COMMIT >/output/stdio.txt 2>&1
4 changes: 2 additions & 2 deletions docker/tester/build-test-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ else
externalServers=""
fi

docker build --tag autotest/${deliverable}:${commit} \
docker build --tag autotest/${deliverable}-${repoName}:${commit} \
--build-arg testsuiteUrl=https://${githubApiKey}@github.com/CS310-2017Jan/${repoName}.git \
--build-arg testsuiteCommit=${commit} \
--build-arg allowDNS=${allowDNS} \
Expand All @@ -59,7 +59,7 @@ docker build --tag autotest/${deliverable}:${commit} \
"${dockerDir}"


docker build --tag autotest/${deliverable}:latest \
docker build --tag autotest/${deliverable}-${repoName}:latest \
--build-arg testsuiteUrl=https://${githubApiKey}@github.com/CS310-2017Jan/${repoName}.git \
--build-arg testsuiteCommit=${commit} \
--build-arg allowDNS=${allowDNS:0} \
Expand Down
4 changes: 2 additions & 2 deletions docker/tester/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ outputDir="/output"

buildCmd="yarn run build"
#coverCmd="nyc -r json-summary yarn run test"
coverCmd="yarn run cover"
testsCmd="yarn run test"
coverCmd="yarn run autocover"
testsCmd="yarn run autotest"

date=$(date --utc +%FT%T.%3NZ)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "tsc",
"test": "mocha --recursive",
"deploy": "env $(cat autotest.env | xargs) ./deploy.sh",
"start": "docker start autotest-redis && docker start autotest-db1 && node src/App.js"
"start": "docker start autotest-redis && docker start autotest-db && node src/App.js"
},
"devDependencies": {
"@types/mocha": "^2.2.36",
Expand All @@ -34,6 +34,6 @@
"bull": "^2.0.0",
"redis": "^2.6.0",
"nano": "^6.2.0",
"tmp": "^0.0.31"
"tmp-promise": "^1.0.3"
}
}
4 changes: 4 additions & 0 deletions src/controller/TestJobController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export default class TestJobController {
return this.testQueue.add(job, opts);
}

public async get(jobId: string) {
return this.testQueue.get(jobId);
}

public async count(): Promise<number> {
return this.testQueue.count();
}
Expand Down
57 changes: 51 additions & 6 deletions src/controller/github/CommitCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import CommitCommentRecord from '../../model/requests/CommitComment';
import {GithubResponse, Commit} from '../../model/GithubUtil';
import PostbackController from './PostbackController'
import {DeliverableRecord} from '../../model/settings/DeliverableRecord';
import TestJobController from '../TestJobController';


interface GradeSummary {
deliverable: string;
Expand Down Expand Up @@ -54,11 +56,22 @@ export default class CommitCommentContoller {
body: body
}
} catch(err) {
Log.error('CommitCommentContoller::process() - No results for request.');
Log.info('CommitCommentContoller::process() - No results for request.');
record.isProcessed = false;
response = {
statusCode: 404,
body: 'No results found. Commit may still be queued for processing. Please try again later.'
try {
Log.info('CommitCommentController::process() - Checking if commit is queued.')
let maxPos: number = await that.isQueued(record.deliverable, record.team, record.commit);
let body: string = 'Your commit is still queued for processing. Please try again in a few minutes.';// There are ' + maxPos + (maxPos > 1 ? ' jobs' : ' job') + ' queued.';
response = {
statusCode: 200,
body: body
}
} catch(err) {
Log.error('CommitCommentContoller::process() - ERROR Unable to locate test results.')
response = {
statusCode: 404,
body: 'We can\'t seem to find any results for this commit. Please make a new commit and try again.'
}
}
}
} else {
Expand Down Expand Up @@ -100,8 +113,16 @@ export default class CommitCommentContoller {
});
}

/**
* Extract the mention options which can be 'force' or the deliverable name.
*
* @param requestMsg: string
*/
// private async extractMentionOptions(requestMsg: string): string {
//
// }


// TODO @nickbradley Check the output of db.readRecord
/**
* Checks to see if the user is in the admin list in the database.
*
Expand Down Expand Up @@ -130,8 +151,32 @@ export default class CommitCommentContoller {
return controller.submit(msg);
}

/**
* Checks if the request is in the job queue.
*
*/
private async isQueued(deliverable: string, team: string, commit: Commit): Promise<number> {
// jobId: job.test.image + '|' + job.team + '#' + job.commit,
return new Promise<number>((fulfill, reject) => {
let jobId: string = 'autotest/' + deliverable + '-testsuite:latest|' + team + '#' + commit.short;
let queue: TestJobController = TestJobController.getInstance();
queue.get(jobId).then(job => {
if (job) {
queue.count().then(count => {
fulfill(count);
}).catch(err => {
reject(err);
})
} else {
reject('Job has completed.');
}
}).catch(err => {
reject(err);
});
});
}


// TODO @nickbradley create view (and design document)
/**
* Query the database to determine the date of the most recent request for the
* deliverable made by the user.
Expand Down
2 changes: 1 addition & 1 deletion src/controller/github/PushController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class PushController {
hook: record.commentHook,
test: {
name: repo.name,
image: 'autotest/' + repo.name + ':' + (repo.commit ? repo.commit : 'latest'),
image: 'autotest/' + key + '-' + repo.name + ':' + (repo.commit ? repo.commit : 'latest'),
visibility: repo.visibility,
deliverable: key
}
Expand Down
66 changes: 53 additions & 13 deletions src/model/requests/CommitComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class CommitCommentRecord implements DatabaseRecord {
private _deliverableRate: number;
private _isRequest: boolean;
private _isProcessed: boolean;
private _options: string[] = [];
private _note: string;

constructor() {
try {
Expand All @@ -56,10 +58,13 @@ export default class CommitCommentRecord implements DatabaseRecord {
that._isRequest = payload.comment.body.toLowerCase().includes(this.config.getMentionTag());
that._isProcessed = true;
if (that._isRequest) {
let reqDeliverable: string = that.extractDeliverable(that.message);
that._options = this.extractOptions(this.message);
let reqDeliverable: string = this._options[0];//that.extractDeliverable(that.message);
let deliverable: FetchedDeliverable = await that.fetchDeliverable(reqDeliverable);
that._deliverable = deliverable.key;
that._deliverableRate = deliverable.deliverable.rate;
console.log(deliverable);
console.log('***', this._note);
}
fulfill();
} catch(err) {
Expand All @@ -71,34 +76,55 @@ export default class CommitCommentRecord implements DatabaseRecord {


private async fetchDeliverable(key: string): Promise<FetchedDeliverable> {
console.log(key);
if (!key) this._note = 'No deliverable specified; using latest. To specify an earlier deliverable, follow the metion with "#dX", where X is the deliverable.';
let that = this;
return new Promise<FetchedDeliverable>(async (fulfill, reject) => {
try {
let resultsDB = new Database(that.config.getDBConnection(), 'settings');
let deliverablesDoc = await resultsDB.readRecord('deliverables');
let deliverableRecord: DeliverableRecord = new DeliverableRecord(deliverablesDoc);
let fetchedDeliverables: FetchedDeliverable[] = [];
let now: Date = new Date();

if (deliverableRecord.containsKey(key)) {
fulfill({
key: key,
deliverable: deliverableRecord.item(key)
});
let deliverable: Deliverable = deliverableRecord.item(key);

// The key refers to a vaild deliverable that has been released
if (new Date(deliverable.releaseDate) <= now) {
return fulfill({
key: key,
deliverable: deliverableRecord.item(key)
});
// The key refers to a vaild deliverable that hasn't been released
// Get all deliverables that have been released
} else {
this._note = 'The specified deliverable has not been released yet; using latest released.';
for (const key of deliverableRecord.keys()) {
let deliverable: Deliverable = deliverableRecord.item(key);
if (new Date(deliverable.releaseDate) <= now) {
fetchedDeliverables.push({key: key, deliverable: deliverable});
}
}
}
// The key refers to an invaild deliverable
// Get all deliverables that have been released
} else {
let fetchedDeliverables: FetchedDeliverable[] = [];
if (!this._note)
this._note = 'Invalid deliverable specified; using latest. To specify an earlier deliverable, follow the metion with "#dX", where X is the deliverable.';
for (const key of deliverableRecord.keys()) {
let deliverable: Deliverable = deliverableRecord.item(key);
if (new Date(deliverable.releaseDate) <= now) {
fetchedDeliverables.push({key: key, deliverable: deliverable});
}
}

let latestDeliverable: FetchedDeliverable = fetchedDeliverables.reduce((prev, current) => {
return (prev.deliverable.dueDate > current.deliverable.dueDate) ? prev : current
}, fetchedDeliverables[0]);

fulfill(latestDeliverable);
}
// Of the released deliverables, return the one with the latest due date
let latestDeliverable: FetchedDeliverable = fetchedDeliverables.reduce((prev, current) => {
return (prev.deliverable.dueDate > current.deliverable.dueDate) ? prev : current
}, fetchedDeliverables[0]);

fulfill(latestDeliverable);
} catch(err) {
reject(err);
}
Expand Down Expand Up @@ -166,11 +192,25 @@ export default class CommitCommentRecord implements DatabaseRecord {

private extractDeliverable(comment: string): string {
let deliverable: string;
let matches: string[] = /.*#[dD](\d{1,2}).*/i.exec(this.message);
let matches: string[] = /.*#[dD](\d{1,2}).*/i.exec(comment);
if (matches) {
deliverable = 'd' + +matches[1];
}

return deliverable;
}

private extractOptions(comment: string): string[] {
let options: string[] = [];
let mentionTag: string = this.config.getMentionTag();
let re: RegExp = new RegExp(mentionTag + '\\s*#([a-zA-Z0-9]+)','gi');
let matches: string[] = re.exec(comment);
if (matches) {
matches.shift()
options = matches.map(option => {
return option.toLowerCase();
});
}
return options;
}
}
Loading

0 comments on commit 097fd5e

Please sign in to comment.