diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 000000000..7a4fb8677 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,34 @@ +on: + pull_request: + branches: + - dev + push: + branches: + - dev + +name: Build Test + +jobs: + build-linux-binary: + runs-on: ubuntu-latest + steps: + - name: Install cross-compilers for linux/arm64 + run: sudo apt-get update && sudo apt-get -y install gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + - name: Checkout code + uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '18.14' + - name: Build Web + id: build_frontend + run: | + cd frontend && npm install && npm run build:dev + env: + NODE_OPTIONS: --max-old-space-size=8192 + - uses: actions/setup-go@v4 + with: + go-version: '1.20.x' + - name: Build Server + uses: goreleaser/goreleaser-action@v4 + with: + args: release --snapshot --clean \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 000000000..1d1c45023 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,41 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Create Release And Upload assets + +jobs: + create-release: + runs-on: ubuntu-latest + steps: + - name: Install cross-compilers + run: sudo apt-get update && sudo apt-get -y install gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + - name: Checkout code + uses: actions/checkout@v2 + - uses: actions/setup-node@v3 + with: + node-version: '18.14' + - name: Build Web + run: | + cd frontend && npm install && npm run build:dev + env: + NODE_OPTIONS: --max-old-space-size=8192 + - uses: actions/setup-go@v4 + with: + go-version: '1.20.x' + - name: Build Release + uses: goreleaser/goreleaser-action@v4 + with: + args: release --skip-publish --clean + - name: Upload Assets + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + draft: true + files: | + dist/*.tar.gz + dist/checksums.txt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index f5abc8015..bafc512d0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,9 @@ cmd/server/web/assets cmd/server/web/monacoeditorwork cmd/server/web/index.html frontend/auto-imports.d.ts + +.history/ +dist/ +1pctl +1panel.service +install.sh \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 000000000..c85dc5e17 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,70 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # - export NODE_OPTIONS="--max-old-space-size=8192" + # - make build_web + - chmod +x ./script.sh + - ./script.sh + - sed -i 's@ORIGINAL_VERSION=.*@ORIGINAL_VERSION=v{{ .Version }}@g' 1pctl + - go mod tidy + +builds: + - main: ./cmd/server/main.go + binary: 1panel + flags: + - -trimpath + ldflags: + - -w -s + - --extldflags "-static -fpic" + tags: + - osusergo + env: + - CGO_ENABLED=1 + - >- + {{- if eq .Arch "amd64"}}CC=x86_64-linux-gnu-gcc{{- end }} + {{- if eq .Arch "arm64"}}CC=aarch64-linux-gnu-gcc{{- end }} + {{- if eq .Arch "loong64"}}CC=loongarch64-linux-gnu-gcc{{- end }} + {{- if eq .Arch "arm"}}CC=arm-linux-gnueabihf-gcc{{- end }} + goos: + - linux + goarch: + - amd64 + - arm64 + - arm + goarm: + - 6 + - 7 + ignore: + - goos: linux + goarch: arm + - goos: linux + goarch: loong64 + +archives: + - format: tar.gz + name_template: "{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{- if .Arm }}v{{ .Arm }}{{ end }}" + wrap_in_directory: true + files: + - 1pctl + - 1panel.service + - install.sh + - README.md + - LICENSE + +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +release: + draft: true + mode: append + extra_files: + - glob: dist/*.tar.gz + - glob: dist/checksums.txt + name_template: "Release {{.Tag}}" + +# The lines beneath this are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..af22c4dca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM node:18.14 as build_web +ARG TARGETARCH +ARG NPM_REGISTRY="https://registry.npmmirror.com" +ENV NODE_OPTIONS="--max-old-space-size=4096" + +WORKDIR /data + +RUN set -ex \ + && npm config set registry ${NPM_REGISTRY} + +ADD . /data + +RUN set -ex \ + && cd /data/frontend \ + && npm install + +RUN set -ex \ + && cd /data/frontend \ + && npm run build:dev + +FROM golang:1.20 +ARG TARGETARCH +ARG GOPROXY="https://goproxy.cn,direct" + +COPY --from=build_web /data /data + +WORKDIR /data + +RUN set -ex \ + && go env -w GOPROXY=${GOPROXY} \ + && go install github.com/goreleaser/goreleaser@latest \ + && goreleaser build --single-target --snapshot --clean + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/script.sh b/script.sh new file mode 100755 index 000000000..b6261f199 --- /dev/null +++ b/script.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +command -v wget >/dev/null || { + echo "wget not found, please install it and try again ." + exit 1 +} + +if [ ! -f "1pctl" ]; then + wget https://github.com/1Panel-dev/installer/raw/main/1pctl +fi + +if [ ! -f "1panel.service" ]; then + wget https://github.com/1Panel-dev/installer/raw/main/1panel.service +fi + +if [ ! -f "install.sh" ]; then + wget https://github.com/1Panel-dev/installer/raw/main/install.sh +fi + +chmod 755 1pctl install.sh \ No newline at end of file