Web Infra HW 03 MAK - TheEvergreenStateCollege/upper-division-cs-23-24 GitHub Wiki
page index
All students in SOS will do Lap 1 for Web Infra in order to host their projects in a high-availability way.
Our goal in this homework for Lap 1 is
- connect our Postgres database to our Express API server using the Prisma Object Relational Modeling.
- design a data schema for our Postgres database.
- you may design a schema for your final project idea if you have one instead of the general product idea in the FrontendMasters tutorial
- create services for two projects using systemd, that will automatically restart if the service is not running, for high-availability
- the python HTTP server for one your front-end projects, or the front-end project for a classmate who isn't taking Web Infra
- your Express API server that is offering data that we started in class on Thursday, Jan 25th
Install tmux for terminal multiplexing and easier management of services and infrastructure tasks. sudo apt install -y tmux
You can work the four videos on FrontendMasters on working with tmux, or check out this handy cheatsheet. You may also wish to install neovim with a modern plugin setup like chad , since the t2.micro AWS server is too weak to run VSCode with the remote explorer. https://nvchad.com/docs/quickstart/install You can become more familiar with vim (neovim has identical keybindings) with this vim Fundamentals FrontEndMasters course.
Read and/or watch these two sections of the API design with NodeJS and Express course. Section 3: Object Relational Mapping with Prisma Section 4: Routes and Middleware The entire course, just for reference. https://frontendmasters.com/courses/api-design-nodejs-v4/
watch and follow along
https://hendrixer.github.io/API-design-v4/lessons/intro-to-prisma/what-is-prisma
https://hendrixer.github.io/API-design-v4/lessons/intro-to-prisma/what-is-prisma https://hendrixer.github.io/API-design-v4/lessons/intro-to-prisma/db-setup
get a postgres database https://dashboard.render.com/ created database https://dashboard.render.com/d/dpg-cpbm7jun7f5s73ffehi0-a
External Database URL postgres://mak_database_user:KesnesBmdounqkVEyAn1XOYgXvEgG4mh@dpg-cpbm7jun7f5s73ffehi0-a.oregon-postgres.render.com/mak_database
made codespace to work in https://silver-orbit-x77rqgp7gpw39pr4.github.dev/
Installing Prisma npm i typescript ts-node @types/node prisma --save-dev
@MKrause-code ➜ /workspaces/codespaces-blank $ npm i typescript ts-node @types/node prisma --save-dev
added 26 packages in 9s
npm notice
npm notice New minor version of npm available! 10.5.2 -> 10.8.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.0
npm notice Run npm install -g [email protected] to update!
npm notice
@MKrause-code ➜ /workspaces/codespaces-blank $
create a tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"lib": ["esnext"],
"esModuleInterop": true
}
}
https://hendrixer.github.io/API-design-v4/lessons/intro-to-prisma/db-setup
initialize Prisma npx prisma init
@MKrause-code ➜ /workspaces/codespaces-blank $ npx prisma init
✔ Your Prisma schema was created at prisma/schema.prisma
You can now open it in your favorite editor.
Next steps:
1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started
2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql, sqlite, sqlserver, mongodb or cockroachdb.
3. Run prisma db pull to turn your database schema into a Prisma schema.
4. Run prisma generate to generate the Prisma Client. You can then start querying your database.
More information in our documentation:
https://pris.ly/d/getting-started
┌────────────────────────────────────────────────────────────────┐
│ Developing real-time features? │
│ Prisma Pulse lets you respond instantly to database changes. │
│ https://pris.ly/cli/pulse │
└────────────────────────────────────────────────────────────────┘
@MKrause-code ➜ /workspaces/codespaces-blank $
installed prisma extension to codespace
edit .env change DATABASE_URL to my External Database URL
DATABASE_URL="postgres://mak_database_user:KesnesBmdounqkVEyAn1XOYgXvEgG4mh@dpg-cpbm7jun7f5s73ffehi0-a.oregon-postgres.render.com/mak_database "
add server.ts
import express from 'express'
const app = express()
app.get('/', (req, res) => {
console.log('express says hello')
res.status(200)
res.json({message: 'hello'})
})
export default app
and add index.ts
import app from './server'
app.listen(3001, () => {
console.log('hello on http://localhost:3001')
})
package.json add to line 8
"dev": "ts-node scr/index.ts"
mine does not look like this
https://hendrixer.github.io/API-design-v4/lessons/data-modeling/design-a-schema go to https://www.framer.com/templates/chronos/ changelog going to make a schema for this app
https://hendrixer.github.io/API-design-v4/lessons/data-modeling/creating-models
in schema.prisma add user schema
model User{
id String @id @default(uuid())
createdAt DataTime @default(now())
username String @unique
password String
}
https://hendrixer.github.io/API-design-v4/lessons/data-modeling/creating-models
make product model in schema.prisma
model Product{
id String @id @default(uuid())
createdAt DataTime @default(now())
name String @db.VarChar(255)
belongsToId String
belongsTo User @relation(fields: [belongsToId], references: [id])
}
format npx
@MKrause-code ➜ /workspaces/codespaces-blank $ npx prisma format
Error: Unexpected non-whitespace character after JSON at position 10
I will fix that later
add products manually to user
products Product[]
https://hendrixer.github.io/API-design-v4/lessons/data-modeling/creating-models https://www.framer.com/templates/chronos/
add updates to schema.prisma
model Update{
id String @id @default(uuid())
createdAt DataTime @default(now())
UpdatedAt DataTime
title Stringbody String
}
and update status
enum UPDATE_STATUS {
IN_PROGRESS
SHIPPED
DEPRECATED
}
add connect UPDATE_STATUS to update and version and asset optional product stuff
model Update{
id String @id @default(uuid())
createdAt DataTime @default(now())
UpdatedAt DataTime
title String
body String
status UPDATE_STATUS @default(IN_PROGRESS)
version String?
asset String?
productId String
product Product @relation(fields: [productId], references: [id])
}
add updates to product
updates Update[]
new model, update point
model UpdatePoint {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime
name String @db.VarChar(255)
description String
updateId String
update Update @relation(fields: [updateId], references: [id])
}
https://hendrixer.github.io/API-design-v4/lessons/data-modeling/first-migrations
Migrations: teaches database what data looks like also for moving data around
install npm i @prisma/client --save
@MKrause-code ➜ /workspaces/codespaces-blank $ npm i @prisma/client --save
npm ERR! code EJSONPARSE
npm ERR! path /workspaces/codespaces-blank/package.json
npm ERR! JSON.parse Unexpected non-whitespace character after JSON at position 10 while parsing near "\n\"scripts\":{\n \"dev\": \"ts-node..."
npm ERR! JSON.parse Failed to parse JSON data.
npm ERR! JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in: /home/codespace/.npm/_logs/2024-05-29T18_20_24_217Z-debug-0.log
https://frontendmasters.com/courses/api-design-nodejs-v4/prisma-overview/ ok I'm going to fix json now rename package.json to package1.json so can generate a new package.json
generate new package.json
@MKrause-code ➜ /workspaces/codespaces-blank $ npm init --yes
Wrote to /workspaces/codespaces-blank/package.json:
{
"name": "codespaces-blank",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"acorn": "^8.11.3",
"acorn-walk": "^8.3.2",
"arg": "^4.1.3",
"create-require": "^1.1.1",
"diff": "^4.0.2",
"make-error": "^1.3.6",
"prisma": "^5.14.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"undici-types": "^5.26.5",
"v8-compile-cache-lib": "^3.0.1",
"yn": "^3.1.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
fixed package.json
{
"name": "codespaces-blank",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "ts-node scr/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express":"^4.18.1"
},
"devDependencies": {
"@types/node": "^20.12.13",
"prisma": "^5.14.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
try formatting prisma
@MKrause-code ➜ /workspaces/codespaces-blank $ npx prisma format
Prisma schema loaded from prisma/schema.prisma
Error: Prisma schema validation - (validate wasm)
Error code: P1012
error: Type "DataTime" is neither a built-in type, nor refers to another model, composite type, or enum.
--> prisma/schema.prisma:18
|
17 | id String @id @default(uuid())
18 | createdAt DataTime @default(now())
|
error: Type "DataTime" is neither a built-in type, nor refers to another model, composite type, or enum.
--> prisma/schema.prisma:26
|
25 | id String @id @default(uuid())
26 | createdAt DataTime @default(now())
|
error: Type "DataTime" is neither a built-in type, nor refers to another model, composite type, or enum.
--> prisma/schema.prisma:42
|
41 | id String @id @default(uuid())
42 | createdAt DataTime @default(now())
|
error: Type "DataTime" is neither a built-in type, nor refers to another model, composite type, or enum.
--> prisma/schema.prisma:43
|
42 | createdAt DataTime @default(now())
43 | UpdatedAt DataTime
|
Validation Error Count: 4
[Context: validate]
Prisma CLI Version : 5.14.0
new error, progress miss type DataTime should be DateTime fixed schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User{
id String @id @default(uuid())
createdAt DateTime @default(now())
username String @unique
password String
products Product[]
}
model Product{
id String @id @default(uuid())
createdAt DateTime @default(now())
name String @db.VarChar(255)
belongsToId String
belongsTo User @relation(fields: [belongsToId], references: [id])
updates Update[]
}
enum UPDATE_STATUS {
IN_PROGRESS
SHIPPED
DEPRECATED
}
model Update{
id String @id @default(uuid())
createdAt DateTime @default(now())
UpdatedAt DateTime
title String
body String
status UPDATE_STATUS @default(IN_PROGRESS)
version String?
asset String?
productId String
product Product @relation(fields: [productId], references: [id])
}
model UpdatePoint {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime
name String @db.VarChar(255)
description String
updateId String
update Update @relation(fields: [updateId], references: [id])
}
try formatting angina
@MKrause-code ➜ /workspaces/codespaces-blank $ npx prisma format
Prisma schema loaded from prisma/schema.prisma
Formatted /workspaces/codespaces-blank/prisma/schema.prisma in 40ms 🚀
success!
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
createdAt DateTime @default(now())
username String @unique
password String
products Product[]
}
model Product {
id String @id @default(uuid())
createdAt DateTime @default(now())
name String @db.VarChar(255)
belongsToId String
belongsTo User @relation(fields: [belongsToId], references: [id])
updates Update[]
}
enum UPDATE_STATUS {
IN_PROGRESS
SHIPPED
DEPRECATED
}
model Update {
id String @id @default(uuid())
createdAt DateTime @default(now())
UpdatedAt DateTime
title String
body String
status UPDATE_STATUS @default(IN_PROGRESS)
version String?
asset String?
productId String
product Product @relation(fields: [productId], references: [id])
UpdatePoint UpdatePoint[]
}
model UpdatePoint {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime
name String @db.VarChar(255)
description String
updateId String
update Update @relation(fields: [updateId], references: [id])
}
look how pretty
back to Migrations
https://hendrixer.github.io/API-design-v4/lessons/data-modeling/first-migrations
Migrations: teaches database what data looks like also for moving data around
install npm i @prisma/client --save
@MKrause-code ➜ /workspaces/codespaces-blank $ npm i @prisma/client --save
added 65 packages, and audited 92 packages in 7s
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
works now
run the migration: npx prisma migrate dev --name init
to reset (don't need to do this) npx prisma migrate –reset\
@MKrause-code ➜ /workspaces/codespaces-blank $ npx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "mak_database", schema "public" at "dpg-cpbm7jun7f5s73ffehi0-a.oregon-postgres.render.com"
Applying migration `20240529185154_init`
The following migration(s) have been created and applied from new schema changes:
migrations/
└─ 20240529185154_init/
└─ migration.sql
Your database is now in sync with your schema.
✔ Generated Prisma Client (v5.14.0) to ./node_modules/@prisma/
client in 109ms
now have a migrations folder
https://hendrixer.github.io/API-design-v4/lessons/routes-and-middleware/creating-routes
make new file router.ts in scr folder
import {Router} from 'express'
const router = Router()
app is entire API, router is a subpart of the API
make product
/*--------------------Product------------------*/
router.get('/product', () => {})
router.get('/product/:id', () => {})
router.put('/product/:id', () => {})
router.post('/product', () => {})
router.delete('/product/:id', () => {})
same for update
/*--------------------Update------------------*/
router.get('/update', () => {})
router.get('/update/:id', () => {})
router.put('/update/:id', () => {})
router.post('/update', () => {})
router.delete('/update/:id', () => {})
same for update point
/*--------------------Update Point------------------*/
router.get('/updatepoint', () => {})
router.get('/updatepoint/:id', () => {})
router.put('/updatepoint/:id', () => {})
router.post('/updatepoint', () => {})
router.delete('/updatepoint/:id', () => {})
https://hendrixer.github.io/API-design-v4/lessons/routes-and-middleware/creating-routes
making route
router.ts
export default router
server.ts
import router from './router'
.
.
.
app.use('/api', router)
now need /api to get to router
https://hendrixer.github.io/API-design-v4/lessons/routes-and-middleware/middleware
get VS code plugin Thunder Client for codespace used to test out API calls
open thunder client New request GET (can't seem to be able to edit request, It works now) http://localhost:3001/api/product
Does not work, API is pinging
add a message to get send (in product router.ts)
router.get('/product', (req, res) => {
res.json({message: 'hello'})
})
start server npm run dev
@MKrause-code ➜ /workspaces/codespaces-blank $ npm run dev
> [email protected] dev
> ts-node scr/index.ts
node:internal/modules/cjs/loader:1148
throw err;
^
Error: Cannot find module './index.ts'
Require stack:
- /workspaces/codespaces-blank/scr/imaginaryUncacheableRequireResolveScript
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Function.resolve (node:internal/modules/helpers:190:19)
at requireResolveNonCached (/workspaces/codespaces-blank/node_modules/ts-node/dist/bin.js:549:16)
at getProjectSearchDir (/workspaces/codespaces-blank/node_modules/ts-node/dist/bin.js:519:40)
at phase3 (/workspaces/codespaces-blank/node_modules/ts-node/dist/bin.js:267:27)
at bootstrap (/workspaces/codespaces-blank/node_modules/ts-node/dist/bin.js:47:30)
at main (/workspaces/codespaces-blank/node_modules/ts-node/dist/bin.js:33:12)
at Object.<anonymous> (/workspaces/codespaces-blank/node_modules/ts-node/dist/bin.js:579:5)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/workspaces/codespaces-blank/scr/imaginaryUncacheableRequireResolveScript'
]
}
Node.js v20.13.1
more stuff to fix another miss type package.ts, scr → src
try 2
@MKrause-code ➜ /workspaces/codespaces-blank $ npm run dev
> [email protected] dev
> ts-node src/index.ts
hello on http://localhost:3001/
problem fixed
open thunder client New request GET http://localhost:3001/api/product
Status: 200 OK Size: 19 Bytes Time: 8 ms response
{
"message": "hello"
}
https://hendrixer.github.io/API-design-v4/lessons/routes-and-middleware/middleware
Middleware: functions that can run right before handlers
install some middleware
morgan npm i morgan --save
@MKrause-code ➜ /workspaces/codespaces-blank $ npm i morgan --save
added 5 packages, and audited 97 packages in 765ms
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
add morgan to server.ts
import morgan from 'morgan'
const app = express()
app.use(morgan('dev'))
start the server
@MKrause-code ➜ /workspaces/codespaces-blank $ npm run dev
> [email protected] dev
> ts-node src/index.ts
hello on http://localhost:3001/
open thunder client New request GET http://localhost:3001/api/product
sent back in terminal
GET /api/product 200 1.503 ms - 19
server.ts
app.use(express.json())
app.use(express.urlencoded({extended: true}))
lets user send stuff
make own middleware server.ts
/*custom middleware*/
app.use((req, res, next) => {
req.sh_secret = 'cat'
next()
})
router.ts
router.get('/product', (req, res) => {
res.json({message: req.sh_secret})
})
send secret as message
stop and start server
^C
@MKrause-code ➜ /workspaces/codespaces-blank $ npm run dev
> [email protected] dev
> ts-node src/index.ts
hello on http://localhost:3001/
open thunder client New request GET http://localhost:3001/api/product
Status: 200 OK Size: 17 Bytes Time: 9 ms { "message": "cat" }
middleware change request object, middleware came first in code
can end response (server.ts)
/*end request, do not go to further route*/
app.use((req, res, next) => {
res.status(401)
res.send('Nope')
})
Log into your AWS server. Use your registered subdomain with dynamic DNS if you have completed Week 2 of the AWS Server Setup, otherwise you can use the public IPv4 address.
Create a directory in your assignments folder and commit your work there. <repo_root> is wherever you cloned the monorepo upper-division-cs on your AWS server.
cd <repo_root>/web24-wi/assignments/<your_github_username> mkdir -p infra/week3 cd infra/week3
Create an Express API server in here, which we started in class together on Thursday, January 25th, following these notes and in these Discord messages. https://hendrixer.github.io/API-design-v4/
- Install Postgres via a docker container following Week 3 of the AWS Server Setup.
- Add Prisma data mappings and migrations up to and including this video https://frontendmasters.com/courses/api-design-nodejs-v4/migrations/
- Use your local Postgres URL at localhost:5432 instead of the render.com platform
- Add custom middleware to your Express API server up to and including this video https://frontendmasters.com/courses/api-design-nodejs-v4/creating-a-custom-middleware/
- Start your database a systemd unit file.
- Example of starting any dockerized service with systemd
- @poperigby's systemd example for running any unix command this is almost enough, but we want to add restarting if the service crashes.
- UPDATE: Don't worry about making a systemd file for the API server with node/npm. The original version of this assignment asked you to do this, but there are issues with using
nvm
in a production deploy when it is meant for single-user installs. We are investigating dockerizing the API service. Commit and push these changes on a branch to the monorepo, create a pull request. Ask a classmate to be a reviewer.
will be following wiki page for Infrastructure Backend 25Jan
Step 1. start AWS server
Step 2. ssh into AWS
PS C:\Users\15125> ssh [email protected]
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.5.0-1014-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Thu May 30 20:24:57 UTC 2024
System load: 0.212890625 Processes: 108
Usage of /: 29.7% of 28.89GB Users logged in: 0
Memory usage: 26% IPv4 address for docker0: 172.17.0.1
Swap usage: 0% IPv4 address for eth0: 172.31.33.213
* Ubuntu Pro delivers the most comprehensive open source security and
compliance features.
https://ubuntu.com/aws/pro
Expanded Security Maintenance for Applications is not enabled.
44 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Thu May 30 20:23:20 2024 from 76.121.15.185
Step 3.
Going to make a new workspace directory, my old directory are a bit of a disaster
ubuntu@ip-172-31-33-213:~$ mkdir -p ~/workspace
ubuntu@ip-172-31-33-213:~$ ls
new node_modules package-lock.json package.json pnpm-lock.yaml workspace wshine
ubuntu@ip-172-31-33-213:~$ ssh-keygen -t rsa -b 4096 -C [email protected]
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ubuntu/.ssh/id_rsa
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:EduaxirWZROGasXKLLfyI7saiopZwpFYpLEoR1RrK1c [email protected]
The key's randomart image is:
+---[RSA 4096]----+
|..+.. . |
|.* o . + |
|= o o E = . |
|oo.+ * o = |
|.oo X S |
|. .* o = . |
|o.o + o |
|+=.+.. |
|O.o+.. |
+----[SHA256]-----+
Cloning class repo
ubuntu@ip-172-31-33-213:~$ cd workspace/
ubuntu@ip-172-31-33-213:~/workspace$ ls
ubuntu@ip-172-31-33-213:~/workspace$ git clone [email protected]:TheEvergreenStateCollege/upper-division-cs.git
Cloning into 'upper-division-cs'...
remote: Enumerating objects: 140701, done.
remote: Counting objects: 100% (47728/47728), done.
remote: Compressing objects: 100% (44802/44802), done.
remote: Total 140701 (delta 2748), reused 47455 (delta 2609), pack-reused 92973
Receiving objects: 100% (140701/140701), 412.43 MiB | 33.03 MiB/s, done.
Resolving deltas: 100% (19791/19791), done.
Updating files: 100% (4976/4976), done.
get into file
ubuntu@ip-172-31-33-213:~/workspace$ cd upper-division-cs/web-24wi/assignments/
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments$ ls
AkinaSS EvergreenTor MKrause-code abyssalremark de02E jeff_cook_w24 ppham tw-edu
DawsonWhi Gavin-Bowers Ryan-Geiser annie emoleary nathanMcL qwerty ty_f
DxxYoungblood JonahEadieEvergreen Wizard0523 aquinnallen faulkdf ndeanon25 rain week1
EvergreenSpock MAK Zachsrob ddnsc harleehair poperigby rilesbe wshine
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments$ cd MAK
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK$ ls
frontend infra
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK$ cd infra/
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ ls
'Web Infra HW 03' api-sever
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ cd Web\ Infra\ HW\ 03/
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$
Step 6. already have an ip address with a domain (used it to ssh into server)
Step 7. check to see if already did the code
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ sudo vim /etc/systemd/system/dynamic-dns.service
already have service that runs code
[Unit]
Description=Update DNS entry
After=network.target
[Service]
Type=simple
ExecStart=curl -X PUT --user infra@arcology.builders:web-infra https://mail.arcology.builders/admin/dns/custom/MAK.arcology.builders
RemainAfterExit=true
[Install]
WantedBy=default.target
checking exerting else
buntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ sudo systemctl
daemon-reload
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ sudo systemctl
enable --now dynamic-dns.service
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ sudo reboot
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ Connection to mak.arcology.builders closed by remote host.
Connection to mak.arcology.builders closed.
PS C:\Users\15125> ssh [email protected]
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.5.0-1014-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Thu May 30 20:24:57 UTC 2024
System load: 0.212890625 Processes: 108
Usage of /: 29.7% of 28.89GB Users logged in: 0
Memory usage: 26% IPv4 address for docker0: 172.17.0.1
Swap usage: 0% IPv4 address for eth0: 172.31.33.213
* Ubuntu Pro delivers the most comprehensive open source security and
compliance features.
https://ubuntu.com/aws/pro
Expanded Security Maintenance for Applications is not enabled.
103 updates can be applied immediately.
55 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
Last login: Thu May 30 20:24:58 2024 from 76.121.15.185
Step 8. make sure nvm, pnpm are installed/ update
ubuntu@ip-172-31-33-213:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash . ~/.nvm/nvm.sh
.: .: Is a directory
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
25 16555 25 4125 0 0 55551 0 --:--:-- --:--:-- --:--:-- 55743
curl: (23) Failure writing output to destination
ubuntu@ip-172-31-33-213:~$ nvm install v20
Downloading and installing node v20.14.0...
Downloading https://nodejs.org/dist/v20.14.0/node-v20.14.0-linux-x64.tar.xz...
############################################################################################################## 100.0%Computing checksum with sha256sum
Checksums matched!
Now using node v20.14.0 (npm v10.7.0)
ubuntu@ip-172-31-33-213:~$ npm i -g pnpm
added 1 package in 2s
1 package is looking for funding
run `npm fund` for details
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice To update run: npm install -g [email protected]
npm notice
step 9.
go into assignment directory that I am using for this assignment
ubuntu@ip-172-31-33-213:~$ cd workspace/upper-division-cs/web-24wi/assignments/MAK/infra/
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ ls
'Web Infra HW 03' api-sever
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ cd Web\ Infra\ HW\ 03/
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ ls
'readings code'
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$
install express
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ pnpm init
Wrote to /home/ubuntu/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03/package.json
{
"name": "Web Infra HW 03",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ pnpm i express
Packages: +64
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 64, reused 52, downloaded 12, added 64, done
dependencies:
+ express 4.19.2
Done in 1.9s
add server code
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ vim server.js
1 const express = require("express");
2 const app = express();
3 const port = 5000;
4 const path = require("path");
5
6 app.use(express.static("static"));
7
8 /*app.[method]([route], [route handler])*/
9 app.get("/", (req, res) => {
10 // sending back an HTML file that a browser can render on the screen.
11 res.sendFile(path.resolve("pages/index.html"));
12 });
13
14 // creates and starts a server for our API on a defined port
15 app.listen(port, () => {
16 console.log(`Example app listening at http://localhost:${port}`);
17 });
:x
step 10.
make placeholder page
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ mkdir -p pages
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ vim pages/index.html
1 document.write("Hello world");
start server node
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ node server.js
Example app listening at http://localhost:5000
Step 11.
go to http://mak.arcology.builders:5000/
not exactly what I meant but it works
Step 12. get and make 3 google search hits
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03/pages$ ls
index.html search-hit-1.html search-hit-2.html search-hit-3.html
Step 13.
add to server.js
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03/pages$ cd ..
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ ls
node_modules package.json pages pnpm-lock.yaml 'readings code' server.js
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ vim server.js
19 // Return search hit given :hit URL route parameters
20 app.get("/search-hit/:hit", (req, res) => {
21 // sending back an HTML file that a browser can render on the screen.
22 res.sendFile(path.resolve(`pages/search-hit-${req.params.hit}.html`));
23 });
Step 14. restart node server
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ node server.js
Example app listening at http://localhost:5000
http://mak.arcology.builders:5000/
http://mak.arcology.builders:5000/search-hit/1
http://mak.arcology.builders:5000/search-hit/2
http://mak.arcology.builders:5000/search-hit/3
finished push to github
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ git branch
* WebInfraHW03MAK
main
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra/Web Infra HW 03$ cd ..
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ git add Web\ Infra\ HW\ 03/
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ git commit -m 'search hit work
HW03'
[WebInfraHW03MAK f0e3896bf] search hit work HW03
Committer: Ubuntu <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
7 files changed, 582 insertions(+)
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/package.json
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/pages/index.html
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/pages/search-hit-1.html
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/pages/search-hit-2.html
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/pages/search-hit-3.html
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/pnpm-lock.yaml
create mode 100644 web-24wi/assignments/MAK/infra/Web Infra HW 03/server.js
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ git push
fatal: The current branch WebInfraHW03MAK has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin WebInfraHW03MAK
ubuntu@ip-172-31-33-213:~/workspace/upper-division-cs/web-24wi/assignments/MAK/infra$ git push --set-upstream origin
WebInfraHW03MAK
Enumerating objects: 116, done.
Counting objects: 100% (107/107), done.
Compressing objects: 100% (58/58), done.
Writing objects: 100% (80/80), 103.51 KiB | 7.96 MiB/s, done.
Total 80 (delta 25), reused 49 (delta 17), pack-reused 0
remote: Resolving deltas: 100% (25/25), completed with 13 local objects.
remote:
remote: Create a pull request for 'WebInfraHW03MAK' on GitHub by visiting:
remote: https://github.com/TheEvergreenStateCollege/upper-division-cs/pull/new/WebInfraHW03MAK
remote:
To github.com:TheEvergreenStateCollege/upper-division-cs.git
* [new branch] WebInfraHW03MAK -> WebInfraHW03MAK
Branch 'WebInfraHW03MAK' set up to track remote branch 'WebInfraHW03MAK' from 'origin'.
pushed to the github