merge from dev, ci-done

This commit is contained in:
Sense T 2024-04-23 15:44:27 +08:00
parent 021ec9c8f6
commit 7ec564aac0
8 changed files with 243 additions and 25 deletions

78
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -0,0 +1,78 @@
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3.3.0
with:
cosign-release: v1.13.2
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

77
.github/workflows/go.yml vendored Normal file
View File

@ -0,0 +1,77 @@
name: Go
on:
push:
tags:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up NodeJS
uses: actions/setup-node@v4
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22
- name: Build Web UI
run: |
cd web
npm i && npm run build
cd ..
go generate ./...
- name: Build-linux-amd64
env:
GOOS: linux
GOARCH: amd64
run: |
mkdir -p recored-ui-${GOOS}-${GOARCH}
go build -trimpath -ldflags "-w -s" -v -o ./recored-ui-${GOOS}-${GOARCH} ./...
cp README.md LICENSE recored-ui-${GOOS}-${GOARCH}
tar czvf recored-ui-${GOOS}-${GOARCH}.tgz recored-ui-${GOOS}-${GOARCH}
- name: Build-linux-arm64
env:
GOOS: linux
GOARCH: arm64
run: |
mkdir -p recored-ui-${GOOS}-${GOARCH}
go build -trimpath -ldflags "-w -s -X main.Version=${{ github.ref_name }}" -v -o ./recored-ui-${GOOS}-${GOARCH} ./...
cp README.md LICENSE recored-ui-${GOOS}-${GOARCH}
tar czvf recored-ui-${GOOS}-${GOARCH}.tgz recored-ui-${GOOS}-${GOARCH}
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
name: Release ${{ github.ref_name }}
- name: Upload Release Asset Linux arm64
id: upload-release-asset-linux-arm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/recored-ui-linux-arm64.tgz
asset_name: recored-ui-linux-arm64.tgz
asset_content_type: application/x-gzip
- name: Upload Release Asset Linux amd64
id: upload-release-asset-linux-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/recored-ui-linux-amd64.tgz
asset_name: recored-ui-linux-amd64.tgz
asset_content_type: application/x-gzip

6
.gitignore vendored
View File

@ -16,7 +16,8 @@
*.out *.out
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ !vendor/modules.txt
vendor/**/*
# Go workspace file # Go workspace file
go.work go.work
@ -35,4 +36,5 @@ test/
node_modules/ node_modules/
dist/ dist/
.direnv .direnv
result

View File

@ -6,9 +6,9 @@ RUN cd web && npm i && npm run build
FROM golang as server FROM golang as server
WORKDIR /src WORKDIR /src
COPY --stage web /src . COPY --from=web /src .
RUN go get . && go generate ./... && go build . RUN go get . && go generate ./... && go build -trimpath -ldflags '-w -s -X main.Version=v1.0.0' .
FROM scratch FROM scratch
COPY --stage server /src/reCoreD-UI . COPY --from=server /src/reCoreD-UI .
ENTRYPOINT [ '/reCoreD-UI' ] ENTRYPOINT [ '/reCoreD-UI' ]

View File

@ -8,26 +8,52 @@
utils.lib.eachDefaultSystem (system: utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
name = "reCoreD-UI";
version = "v1.0.0";
in in
{ {
packages = rec { defaultPackage = with pkgs; let
recored-ui = with pkgs; stdenv.mkDerivation rec { web = buildNpmPackage {
name = "recored-ui"; inherit version;
pname = name;
src = "${self}/web";
npmDepsHash = "sha256-e4AYJa0PXhuBRytH4860v6t3DEcQ5awR24HeXRD5pew=";
};
app = buildGoModule {
pname = name;
inherit version;
src = self; src = self;
buildInputs = [
go ldflags = [
nodejs "-s"
"-w"
"-X main.Version=${version}"
]; ];
buildPhase = ''
cd web && npm i && npm run build && cd .. configurePhase = ''
go get . && go generate ./... && go build . -o recored-ui -ldflags "-s -w" cp -r ${web}/lib/node_modules/web/dist server
export HOME=/tmp/build
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp recored-ui $out/bin ls -l
cp $HOME/go/bin/reCoreD-UI $out/bin
''; '';
doCheck = false;
deleteVendor = true;
proxyVendor = true;
}; };
default = recored-ui; in
stdenv.mkDerivation {
name = "${name}-${version}";
src = self;
installPhase = ''
mkdir -p $out/bin
cp ${app}/bin/reCoreD-UI $out/bin
'';
}; };
devShell = with pkgs; mkShell { devShell = with pkgs; mkShell {
@ -63,12 +89,12 @@
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services.recored-ui = { systemd.services.reCoreD-UI = {
wantedBy = [ "multi-uesr.target" ]; wantedBy = [ "multi-uesr.target" ];
environment = { environment = {
RECORED_MYSQL_DSN = cfg.mysql-dsn; RECORED_MYSQL_DSN = cfg.mysql-dsn;
}; };
serviceconfig.ExecStart = "${pkgs.recored-ui}/bin/recored-ui server"; serviceconfig.ExecStart = "${defaultPackage}/bin/reCoreD-UI server";
}; };
}; };
}; };

41
main.go
View File

@ -1,3 +1,26 @@
/*
reCoreD-UI provides web ui for CoreDNS
NAME:
reCoreD-UI - Web UI for CoreDNS
USAGE:
reCoreD-UI [global options] command [command options]
COMMANDS:
server run server
config config some settings
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--config value, -c value config yaml file [$RECORED_CONFIG_FILE]
--mysql-dsn value mysql dsn [$RECORED_MYSQL_DSN]
--debug enable debug mode (default: false)
--help, -h show help
*/
package main package main
import ( import (
@ -11,15 +34,18 @@ import (
"github.com/urfave/cli/v2/altsrc" "github.com/urfave/cli/v2/altsrc"
) )
// will be modified when building
var Version string = "v0.0.1"
func init() { func init() {
logrus.SetReportCaller(true) logrus.SetReportCaller(true)
} }
// @title reCoreD-UI API // @title reCoreD-UI API
// @version 1.0 // @version 1.0
// @description APIs for reCoreD-UI // @description APIs for reCoreD-UI
// @BasePath /api/v1 // @BasePath /api/v1
// @securityDefinitions.basic BasicAuth // @securityDefinitions.basic BasicAuth
func main() { func main() {
flags := []cli.Flag{ flags := []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
@ -47,8 +73,9 @@ func main() {
} }
app := &cli.App{ app := &cli.App{
Name: "reCoreD-UI", Name: "reCoreD-UI",
Usage: "Web UI for CoreDNS", Version: Version,
Usage: "Web UI for CoreDNS",
Before: altsrc.InitInputSourceWithContext( Before: altsrc.InitInputSourceWithContext(
flags, altsrc.NewYamlSourceFromFlagFunc("config"), flags, altsrc.NewYamlSourceFromFlagFunc("config"),
), ),

View File

@ -18,6 +18,7 @@ type Props = {
createRecord(record: Record): Promise<void> createRecord(record: Record): Promise<void>
} }
// convert enum RecordTypes to a list for select options.
const recordTypeOptions = Object.entries(RecordTypes).filter(e => e[1] !== RecordTypes.RecordTypeSOA).map(e => { const recordTypeOptions = Object.entries(RecordTypes).filter(e => e[1] !== RecordTypes.RecordTypeSOA).map(e => {
return { return {
value: e[1], value: e[1],
@ -246,6 +247,8 @@ export default function RecordEditModal({ open, record, onOk, onCancel, editReco
</Form.Item> </Form.Item>
<Form.Item<Record> noStyle shouldUpdate={(p, c) => p.record_type !== c.record_type}> <Form.Item<Record> noStyle shouldUpdate={(p, c) => p.record_type !== c.record_type}>
{ {
// load form for record type from the map 'controls'.
// this is a dynamic form
({ getFieldValue }: FormInstance<Record>) => { ({ getFieldValue }: FormInstance<Record>) => {
const e = controls.get(getFieldValue('record_type')) const e = controls.get(getFieldValue('record_type'))
if (!e) { if (!e) {

View File

@ -1,3 +1,8 @@
/*
Web UI for reCoreD-UI
Use React and ant-design now.
JSX/TSX is cool!
*/
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom/client' import ReactDOM from 'react-dom/client'
import App from './App.tsx' import App from './App.tsx'