Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam McKee committed Jan 24, 2024
1 parent bfdbcef commit a9ba3a5
Show file tree
Hide file tree
Showing 34 changed files with 522 additions and 286 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "tsc --build --clean && tsc --build"
},
"dependencies": {
"@eighty4/install-github": "workspace:^0.0.1",
"@eighty4/install-template": "workspace:^0.0.1",
"cookie-parser": "^1.4.6",
"express": "^5.0.0-beta.1",
Expand Down
75 changes: 0 additions & 75 deletions backend/src/Repositories.ts

This file was deleted.

18 changes: 8 additions & 10 deletions backend/src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import net from 'node:net'
import express, {RequestHandler} from 'express'
import cookieParser from 'cookie-parser'
import {queryLatestRelease} from '@eighty4/install-github'
import {generateScript} from '@eighty4/install-template'
import {loadGeneratedScripts, saveGeneratedScript} from './Database.js'
import {initiateLogin, resolveLogin} from './Login.js'
import {queryLatestRelease} from './Releases.js'
import {resolveTemplateRuntimeVersion} from './Resolution.js'
import {resolveTemplateRuntimeVersion} from './Template.js'
import {verifyAccessToken} from './User.js'

const parsePortEnvVariable = (key: string, def: number): number => {
Expand All @@ -15,7 +15,7 @@ const parsePortEnvVariable = (key: string, def: number): number => {
} else {
try {
return parseInt(val, 10)
} catch(e) {
} catch (e) {
console.error(`env variable ${key} must be numeric`)
process.exit(1)
}
Expand Down Expand Up @@ -48,7 +48,7 @@ app.use((req, res, next) => {
})

const authorize: RequestHandler = (req, res, next) => {
const accessToken = req.cookies.gat
const accessToken = req.cookies.gh
verifyAccessToken(accessToken)
.then((user) => {
if (user === false) {
Expand Down Expand Up @@ -89,7 +89,7 @@ app.get('/login/notify', async (req, res) => {
} else {
try {
const authData = await resolveLogin(loginId)
res.setHeader('Set-Cookie', `gat=${authData.accessToken}; Secure; HttpOnly; SameSite=Strict; Path=/api`)
res.setHeader('Set-Cookie', `gh=${authData.accessToken}; Secure; SameSite=Strict; Path=/api`)
res.json({newUser: authData.newUser})
} catch (e: any) {
console.log('auth resolve wtf', e.message)
Expand All @@ -110,11 +110,9 @@ app.get('/api/projects', authorize, async (req, res) => {
})

app.get('/api/release/:repoOwner/:repoName', authorize, async (req, res) => {
const release = await queryLatestRelease({
accessToken: req.user!.accessToken, repository: {
owner: req.params['repoOwner'],
name: req.params['repoName'],
},
const release = await queryLatestRelease(req.user!.accessToken, {
owner: req.params['repoOwner'],
name: req.params['repoName'],
})
if (release) {
res.json(release)
Expand Down
13 changes: 13 additions & 0 deletions backend/src/Template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {readFileSync} from 'node:fs'

export function resolveTemplateRuntimeVersion() {
try {
let packageJson = import.meta.resolve('../node_modules/@eighty4/install-template/package.json')
if (packageJson.startsWith('file:///')) {
packageJson = packageJson.substring(7)
}
return JSON.parse(readFileSync(packageJson).toString()).version
} catch (e) {
throw new Error('failed resolving version of @eighty4/install-template')
}
}
1 change: 1 addition & 0 deletions backend/src/req.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare namespace Express {
export interface Request {
user?: { accessToken: string, login: string, userId: number },
cookies: { gh?: string },
}
}
3 changes: 3 additions & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"src/**/*.ts"
],
"references": [
{
"path": "../github"
},
{
"path": "../template"
}
Expand Down
24 changes: 24 additions & 0 deletions cloud/aws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
t4g arm instance
t4g.medium
$12 per month
2 cpu 4 gb

t3 intel instance
t3.medium
$15 per month
2 cpu 4 gb

CICD on AWS would be with CodeBuild or CodePipeline
https://aws.amazon.com/blogs/devops/build-arm-based-applications-using-codebuild/

install docker
configure systemd postgres and install.sh services
https://blog.container-solutions.com/running-docker-containers-with-systemd

cicd update install.sh with ssh restart
https://unix.stackexchange.com/a/395781

send to grafana cloud
- machine metrics
- container metrics
- container logs
30 changes: 30 additions & 0 deletions cloud/backend.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
job "install.backend" {
type = "service"

group "install.backend" {
count = 1

task "install.backend" {
driver = "docker"

config {
image = "84tech/install.backend:latest"

auth {
config = "/Users/adam/.docker/config.json"
}
}

env {
}
}
}

update {
max_parallel = 1
min_healthy_time = "5s"
healthy_deadline = "3m"
auto_revert = false
canary = 0
}
}
27 changes: 27 additions & 0 deletions cloud/postgres.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
job "postgres" {
type = "service"

group "postgres" {
count = 1

task "postgres" {
driver = "docker"

config {
image = "postgres:16"
}

env {
POSTGRES_PASSWORD = eighty4
}
}
}

update {
max_parallel = 1
min_healthy_time = "5s"
healthy_deadline = "3m"
auto_revert = false
canary = 0
}
}
5 changes: 3 additions & 2 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@
</div>
</div>
<div id="header">
<h2>Binary Installs,</h2>
<h3>Simplified</h3>
<h1 style="display: none">Install.sh</h1>
<h2>Binaries,</h2>
<h3>Installed</h3>
</div>
<div id="logo">
<img src="/logo_i.svg" alt="Install.sh logo"/>
Expand Down
Loading

0 comments on commit a9ba3a5

Please sign in to comment.