University coursework. Grade: 98%
- Frontend: No longer available
- Backend: No longer available
- After signing-up for Google Cloud Platform, access the Console via the following url: "https://console.cloud.google.com/"
- In the header, click "Select Project" -> "New Project"
- Give the project an appropriate name
- Open Cloud Shell inside the GCP Console
- Enter the command "gcloud app create"
- If an error occurs suggesting no project is selected, close Cloud Shell, ensure the project you created is selected, reopen Cloud Shell and retry step 5
- When prompted enter the number "12", and press enter
- Open the project files in Eclipse Enterprise
- Install "Google Cloud Tools for Eclipse" via "Help" -> "Eclipse Marketplace" -> Search tab
- Right click the project in Eclipse and click "Deploy to App Engine Standard"
- Under Eclipse's console, the URL for the backend can be found / accessed via the console's output similar to the following:
"Deployed service [default] to [https://servletcoursework-336513.nw.r.appspot.com]"
You can stream logs from the command line by running: $ gcloud app logs tail -s default
To view your application in the web browser run: - "gcloud app browse --project=servletcoursework-336513"
- After accessing the backend URL, open the file from the 'project root/client/src/constants/endpoints.ts'
- Replace the existing URL in the root constant to the value of the copied URL with no forward slashes appended to the end of the URL
- const ROOT = 'https://industrial-pad-336114.nw.r.appspot.com';
- becomes:
- const ROOT = 'https://servletcoursework-336513.nw.r.appspot.com';
- In GCP Console, access SQL
- Click "create instance"
- Click "Choose MySQL"
- Click "Enable API" if not already enabled
- Set up Database:
- Enter an Instance ID e.g. "servletcourseworkdb"
- Generate password, and make a note of it for later
- Database version: "MySQL 5.7"
- Region: "euroupe-west2"
- Zonal availibility: "Single Zone"
- Machine type: "Standard", "1 vCPU, 3.75 GB"
- Storage type: "SSD"
- Storage capacity: "10 GB"
- Connections: "Public IP"
- Authorized networks:
- Name: "Public"
- Network: "0.0.0.0/0"
- Uncheck "Automate backups"
- Create instance
- Go to "Cloud Storage" in GCP Console
- Click "Create Bucket"
- Enter a unique name e.g. "servletcourseworksqlfile"
- Location type: "Region"
- Location: "europe-west2"
- Storage class: "Standard"
- Uncheck Enforce public access prevention
- Access control: uniform
- Create bucket
- Click "Upload Files"
- Select "createfilms.sql" from inside project root
- Go to "SQL" in GCP Console
- Click the Instance ID of the previously created MySQL Instance
- Click "Databases" in the left side-panel
- Click "Create Database"
- Enter the database name "servletcoursework"
- Click "Create"
- Click "Overview" in the left side-panel
- Click "Import"
- Source: Click "browse" and select the previously created bucket and uploaded "createfilms.sql"
- File format: SQL
- Database: "servletcoursework"
- Click "Import"
- Scroll down to the section "Connect to this instance"
- Copy the text under "Connection name", e.g. "servletcoursework-336513:europe-west2:servletcourseworkdb2"
- Open the file found in the project root/src/connectionPool/ConnectionPoolSingleton.java
- Replace the variable "connectionName" with the previously copied connection name
- Replace the variable "databaseName" with the name of the database, it should be "servletcoursework" if step 10 was followed correctly
- Replace the variable "password" with the password generated in step 5
- Repeat step 9 from the Back-end setup section
-
Access the file with the path: "Servlet-Coursework/client/serverless.yml"
-
Under the "custom" section, modify the property under ClientBucket, name
- Replacing "9uo2ftpc" with a random string containing lowercase letters and numbers from "servletcourseworkclient9uo2ftpc-${self:provider.stage}"
- This is due to buckets needing a unique name across the entirety of AWS
-
Sign up for AWS, and install AWS CLI
-
Create an IAM user using the AWS (web) Console
- Enable "Access key - Programmatic access" & "Password - AWS Management Console access"
- Create a group and attach "AdministratorAccess" policy
-
If no access key has been generated, generate an access key by clicking the new user -> Security credentials -> Create access key
-
In your terminal run "aws configure"
- Access Key ID and Secret Access Key can be found inside the generated access key csv file
- Region: "eu-west-2"
- Output format: "json"
-
In the terminal enter "cd client"
-
Next, enter "npm i"
-
Next, enter "npm run serverlessDeploy"
-
Go to the AWS (web) console, and go to CloudFront -> Distributions
-
The URL for the frontend can be found under "Domain name" for the distribution with a description of "Servlet Coursework Client"
-
Go to "Amazon S3" in the console
-
Click on the bucket with the suffix "-prod", e.g. "servletcourseworkclient9uo2ftpc-prod"
-
Copy the name of the bucket including the suffix
-
Open the "package.json" file inside the client folder
-
Modify the "sync" script such that it is as follows: "aws s3 rm s3://[bucket name] --recursive && aws s3 sync ./build s3://[bucket name]" e.g. "aws s3 rm s3://servletcourseworkclient9uo2ftpc-prod --recursive && aws s3 sync ./build s3://servletcourseworkclient9uo2ftpc-prod"
-
Ensure that your terminal is still inside the client folder
-
Enter "npm deploy"
-
Front-end can now be accessed via the URL from step 9
- If Eclipse throws an error that there are errors in the project when attempting to deploy to App Engine, right click the project in project explorer -> Maven -> Update Project -> OK. If this does not work Clean the project in Eclipse and try again.