Skip to content

Commit

Permalink
Merge pull request #49 from CSSE6400/release_ready
Browse files Browse the repository at this point in the history
Release ready
  • Loading branch information
henrybatt authored Jun 2, 2024
2 parents c8b94b8 + bfd54b5 commit 68db664
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 74 deletions.
6 changes: 6 additions & 0 deletions application/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ RUN chmod +x entrypoint.sh
# Copying our application into the container
COPY app /app

ARG ROUTING_URL
ARG GEOCODING_URL

# Set environment variables
ENV REACT_APP_ROUTING_URL=$ROUTING_URL
ENV REACT_APP_GEOCODING_URL=$GEOCODING_URL
# Build the frontend with yarn
RUN /bin/bash -c "source ~/.bashrc && cd frontend && yarn install && yarn build"

Expand Down
3 changes: 2 additions & 1 deletion application/app/frontend/src/api/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const fetchCoordinates = async (address) => {
const url = `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(address)}&format=json`;
const geocodingUrl = process.env.REACT_APP_GEOCODING_URL
const url = `${geocodingUrl}/search?q=${encodeURIComponent(address)}&format=json`;
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
Expand Down
6 changes: 5 additions & 1 deletion application/app/frontend/src/components/Routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ const customIcon = new L.Icon({
iconAnchor: [12, 41],
popupAnchor: [1, -34],
});

const createRoutineMachineLayer = ({ waypoints }) => {
const url = process.env.REACT_APP_ROUTING_URL
const routingUrl = `${url}/route/v1`
const instance = L.Routing.control({
waypoints: waypoints.map(wp => L.latLng(wp.lat, wp.lng)),
router: L.Routing.osrmv1({
serviceUrl: routingUrl
}),
lineOptions: {
styles: [
{
Expand Down
21 changes: 13 additions & 8 deletions application/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
version: '3.8'

services:
database:
image: postgis/postgis
restart: always
Expand All @@ -13,28 +14,32 @@ services:
- "5432:5432"

api:
build: .
build:
context: .
args:
ROUTING_URL: https://router.project-osrm.org
GEOCODING_URL: https://nominatim.openstreetmap.org
container_name: ridingshare
restart: always
environment:
CELERY_BROKER_URL: redis://redis:6379
SQLALCHEMY_DATABASE_URI: postgresql+psycopg://administrator:verySecretPassword@database:5432/ride
ROUTING_URL: http://router.project-osrm.org
GEOCODING_URL: https://nominatim.openstreetmap.org
ports:
- "8080:8080"
depends_on:
- database
command: ["flask", "--app", "wsgi:app", "run", "--debug", "--host", "0.0.0.0", "--port", "8080"]

matching_worker:
build: .
build:
context: .
args:
ROUTING_URL: https://router.project-osrm.org
GEOCODING_URL: https://nominatim.openstreetmap.org
restart: always
environment:
CELERY_BROKER_URL: redis://redis:6379
SQLALCHEMY_DATABASE_URI: postgresql+psycopg://administrator:verySecretPassword@database:5432/ride
ROUTING_URL: http://router.project-osrm.org
GEOCODING_URL: https://nominatim.openstreetmap.org
command: celery --app tasks.celery_app worker --loglevel=info -Q matching.fifo --uid=nobody --gid=nogroup
depends_on:
- redis
Expand All @@ -44,4 +49,4 @@ services:
image: redis:latest
restart: always
ports:
- "6379:6379"
- "6379:6379"
93 changes: 34 additions & 59 deletions k6.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,18 @@ function simulateUserLoginTest() {
sleep(1);
}

function simulateTripCreationTest() {
let url = `${ENDPOINT}/trip/create`;
const now = new Date();
// Randomize the start time to be within the next 1 to 10 days
const startInMinutes = Math.floor(Math.random() * 14400) + 1440; // 1440 minutes in a day, up to 10 days
const startTime = new Date(now.getTime() + startInMinutes * 60000);

// End time is 1 to 4 hours after start time, but could be more for longer durations
const endInMinutes = Math.floor(Math.random() * 180) + 60; // between 1 hour (60 minutes) and 4 hours (240 minutes)
const endTime = new Date(startTime.getTime() + endInMinutes * 60000);
function simulateGetPendingTripTest() {
let url = `${ENDPOINT}/trips/get/pending`;


const payload = JSON.stringify({
"username": "jDoe11",
"password": "53%32",
"start_time": startTime.toISOString(),
"end_time": endTime.toISOString(),
"start_location": {"latitude": 37.7749, "longitude": -122.4194, "address": "123 street road, Brisbane, QLD"},
"end_location": {"latitude": 37.7749, "longitude": -122.4194, "address": "125 street road, Brisbane, QLD"},
"seats_remaining": 3,
"distance_addition": 4
});

const params = { headers: { 'Content-Type': 'application/json' } };
let response = http.post(url, payload, params);
check(response, { 'is status 201': (r) => r.status === 201 });
check(response, { 'is status 200': (r) => r.status === 200 });
sleep(1);
}

Expand All @@ -58,47 +45,17 @@ export const options = {
{ duration: "2m", target: 0 },
],
},

},
// scenarios: {
// RegularTraffic: {
// executor: 'per-vu-iterations',
// vus: 10000,
// iterations: 1,
// exec: 'simulateUserLogin'
// },
// RushHourTraffic: {
// executor: 'per-vu-iterations',
// vus: 10000,
// iterations: 1,
// exec: 'simulateTripCreation'
// },
// VariableDemand: {
// executor: 'ramping-arrival-rate',
// startRate: 5,
// timeUnit: '1m',
// stages: [
// { target: 20, duration: '5m' }, // Peak time
// { target: 5, duration: '3m' }, // Off-peak
// { target: 20, duration: '2m' } // Back to peak
// ],
// preAllocatedVUs: 50,
// maxVUs: 200,
// exec: 'simulateTripCreation'
// },
// EventSurge: {
// executor: 'per-vu-iterations',
// vus: 10000,
// iterations: 1,
// exec: 'simulateUserLogin'
// },
// TargetedPromotion: {
// executor: 'per-vu-iterations',
// vus: 2000,
// iterations: 1,
// exec: 'simulateUserLogin'
// }
};
getPendingTrip: {
exec: 'simulateTripCreation',
executor: "ramping-vus",
stages: [
{ duration: "2m", target: 100 },
{ duration: "2m", target: 25 },
{ duration: "2m", target: 0 },
],
}
},
};

export function setup() {
// Create a driver user
Expand All @@ -116,6 +73,24 @@ export function setup() {
let response = http.post(url, payload, params);
check(response, { 'Sign Up a Driver': (r) => r.status === 201 });

sleep(1);
let url2 = `${ENDPOINT}/trip/create`;

const payload2 = JSON.stringify({
"username": "jDoe11",
"password": "53%32",
"start_time": "2024-05-31T07:38:56Z",
"end_time": "2024-05-31T08:00:00Z",
"start_location": {"latitude": 37.7749, "longitude": -122.4194, "address": "123 street road, Brisbane, QLD"},
"end_location": {"latitude": 37.7749, "longitude": -122.4194, "address": "125 street road, Brisbane, QLD"},
"seats_remaining": 3,
"distance_addition": 4
});

const params2 = { headers: { 'Content-Type': 'application/json' } };
let response2 = http.post(url2, payload2, params2);
check(response2, { 'is status 201': (r) => r.status === 201 });

}

export function simulateUserLogin() {
Expand All @@ -125,6 +100,6 @@ export function simulateUserLogin() {
}
export function simulateTripCreation() {
group('User Actions', function () {
simulateTripCreationTest();
simulateGetPendingTripTest();
});
}
6 changes: 3 additions & 3 deletions terraform/GIS.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ variable "geocoding_engine_url" {
}

locals {
routing_url = "${var.routing_engine_url == "" ? data.external.hosted_routing_ip.result.value : var.routing_engine_url}"
geocoding_url = "${var.geocoding_engine_url == "" ? data.external.hosted_geocoding_ip.result.value : var.geocoding_engine_url}"
}
routing_url = "${var.routing_engine_url == "" ? "http://${data.external.hosted_routing_ip.result.value}" : var.routing_engine_url}"
geocoding_url = "${var.geocoding_engine_url == "" ? "http://${data.external.hosted_geocoding_ip.result.value}" : var.geocoding_engine_url}"
}
8 changes: 6 additions & 2 deletions terraform/repositories.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ resource "docker_image" "riding_share" {
name = "${aws_ecr_repository.riding_share.repository_url}:latest"
build {
context = "./application"
build_args = {
ROUTING_URL = local.routing_url
GEOCODING_URL = local.geocoding_url
}
}
}

resource "docker_registry_image" "riding_share" {
name = docker_image.riding_share.name
}
}

0 comments on commit 68db664

Please sign in to comment.