Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config refactor #915

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .local-dev/config/ns.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
privateKeyFile: /keys/id_ed25519
adminerURL: http://adminer.local.trapti.tech/
additionalLinks:
- name: Wiki
url: https://wiki.trap.jp/services/NeoShowcase
- name: Adminer
url: http://adminer.local.trapti.tech/

db:
host: mysql
Expand Down
2 changes: 1 addition & 1 deletion .local-manifest/db/adminer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: adminer
image: dockette/adminer:full
image: adminer:4.8.1
imagePullPolicy: Always
env:
- name: ADMINER_DEFAULT_SERVER
Expand Down
9 changes: 7 additions & 2 deletions api/proto/neoshowcase/protobuf/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ message AvailablePort {
PortPublicationProtocol protocol = 3;
}

message AdditionalLink {
string name = 1;
string url = 2;
}

message SystemInfo {
// public_key システムのSSH公開鍵 リポジトリごとにSSH秘密鍵を設定しないデフォルトSSH認証で使用
string public_key = 1;
Expand All @@ -38,8 +43,8 @@ message SystemInfo {
repeated AvailableDomain domains = 3;
// ports 使用可能なポート一覧
repeated AvailablePort ports = 4;
// adminer_url ユーザー用DB管理画面URL
string adminer_url = 5;
// additional_links UIメニューに表示するリンク一覧
repeated AdditionalLink additional_links = 5;
// version NeoShowcase version
string version = 6;
// revision NeoShowcase version
Expand Down
6 changes: 3 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

type Config struct {
PrivateKeyFile string `mapstructure:"privateKeyFile" yaml:"privateKeyFile"`
AdminerURL domain.AdminerURL `mapstructure:"adminerURL" yaml:"adminerURL"`
PrivateKeyFile string `mapstructure:"privateKeyFile" yaml:"privateKeyFile"`
AdditionalLinks []*domain.AdditionalLink `mapstructure:"additionalLinks" yaml:"additionalLinks"`

DB repository.Config `mapstructure:"db" yaml:"db"`
Storage domain.StorageConfig `mapstructure:"storage" yaml:"storage"`
Expand Down Expand Up @@ -106,7 +106,7 @@ type SSGenConfig struct {

func init() {
viper.SetDefault("privateKeyFile", "")
viper.SetDefault("adminerURL", "http://adminer.local.trapti.tech/")
viper.SetDefault("additionalLinks", nil)

viper.SetDefault("db.host", "127.0.0.1")
viper.SetDefault("db.port", 3306)
Expand Down
11 changes: 10 additions & 1 deletion cmd/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/traPtitech/neoshowcase/pkg/usecase/systeminfo"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -93,6 +94,7 @@ var providers = wire.NewSet(
traefikv1alpha1.NewForConfig,
ssgen.NewGeneratorService,
sshserver.NewSSHServer,
systeminfo.NewService,
ubuilder.NewService,
webhook.NewReceiver,
provideRepositoryPrivateKey,
Expand All @@ -103,6 +105,7 @@ var providers = wire.NewSet(
buildpack.NewBuildpackBackend,
provideBuilderConfig,
provideBuildkitClient,
provideSystemInfoConfig,
provideControllerServer,
provideContainerLogger,
provideMetricsService,
Expand All @@ -111,7 +114,7 @@ var providers = wire.NewSet(
provideHealthCheckFunc,
provideStaticServer,
provideStaticServerDocumentRootPath,
wire.FieldsOf(new(Config), "AdminerURL", "DB", "Storage", "Image", "Components"),
wire.FieldsOf(new(Config), "DB", "Storage", "Image", "Components"),
wire.FieldsOf(new(ComponentsConfig), "Builder", "Controller", "Gateway", "GiteaIntegration", "SSGen"),
)

Expand Down Expand Up @@ -198,6 +201,12 @@ func provideBuildkitClient(c Config) (*buildkit.Client, error) {
return client, nil
}

func provideSystemInfoConfig(c Config) *systeminfo.ServiceConfig {
return &systeminfo.ServiceConfig{
AdditionalLinks: c.AdditionalLinks,
}
}

func provideControllerServer(
c Config,
controllerHandler pbconnect.ControllerServiceHandler,
Expand Down
27 changes: 15 additions & 12 deletions cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ services:
- apps

adminer:
image: dockette/adminer:full
image: adminer:4.8.1
restart: always
environment:
ADMINER_DEFAULT_SERVER: mysql
Expand Down
51 changes: 47 additions & 4 deletions dashboard/src/api/neoshowcase/protobuf/gateway_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,49 @@ export class AvailablePort extends Message<AvailablePort> {
}
}

/**
* @generated from message neoshowcase.protobuf.AdditionalLink
*/
export class AdditionalLink extends Message<AdditionalLink> {
/**
* @generated from field: string name = 1;
*/
name = "";

/**
* @generated from field: string url = 2;
*/
url = "";

constructor(data?: PartialMessage<AdditionalLink>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "neoshowcase.protobuf.AdditionalLink";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "url", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): AdditionalLink {
return new AdditionalLink().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): AdditionalLink {
return new AdditionalLink().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): AdditionalLink {
return new AdditionalLink().fromJsonString(jsonString, options);
}

static equals(a: AdditionalLink | PlainMessage<AdditionalLink> | undefined, b: AdditionalLink | PlainMessage<AdditionalLink> | undefined): boolean {
return proto3.util.equals(AdditionalLink, a, b);
}
}

/**
* @generated from message neoshowcase.protobuf.SystemInfo
*/
Expand Down Expand Up @@ -299,11 +342,11 @@ export class SystemInfo extends Message<SystemInfo> {
ports: AvailablePort[] = [];

/**
* adminer_url ユーザー用DB管理画面URL
* additional_links UIメニューに表示するリンク一覧
*
* @generated from field: string adminer_url = 5;
* @generated from field: repeated neoshowcase.protobuf.AdditionalLink additional_links = 5;
*/
adminerUrl = "";
additionalLinks: AdditionalLink[] = [];

/**
* version NeoShowcase version
Expand Down Expand Up @@ -331,7 +374,7 @@ export class SystemInfo extends Message<SystemInfo> {
{ no: 2, name: "ssh", kind: "message", T: SSHInfo },
{ no: 3, name: "domains", kind: "message", T: AvailableDomain, repeated: true },
{ no: 4, name: "ports", kind: "message", T: AvailablePort, repeated: true },
{ no: 5, name: "adminer_url", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 5, name: "additional_links", kind: "message", T: AdditionalLink, repeated: true },
{ no: 6, name: "version", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 7, name: "revision", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);
Expand Down
43 changes: 35 additions & 8 deletions dashboard/src/components/UI/UserMenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DropdownMenu } from '@kobalte/core'
import { keyframes, style } from '@macaron-css/core'
import { styled } from '@macaron-css/solid'
import { A } from '@solidjs/router'
import type { Component } from 'solid-js'
import { type Component, For } from 'solid-js'
import type { User } from '/@/api/neoshowcase/protobuf/gateway_pb'
import { systemInfo } from '/@/libs/api'
import { colorVars, media, textVars } from '/@/theme'
Expand Down Expand Up @@ -98,6 +98,24 @@ const VersionContainer = styled('div', {
},
})

const linkNameToMaterialIcon = (name: string): string => {
// Manually assign icons to some known external link names
const lowerName = name.toLowerCase()
switch (lowerName) {
case 'wiki':
case 'help':
return 'help'
case 'phpmyadmin':
case 'adminer':
case 'db admin':
return 'database'
}
if (lowerName.includes('mysql') || lowerName.includes('mongo')) {
return 'database'
}
return 'open_in_new'
}

export const UserMenuButton: Component<{
user: User
}> = (props) => {
Expand All @@ -119,13 +137,22 @@ export const UserMenuButton: Component<{
</Button>
</A>
</DropdownMenu.Item>
<DropdownMenu.Item>
<a href="https://wiki.trap.jp/services/NeoShowcase" target="_blank" rel="noopener noreferrer">
<Button variants="text" size="medium" leftIcon={<MaterialSymbols>help</MaterialSymbols>} full>
Help
</Button>
</a>
</DropdownMenu.Item>
<For each={systemInfo()?.additionalLinks}>
{(link) => (
<DropdownMenu.Item>
<a href={link.url} target="_blank" rel="noopener noreferrer">
<Button
variants="text"
size="medium"
leftIcon={<MaterialSymbols>{linkNameToMaterialIcon(link.name)}</MaterialSymbols>}
full
>
{link.name}
</Button>
</a>
</DropdownMenu.Item>
)}
</For>
<DropdownMenu.Item>
<VersionContainer>
<span>NeoShowcase</span>
Expand Down
7 changes: 0 additions & 7 deletions dashboard/src/components/templates/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ export const Header: Component = () => {
Queue
</Button>
</A>
<Show when={systemInfo()?.adminerUrl}>
<a href={systemInfo()?.adminerUrl} target="_blank" rel="noopener noreferrer">
<Button size="medium" variants="text" rightIcon={<MaterialSymbols>open_in_new</MaterialSymbols>}>
Adminer
</Button>
</a>
</Show>
</NavigationContainer>
<Show when={user()}>
{(user) => (
Expand Down
7 changes: 0 additions & 7 deletions dashboard/src/components/templates/MobileNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ const MobileNavigation: Component = () => {
Queue
</Button>
</A>
<Show when={systemInfo()?.adminerUrl}>
<a href={systemInfo()?.adminerUrl} target="_blank" rel="noopener noreferrer">
<Button full size="medium" variants="text" rightIcon={<MaterialSymbols>open_in_new</MaterialSymbols>}>
Adminer
</Button>
</a>
</Show>
</NavigationContainer>
</Dialog.Content>
</Dialog.Portal>
Expand Down
Loading
Loading