Skip to content

Commit

Permalink
feat!: Plugsy can now work in agent mode.
Browse files Browse the repository at this point in the history
It can now gather statuses from within a cluster and push to another plugsy endpoint, docs to follow.

Huge refactor.

breaking change: the types for each of the config plugins is now capitalised.
  • Loading branch information
Inlustra committed Jun 25, 2021
1 parent 1ea53b1 commit 8a41ed1
Show file tree
Hide file tree
Showing 42 changed files with 2,575 additions and 708 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
uses: jacobtomlinson/gha-find-replace@master
with:
find: "https:\\/\\/github\\.com\\/plugsy\\/core\\/releases\\/download\\/(.*?)\\/schema\\.json"
replace: "https://github.com/plugsy/core/releases/download/v${{ steps.extractver.outputs.version }}/schema.json"
replace: "https://github.com/plugsy/core/releases/download/v${{ steps.extractver.outputs.version }}/config-schema.json"

- name: Create Pull Request with updated package files
if: steps.initversion.outputs.version != steps.extractver.outputs.version
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ config.json

```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {}
},
{
"type": "raw",
"type": "RAW",
"config": {
"id": "file",
"items": [
Expand Down Expand Up @@ -165,14 +165,14 @@ Example using the [raw connector](docs/connectors/raw.md):

```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {}
},
{
"type": "raw",
"type": "RAW",
"config": {
"id": "file",
"items": [
Expand Down
16 changes: 5 additions & 11 deletions client/components/Favicon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ export interface FaviconProps {
}

export const Favicon: React.FC<FaviconProps> = ({ state = "GREEN" }) => {
const href =
state === "GREEN" ? "/favicon-success.svg" : "/favicon-error.svg";
return (
<Head>
<link
rel="icon"
type="image/svg+xml"
href={state === "GREEN" ? '/favicon-success.svg' : '/favicon-error.svg'}
/>
<link
rel="mask-icon"
type="image/svg+xml"
href={state === "GREEN" ? '/favicon-success.svg' : '/favicon-error.svg'}
/>
<link rel="alternate icon" href={'/favicon.ico'}/>
<link rel="icon" type="image/svg+xml" href={href} />
<link rel="mask-icon" type="image/svg+xml" href={href} />
<link rel="alternate icon" href={"/favicon.ico"} />
</Head>
);
};
16 changes: 8 additions & 8 deletions client/components/Item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { SSRPopover } from "../SSRPopover";
import { ArrowContainer } from "react-tiny-popover";

interface ItemData {
icon?: string;
iconPack?: string;
iconName?: string | null;
iconPack?: string | null;
text?: string;
link?: string;
status?: string;
Expand Down Expand Up @@ -53,14 +53,14 @@ const TextContainer = styled.div`
const Popover: React.FC<{ entities: ItemData[] }> = ({ entities }) => {
return (
<PopoverContainer>
{entities.map(({ text, icon, status, iconPack, state }, i) => (
{entities.map(({ text, iconName, status, iconPack, state }, i) => (
<Fragment key={`child-${text}`}>
<PopoverEntity>
<StatusBar state={state} />
<TagInfo>
{icon && iconPack ? (
{iconName && iconPack ? (
<Icon>
<DynamicIcon icon={icon} iconPack={iconPack} />
<DynamicIcon icon={iconName} iconPack={iconPack} />
</Icon>
) : null}
<TextContainer>
Expand Down Expand Up @@ -155,7 +155,7 @@ const Margins = styled.div`
`;

export const Item: React.FC<ItemProps> = ({
icon,
iconName,
iconPack,
text,
link,
Expand Down Expand Up @@ -201,9 +201,9 @@ export const Item: React.FC<ItemProps> = ({
<StatusBar state={state} />
<Margins>
<TagInfo>
{icon && iconPack ? (
{iconName && iconPack ? (
<Icon>
<DynamicIcon icon={icon} iconPack={iconPack} />
<DynamicIcon icon={iconName} iconPack={iconPack} />
</Icon>
) : null}
<TextContainer>
Expand Down
6 changes: 4 additions & 2 deletions client/pages/Home/Home.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ fragment FullCategory on Category {
items {
name
status
icon
iconName
iconPack
link
state
connectorType
children {
name
state
icon
iconName
iconPack
status
connectorType
}
Expand Down
33 changes: 24 additions & 9 deletions client/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import parseISO from "date-fns/parseISO";
import Head from "next/head";
import React, { useCallback, useEffect, useState } from "react";
import styled from "styled-components";
import { apolloClient } from "../../../lib/apollo";
import { createApolloClient } from "../../../lib/apollo";
import { State } from "../../../types.graphql";
import { ConnectionStatus } from "../../components/ConnectionStatus";
import { Category } from "../../components/Category";
Expand All @@ -19,6 +19,9 @@ import {
} from "./Home.generated.graphql";
import { useHarmonicIntervalFn } from "react-use";
import { Favicon } from "../../components/Favicon";
import { createIsomorphLink } from "../../../lib/apollo/links";
import { GetServerSideProps } from "next";
import absoluteUrl from "next-absolute-url";

interface Props {
initialCategories?: FullCategoryFragment[];
Expand Down Expand Up @@ -140,7 +143,8 @@ export function Home({
({
name,
link,
icon,
iconName,
iconPack,
state,
children,
status,
Expand All @@ -150,22 +154,29 @@ export function Home({
key: name,
text: name,
link: link ?? undefined,
iconPack: icon?.split("/")[0],
icon: icon?.split("/")[1],
iconPack,
iconName,
connectorType,
state: statesToStatus([
state,
...children.map((child) => child.state),
]),
status: status ? toTitleCase(status) : undefined,
children: children.map(
({ name, icon, state, status, connectorType }) => ({
({
name,
iconName,
iconPack,
state,
status,
connectorType,
}) => ({
key: name,
connectorType,
iconName,
iconPack,
text: name,
status: status ? toTitleCase(status) : undefined,
iconPack: icon?.split("/")[0],
icon: icon?.split("/")[1],
state: statesToStatus([state]),
})
),
Expand Down Expand Up @@ -194,7 +205,11 @@ export function Home({
);
}

export async function getServerSideProps() {
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
const { origin } = absoluteUrl(req);
const apolloClient = createApolloClient({
links: [createIsomorphLink(origin)],
});
const { data, error } = await apolloClient.query<InitQuery>({
query: InitDocument,
fetchPolicy: "no-cache",
Expand All @@ -211,4 +226,4 @@ export async function getServerSideProps() {
initialServerTime: data?.serverTime ?? null,
} as Props,
};
}
};
26 changes: 24 additions & 2 deletions codegen.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
schema: "**/*.server.graphql"
generates:
server/agent/agent.generated.graphql.ts:
documents: "server/agent/*.graphql"
plugins:
- add:
content: "/* eslint-disable */"
- typescript
- typescript-graphql-request
- typescript-operations
config:
enumsAsTypes: true
avoidOptionals: true
rawRequest: true

./types.graphql.ts:
config:
enumsAsTypes: true
avoidOptionals: true
plugins:
- add:
content: "/* eslint-disable */"
- typescript
./:
documents: "**/*.graphql"
documents: "client/**/*.graphql"
preset: near-operation-file
config:
enumsAsTypes: true
avoidOptionals: true
presetConfig:
extension: .generated.graphql.ts
baseTypesPath: types.graphql.ts
Expand All @@ -28,8 +47,11 @@ generates:
- typescript-operations
- typed-document-node
config:
enumsAsTypes: true
avoidOptionals: true
contextType: ../context#Context
useIndexSignature: true
defaultMapper: DeepPartial<{T}>
scalars:
scalars:
Date: Date
Void: void
8 changes: 4 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {}
},
{
"type": "website",
"type": "WEBSITE",
"config": {
"sites": [
{
Expand Down Expand Up @@ -40,4 +40,4 @@
}
}
]
}
}
8 changes: 4 additions & 4 deletions docs/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Can use a list of website urls (And other request formats) for Plugsy to ping an

```
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {}
},
{
"type": "website",
"type": "WEBSITE",
"config": {
"sites": [
{
Expand All @@ -45,7 +45,7 @@ Can use a list of website urls (And other request formats) for Plugsy to ping an
}
},
{
"type": "raw",
"type": "RAW",
"config": {
"items": [
{
Expand Down
12 changes: 6 additions & 6 deletions docs/connectors/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ A docker connector, provides access directly to a docker socket or URL mapping e

```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {}
}
]
Expand Down Expand Up @@ -95,10 +95,10 @@ services:
```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {
"containerMap": {
"vikunjafrontend": {
Expand Down Expand Up @@ -130,10 +130,10 @@ See [Dockerode](https://www.npmjs.com/package/dockerode) for alternative connect

```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "docker",
"type": "DOCKER",
"config": {
"id": "", // Optional defaults to "docker"
"dockerOptions": {
Expand Down
8 changes: 4 additions & 4 deletions docs/connectors/raw.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Provides items in the dashboard directly from the config itself

```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "raw",
"type": "RAW",
"config": {
"items": [
{
Expand All @@ -28,10 +28,10 @@ Provides items in the dashboard directly from the config itself

```jsonc
{
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/schema.json",
"$schema": "https://github.com/plugsy/core/releases/download/v2.2.0/config-schema.json",
"connectors": [
{
"type": "raw",
"type": "RAW",
"config": {
"items": [
{
Expand Down
Loading

0 comments on commit 8a41ed1

Please sign in to comment.