diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b2dfe19 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/logo.png b/.github/logo.png new file mode 100644 index 0000000..136cb4c Binary files /dev/null and b/.github/logo.png differ diff --git a/.github/workflows/CodeQL.yaml b/.github/workflows/CodeQL.yaml new file mode 100644 index 0000000..3bd3ea4 --- /dev/null +++ b/.github/workflows/CodeQL.yaml @@ -0,0 +1,39 @@ +name: "CodeQL" + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + schedule: + - cron: "0 0 * * *" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["go"] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..62e7306 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,55 @@ +name: Release CAN-Bridge + +on: + workflow_dispatch: + push: + branches: + - "main" + tags: + - "*.*.*" + +env: + GO_VERSION: "1.24" + GO111MODULE: on + +permissions: + contents: write + id-token: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + if: success() && startsWith(github.ref, 'refs/tags/') + with: + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_USERNAME: ${{ github.repository_owner }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..74daf47 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,109 @@ +version: 2 + +project_name: dashboard-server + +before: + hooks: + - go mod tidy + +builds: + - id: dashboard-server + goos: + - linux + goarch: + - amd64 + - arm64 + - arm + goarm: + - "6" + - "7" + ldflags: + - -s -w + +archives: + - formats: ["tar.gz"] + files: + - static + - README.md + - README_CN.md + - LICENSE + +release: + draft: false + +dockers: + - image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-amd64" + dockerfile: Dockerfile.goreleaser + use: buildx + build_flag_templates: + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + goos: linux + goarch: amd64 + extra_files: + - static + + - image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-arm64" + dockerfile: Dockerfile.goreleaser + use: buildx + build_flag_templates: + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + goos: linux + goarch: arm64 + + - image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv6" + dockerfile: Dockerfile.goreleaser + use: buildx + build_flag_templates: + - "--platform=linux/arm/v6" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + goos: linux + goarch: arm + goarm: "6" + + - image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv7" + dockerfile: Dockerfile.goreleaser + use: buildx + build_flag_templates: + - "--platform=linux/arm/v7" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + goos: linux + goarch: arm + goarm: "7" + +docker_manifests: + - name_template: "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}" + image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-amd64" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-arm64" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv6" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv7" + - name_template: "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:latest" + image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-amd64" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-arm64" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv6" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv7" + - name_template: "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:v{{ .Major }}" + image_templates: + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-amd64" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-arm64" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv6" + - "ghcr.io/{{ .Env.GITHUB_USERNAME }}/dashboard-server:{{ .Tag }}-armv7" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9537283 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# ---- Build Stage ---- +FROM golang:1.24-alpine AS builder + +WORKDIR /app + +COPY --link go.mod go.sum ./ +RUN go mod download + +COPY --link . . + +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o dashboard-server . + +# ---- Runtime Stage ---- +FROM alpine:3.21 + +WORKDIR /app + +COPY --link static/ ./static/ + +COPY --link --from=builder /app/dashboard-server /usr/local/bin/dashboard-server + +EXPOSE 9099 + +ENV SERVER_PORT="9099" + +CMD ["dashboard-server"] \ No newline at end of file diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..fcf31a5 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,10 @@ +FROM alpine:3.21 + +COPY --link dashboard-server /usr/local/bin/dashboard-server +COPY --link static/ ./static/ + +EXPOSE 9099 + +ENV SERVER_PORT="9099" + +ENTRYPOINT ["dashboard-server"]