From f469bbe3bcc6d457d5b4957223bd4e2e4bb4d92e Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 20 Mar 2022 21:04:42 -0700 Subject: [PATCH] copy frontend into core for docker bundle --- core/.gitignore | 1 + core/Dockerfile | 2 ++ core/package.json | 7 +++---- frontend/src/components/App/App.tsx | 17 ++++++++++------- frontend/src/components/Login.tsx | 3 +-- frontend/src/state/StateProvider.tsx | 4 +--- frontend/src/util/client.ts | 10 +++++----- frontend/src/util/helpers.ts | 5 ----- 8 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 core/.gitignore diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 000000000..10d4fb7ac --- /dev/null +++ b/core/.gitignore @@ -0,0 +1 @@ +frontend \ No newline at end of file diff --git a/core/Dockerfile b/core/Dockerfile index d526fa5b6..c24929262 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -3,6 +3,8 @@ FROM node:alpine RUN apk update && apk add docker git openrc --no-cache RUN addgroup root docker && rc-update add docker boot +COPY ./frontend /frontend + WORKDIR /monitor COPY ./build/package.json ./ diff --git a/core/package.json b/core/package.json index 5cc83381c..e54f01d66 100644 --- a/core/package.json +++ b/core/package.json @@ -6,10 +6,9 @@ "license": "MIT", "scripts": { "start": "tsc && node build/main.js", - "build": "vite build && node post-build.mjs && docker build -t mbecker2020/monitor-core .", - "push": "yarn build && docker push mbecker2020/monitor-core", - "docker-run": "docker run -d --name monitor-core --network=\"host\" -v /Users/max/GitHub/monitor/core/secrets:/secrets -v /Users/max/GitHub/monitor/frontend/build:/frontend mbecker2020/monitor-core", - "docker-remove": "docker stop monitor-core && docker container rm monitor-core" + "build-copy-frontend": "cd ../frontend && yarn build && cd ../core && rm -r frontend && mkdir frontend && cp -a ../frontend/build/. ./frontend/", + "build": "vite build && node post-build.mjs && yarn build-copy-frontend && docker build -t mbecker2020/monitor-core .", + "push": "yarn build && docker push mbecker2020/monitor-core" }, "devDependencies": { "@monitor/types": "1.0.0", diff --git a/frontend/src/components/App/App.tsx b/frontend/src/components/App/App.tsx index 86e676f59..9aa63f7be 100644 --- a/frontend/src/components/App/App.tsx +++ b/frontend/src/components/App/App.tsx @@ -4,6 +4,7 @@ import styles from "./App.module.css"; import UserInfo from "../UserInfo"; import { User } from "@monitor/types" import Login from "../Login"; +import { AppStateProvider } from "../../state/StateProvider"; const App: Component = () => { const [user, { mutate }] = createResource(() => client.getUser()); @@ -12,13 +13,15 @@ const App: Component = () => {
- { - client.logout(); - mutate(false); - }} - /> + + { + client.logout(); + mutate(false); + }} + /> +
...
diff --git a/frontend/src/components/Login.tsx b/frontend/src/components/Login.tsx index 4e433fb4b..dd5cd7d73 100644 --- a/frontend/src/components/Login.tsx +++ b/frontend/src/components/Login.tsx @@ -1,5 +1,4 @@ import { Component } from "solid-js"; -import { loginGithub } from "../util/helpers"; import Input from "./util/Input"; import Grid from "./util/layout/Grid"; import { createStore } from "solid-js/store"; @@ -59,7 +58,7 @@ const Login: Component<{ setUser: (user: User | false) => void }> = (p) => { - + ); }; diff --git a/frontend/src/state/StateProvider.tsx b/frontend/src/state/StateProvider.tsx index 546eb4599..fb62a6813 100644 --- a/frontend/src/state/StateProvider.tsx +++ b/frontend/src/state/StateProvider.tsx @@ -16,15 +16,13 @@ export type State = { const context = createContext }>(); -export const Provider: Component<{}> = (p) => { +export const AppStateProvider: Component<{}> = (p) => { const state: State = { servers: useServers(), builds: useBuilds(), deployments: useDeployments(), updates: useUpdates(), }; - - // created state before attaching ws, to pass state easily to ws const ws = useWs(state); diff --git a/frontend/src/util/client.ts b/frontend/src/util/client.ts index 1cda2ce0c..e0c27fa08 100644 --- a/frontend/src/util/client.ts +++ b/frontend/src/util/client.ts @@ -1,5 +1,4 @@ import axios from "axios"; -import { URL } from ".."; import { User } from "@monitor/types"; export default class Client { @@ -8,17 +7,14 @@ export default class Client { constructor(private baseURL: string) { const params = new URLSearchParams(location.search); const token = params.get("token"); - const redirect = params.get("redirect") if (token) { this.token = token; localStorage.setItem("access_token", this.token); history.replaceState( {}, "", - `${URL}${redirect ? `/?redirect=${redirect}` : ""}` + this.baseURL ); - } else if (params.get("logout") === "true") { - this.logout(); } } @@ -29,6 +25,10 @@ export default class Client { return await this.getUser(); } + loginGithub() { + window.location.replace(`${this.baseURL}/login/github`); + } + async signup(username: string, password: string) { const jwt: string = await this.post("/signup", { username, password }); this.token = jwt; diff --git a/frontend/src/util/helpers.ts b/frontend/src/util/helpers.ts index e9450c595..7555b0d90 100644 --- a/frontend/src/util/helpers.ts +++ b/frontend/src/util/helpers.ts @@ -1,4 +1,3 @@ -import { URL } from ".."; import { Collection, User } from "@monitor/types"; export function combineClasses(...classes: (string | undefined)[]) { @@ -14,10 +13,6 @@ export function getAuthProvider(user: User) { else return "Local"; } -export function loginGithub() { - window.location.replace(`${URL}/login/github`); -} - export function generateQuery(query?: Collection) { if (query) { const q = Object.keys(query)