Skip to content

Commit aa1f66f

Browse files
authored
Merge pull request #39 from WorldBank-Transport/develop
Release new versions
2 parents 49ed574 + 24dd1a5 commit aa1f66f

File tree

29 files changed

+4727
-1081
lines changed

29 files changed

+4727
-1081
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ jobs:
9595
docker tag ${DOCKER_IMAGE} ${DOCKER_ORG}/${DOCKER_IMAGE}:${VERSION}
9696
docker push ${DOCKER_ORG}/${DOCKER_IMAGE}:${VERSION}
9797
98+
echo Pushing image to Docker Hub with latest tag
99+
docker tag ${DOCKER_IMAGE} ${DOCKER_ORG}/${DOCKER_IMAGE}:latest
100+
docker push ${DOCKER_ORG}/${DOCKER_IMAGE}:latest
101+
98102
deploy-analysis-prod:
99103
docker:
100104
- image: circleci/node:6
@@ -152,6 +156,10 @@ jobs:
152156
docker tag ${DOCKER_IMAGE} ${DOCKER_ORG}/${DOCKER_IMAGE}:${VERSION}
153157
docker push ${DOCKER_ORG}/${DOCKER_IMAGE}:${VERSION}
154158
159+
echo Pushing image to Docker Hub with latest tag
160+
docker tag ${DOCKER_IMAGE} ${DOCKER_ORG}/${DOCKER_IMAGE}:latest
161+
docker push ${DOCKER_ORG}/${DOCKER_IMAGE}:latest
162+
155163
workflows:
156164
version: 2
157165
build-deploy:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ docker build -t ram-analysis .
1717
## Releasing a new version
1818
The process to release a new version:
1919

20-
- still on `develop`, bump the version in `./ram-tools/package.json` and/or `./ram-analysis/package.json`
20+
- still on `develop`, bump the version in `./ram-vt/package.json` and/or `./ram-analysis/package.json`
2121
- set up PR, have somebody do a review and merge `develop` into `master`
2222
- CircleCI will add a new tag to git using the version in `package.json`
2323
Because this repo holds two containers that are independently versioned, the git tags are prepended with the container name (eg. `ram-vt-v0.1.0`)

ram-analysis/.babelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
]
11+
],
12+
"plugins": [],
13+
"sourceMaps": "inline",
14+
"retainLines": true
15+
}

ram-analysis/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"mocha": true
66
},
77
"parserOptions": {
8-
"ecmaVersion": 6
8+
"ecmaVersion": 2017
99
},
1010
"rules": {
1111
"semi": [2, "always"],

ram-analysis/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v6.15

ram-analysis/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COPY . /code
44

55
WORKDIR /code
66

7-
RUN npm install
7+
RUN yarn
88

99
RUN mkdir /conversion && cd /conversion && echo "disk=/var/tmp/stxxl,2500,memory" > .stxxl && ln -s /code/node_modules/osrm/profiles/lib/ .
1010

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Calculate ETA
22

3-
TODO: Add explanation about what the file does
3+
Calculates the time matrix between all origins and destinations in a given area.
4+
Executed as a forked node process that responds to messages.
45

56
This file is not called directly because node does not support all the used es6 features.
67
The file `calculateETA.js` in the parent directory contains the babel register and should be executed instead.

ram-analysis/app/calculateETA.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// only ES5 is allowed in this file
2-
require('babel-register')({
3-
presets: [ 'es2015' ]
4-
});
2+
require('@babel/register')();
53

64
// load the server
75
require('./calculate-eta/');

ram-analysis/app/s3/index.js

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use strict';
22
import * as Minio from 'minio';
3+
import Http from 'http';
4+
import Https from 'https';
5+
6+
import { getAWSInstanceCredentials } from '../utils/aws';
37

4-
var minioClient;
58
const {
69
STORAGE_HOST,
710
STORAGE_PORT,
@@ -12,30 +15,64 @@ const {
1215
STORAGE_REGION
1316
} = process.env;
1417

15-
switch (STORAGE_ENGINE) {
16-
case 'minio':
17-
minioClient = new Minio.Client({
18-
endPoint: STORAGE_HOST,
19-
port: parseInt(STORAGE_PORT),
20-
secure: false,
21-
accessKey: STORAGE_ACCESS_KEY,
22-
secretKey: STORAGE_SECRET_KEY
23-
});
24-
break;
25-
case 's3':
26-
minioClient = new Minio.Client({
27-
// Endpoint gets updated based on region.
28-
endPoint: 's3.amazonaws.com',
29-
region: STORAGE_REGION,
30-
accessKey: STORAGE_ACCESS_KEY,
31-
secretKey: STORAGE_SECRET_KEY
32-
});
33-
break;
34-
default:
35-
throw new Error('Invalid storage engine. Use s3 or minio');
36-
}
37-
38-
export default minioClient;
39-
4018
export const bucket = STORAGE_BUCKET;
4119
export const region = STORAGE_REGION;
20+
21+
/**
22+
* Initializes the minio s3 client depending on the engine and credentials
23+
* source in use. Needs to be a promise because it may rely on asynchronously
24+
* fetched credentials.
25+
*
26+
* @returns Minio Client
27+
*/
28+
export default async function S3 () {
29+
let minioClient;
30+
let agent;
31+
32+
switch (STORAGE_ENGINE) {
33+
case 'minio':
34+
minioClient = new Minio.Client({
35+
endPoint: STORAGE_HOST,
36+
port: parseInt(STORAGE_PORT),
37+
secure: false,
38+
accessKey: STORAGE_ACCESS_KEY,
39+
secretKey: STORAGE_SECRET_KEY
40+
});
41+
agent = Http.globalAgent;
42+
break;
43+
case 's3':
44+
let credentials;
45+
if (!STORAGE_ACCESS_KEY && !STORAGE_SECRET_KEY) {
46+
// If we're using a S3 storage engine but no accessKey and secretKey
47+
// are set up, we assume that it is being run from a EC2 instance and
48+
// will try to get the credentials through the url. We're not throwing
49+
// any error if it fails because that is checked on startup.
50+
// See app/index.js
51+
const AWSInstanceCredentials = await getAWSInstanceCredentials();
52+
credentials = {
53+
accessKey: AWSInstanceCredentials.accessKey,
54+
secretKey: AWSInstanceCredentials.secretKey,
55+
sessionToken: AWSInstanceCredentials.sessionToken
56+
};
57+
} else {
58+
credentials = {
59+
accessKey: STORAGE_ACCESS_KEY,
60+
secretKey: STORAGE_SECRET_KEY
61+
};
62+
}
63+
64+
minioClient = new Minio.Client({
65+
endPoint: 's3.amazonaws.com',
66+
...credentials
67+
});
68+
agent = Https.globalAgent;
69+
break;
70+
default:
71+
throw new Error('Invalid storage engine. Use s3 or minio');
72+
}
73+
74+
// Temp fix for https://github.com/minio/minio-js/issues/641
75+
minioClient.agent = agent;
76+
77+
return minioClient;
78+
}

ram-analysis/app/s3/utils.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
2-
import s3, { bucket } from './';
2+
import S3, { bucket } from './';
33

44
// Proxy of removeObject function, assuming the bucket.
5-
export function removeFile (file) {
5+
export async function removeFile (file) {
6+
const s3 = await S3();
67
return new Promise((resolve, reject) => {
78
s3.removeObject(bucket, file, err => {
89
if (err) {
@@ -14,7 +15,8 @@ export function removeFile (file) {
1415
}
1516

1617
// Get file.
17-
export function getFile (file) {
18+
export async function getFile (file) {
19+
const s3 = await S3();
1820
return new Promise((resolve, reject) => {
1921
s3.getObject(bucket, file, (err, dataStream) => {
2022
if (err) {
@@ -26,7 +28,8 @@ export function getFile (file) {
2628
}
2729

2830
// Get file content.
29-
export function getFileContents (file) {
31+
export async function getFileContents (file) {
32+
const s3 = await S3();
3033
return new Promise((resolve, reject) => {
3134
s3.getObject(bucket, file, (err, dataStream) => {
3235
if (err) return reject(err);
@@ -40,19 +43,14 @@ export function getFileContents (file) {
4043
}
4144

4245
// Get file content in JSON.
43-
export function getJSONFileContents (file) {
44-
return getFileContents(file)
45-
.then(result => {
46-
try {
47-
return JSON.parse(result);
48-
} catch (e) {
49-
Promise.reject(e);
50-
}
51-
});
46+
export async function getJSONFileContents (file) {
47+
const result = await getFileContents(file);
48+
return JSON.parse(result);
5249
}
5350

5451
// Get file and write to disk.
55-
export function writeFile (file, destination) {
52+
export async function writeFile (file, destination) {
53+
const s3 = await S3();
5654
return new Promise((resolve, reject) => {
5755
s3.fGetObject(bucket, file, destination, err => {
5856
if (err) {
@@ -64,7 +62,8 @@ export function writeFile (file, destination) {
6462
}
6563

6664
// Put file.
67-
export function putFile (file, data) {
65+
export async function putFile (file, data) {
66+
const s3 = await S3();
6867
return new Promise((resolve, reject) => {
6968
s3.putObject(bucket, file, data, (err, etag) => {
7069
if (err) {

0 commit comments

Comments
 (0)