Merge branch 'sorenisanerd:master' into master

This commit is contained in:
老J 2022-12-11 18:10:11 +08:00 committed by GitHub
commit 9224e98568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 3007 additions and 20 deletions

36
.github/workflows/pre-release.yaml vendored Normal file
View File

@ -0,0 +1,36 @@
---
name: "pre-release"
on:
push:
branches:
- "master"
jobs:
pre-release-docker:
name: "Pre Release Docker"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
username: "${{ secrets.DOCKER_HUB_USER }}"
password: "${{ secrets.DOCKER_HUB_TOKEN }}"
- name: "Build and push docker image"
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: "${{ secrets.DOCKER_REPO }}:latest"

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"amodio.tsl-problem-matcher"
]
}

15
.vscode/launch.json vendored
View File

@ -7,10 +7,21 @@
{
"name": "Launch GoTTY",
"type": "go",
"buildFlags": "-tags=dev",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"args": ["-a", "127.0.0.1", "-w", "bash"]
}
"args": ["-a", "127.0.0.1", "-w", "${env:SHELL}"]
},
{
"name": "Launch Chrome",
"type": "chrome",
"url": "http://127.0.0.1:8080",
"webRoot": "${workspaceFolder}/js",
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
],
},
]
}

16
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "webpack watch",
"type": "shell",
"command": "cd ${workspaceFolder}/js;DEV=1 npx webpack --watch --mode=development",
"problemMatcher": [
"$ts-webpack-watch"
],
"isBackground": true
}
]
}

View File

@ -1,15 +1,20 @@
FROM golang:1.16
FROM node:16 as js-build
WORKDIR /gotty
COPY js /gotty/js
COPY Makefile /gotty/
RUN make bindata/static/js/gotty.js.map
FROM golang:1.16 as go-build
WORKDIR /gotty
COPY . /gotty
COPY --from=js-build /gotty/js/node_modules /gotty/js/node_modules
COPY --from=js-build /gotty/bindata/static/js /gotty/bindata/static/js
RUN CGO_ENABLED=0 make
FROM alpine:latest
RUN apk update && \
apk upgrade && \
apk --no-cache add ca-certificates && \
apk add bash
apk --no-cache add ca-certificates bash
WORKDIR /root
COPY --from=0 /gotty/gotty /usr/bin/
COPY --from=go-build /gotty/gotty /usr/bin/
CMD ["gotty", "-w", "bash"]

View File

@ -2,7 +2,14 @@ OUTPUT_DIR = ./builds
GIT_COMMIT = `git rev-parse HEAD | cut -c1-7`
VERSION = $(shell git describe --tags)
BUILD_OPTIONS = -ldflags "-X main.Version=$(VERSION)"
ifeq ($(DEV), 1)
BUILD_OPTIONS += -tags dev
WEBPACK_MODE = development
else
WEBPACK_MODE = production
endif
export CGO_ENABLED=0
gotty: main.go assets server/*.go webtty/*.go backend/*.go Makefile

View File

@ -1,3 +1,5 @@
//go:build !dev
package bindata
import "embed"

28
bindata/bindata_dev.go Normal file
View File

@ -0,0 +1,28 @@
//go:build dev
package bindata
import (
"io"
"io/fs"
"os"
)
type GottyFS struct {
fs.FS
}
var Fs GottyFS
func (gfs *GottyFS) ReadFile(name string) ([]byte, error) {
fp, err := gfs.Open(name)
if err != nil {
return nil, err
}
return io.ReadAll(fp)
}
func init() {
Fs = GottyFS{os.DirFS("bindata")}
}

2876
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,8 @@
"ts-loader": "^8.3.0",
"typescript": "^4.3.2",
"webpack": "^5.72.0",
"webpack-cli": "^4.7.0"
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^4.11.1"
},
"dependencies": {
"@popperjs/core": "^2.11.5",

View File

@ -18,6 +18,7 @@
}
},
"exclude": [
"node_modules"
"node_modules",
"dist"
]
}

View File

@ -2,6 +2,14 @@ const path = require('path');
const TerserPlugin = require("terser-webpack-plugin");
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
var devtool;
if (process.env.DEV === '1') {
devtool = 'inline-source-map';
} else {
devtool = 'source-map';
}
module.exports = {
entry: "./src/main.ts",
entry: {
@ -10,7 +18,7 @@ module.exports = {
output: {
path: path.resolve(__dirname, '../bindata/static/js/'),
},
devtool: "source-map",
devtool: devtool,
resolve: {
extensions: [".ts", ".tsx", ".js"],
},

View File

@ -76,7 +76,12 @@ func (wt *WebTTY) Run(ctx context.Context) error {
errs <- func() error {
buffer := make([]byte, wt.bufferSize)
for {
n, err := wt.slave.Read(buffer)
//base64 length
effectiveBufferSize := wt.bufferSize - 1
//max raw data length
maxChunkSize := int(effectiveBufferSize/4) * 3
n, err := wt.slave.Read(buffer[:maxChunkSize])
if err != nil {
return ErrSlaveClosed
}