diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml.bak similarity index 100% rename from .github/workflows/docker-publish.yml rename to .github/workflows/docker-publish.yml.bak diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index eae2ea19..0ae54f8f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -4,7 +4,6 @@ on: push: branches: [ master ] pull_request: - types: [assigned, opened, synchronize, reopened] jobs: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml.bak similarity index 97% rename from .github/workflows/golangci-lint.yml rename to .github/workflows/golangci-lint.yml.bak index f0e5165e..5eba7a5e 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml.bak @@ -1,8 +1,6 @@ name: golangci-lint on: push: - tags: - - v* branches: - master pull_request: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..d6205758 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,69 @@ +name: Release + +on: + push: + branches: [ master ] + release: + types: [ released ] + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.workflow_run.head_sha }} + fetch-depth: 0 + submodules: 'recursive' + + - uses: dotnet/nbgv@master + with: + setAllVars: true + + - run: git tag v$NBGV_SimpleVersion || true + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry docker hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Go 1.x + uses: actions/setup-go@v4 + with: + go-version: 'stable' + cache: true + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SKIP_PUSH: ${{ github.event_name != 'release' }} + GORELEASER_CURRENT_TAG: v${{ env.NBGV_SimpleVersion }} + + - run: gh release list | grep Draft | tail -n +3 | cut -f 1 | xargs -r -L 1 gh release delete --yes diff --git a/.github/workflows/go.yml b/.github/workflows/test.yml similarity index 57% rename from .github/workflows/go.yml rename to .github/workflows/test.yml index cfb47ac6..b7039257 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/test.yml @@ -4,18 +4,19 @@ on: push: branches: [ master ] pull_request: - types: [assigned, opened, synchronize, reopened] + +permissions: + contents: read jobs: - build: + test-and-lint: name: Build runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory uses: actions/checkout@v3 with: - fetch-depth: 0 submodules: 'recursive' - name: Set up Go 1.x @@ -24,10 +25,6 @@ jobs: go-version: 'stable' cache: true - - uses: dotnet/nbgv@master - with: - setAllVars: true - - name: Test lib ssh run: go test -v -cover ./... working-directory: crypto/ssh @@ -35,10 +32,9 @@ jobs: - name: Test sshpiper run: go test -v -race -cover -tags full ./... - - name: create release + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout=60m -E gofmt --verbose --print-resources-usage --build-tags full env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: github.ref == 'refs/heads/master' - run: | - gh release create -d --generate-notes v$NBGV_SimpleVersion - gh release list | grep Draft | tail -n +3 | cut -f 1 | xargs -r -L 1 gh release delete --yes + GOGC: "10" \ No newline at end of file diff --git a/.gitignore b/.gitignore index b8c2a573..b0c6529b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ vendor/ # Go workspace file go.work + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..21f31329 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,220 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy +builds: + - id: sshpiperd + env: + - CGO_ENABLED=0 + goos: + - linux + # - windows + # - darwin + goarch: + - amd64 + - arm64 + main: ./cmd/sshpiperd + binary: sshpiperd + ldflags: + - -X main.mainver={{.Version}} + - id: plugin_workingdir + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # - windows + # - darwin + main: ./plugin/workingdir + binary: plugins/workingdir + tags: + - full + - id: plugin_yaml + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # - windows + # - darwin + main: ./plugin/yaml + binary: plugins/yaml + tags: + - full + - id: plugin_docker + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # - windows + # - darwin + main: ./plugin/docker + binary: plugins/docker + tags: + - full + - id: plugin_kubernetes + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # - windows + # - darwin + main: ./plugin/kubernetes + binary: plugins/kubernetes + tags: + - full + - id: plugin_fixed + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # - windows + # - darwin + main: ./plugin/fixed + binary: plugins/fixed + tags: + - full + - id: plugin_failtoban + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # - windows + # - darwin + main: ./plugin/failtoban + binary: plugins/failtoban + tags: + - full + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + sshpiperd_with_plugins_ + {{- .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + # builds: + # - sshpiperd + # - plugin_workingdir +dockers: + - image_templates: + - "farmer1992/sshpiperd:{{ .Version }}-amd64" + - "ghcr.io/tg123/sshpiperd:{{ .Version }}-amd64" + use: buildx + ids: + - sshpiperd + - plugin_kubernetes + - plugin_workingdir + dockerfile: Dockerfile + build_flag_templates: + - "--platform=linux/amd64" + - "--build-arg=EXTERNAL=1" + extra_files: + - entrypoint.sh + skip_push: "{{ .Env.SKIP_PUSH }}" + - image_templates: + - "farmer1992/sshpiperd:{{ .Version }}-arm64" + - "ghcr.io/tg123/sshpiperd:{{ .Version }}-arm64" + use: buildx + ids: + - sshpiperd + - plugin_kubernetes + - plugin_workingdir + goarch: arm64 + dockerfile: Dockerfile + build_flag_templates: + - "--platform=linux/arm64" + - "--build-arg=EXTERNAL=1" + extra_files: + - entrypoint.sh + skip_push: "{{ .Env.SKIP_PUSH }}" + # full + - image_templates: + - "farmer1992/sshpiperd:full-{{ .Version }}-amd64" + - "ghcr.io/tg123/sshpiperd:full-{{ .Version }}-amd64" + use: buildx + dockerfile: Dockerfile + build_flag_templates: + - "--platform=linux/amd64" + - "--build-arg=EXTERNAL=1" + extra_files: + - entrypoint.sh + skip_push: "{{ .Env.SKIP_PUSH }}" + - image_templates: + - "farmer1992/sshpiperd:full-{{ .Version }}-arm64" + - "ghcr.io/tg123/sshpiperd:full-{{ .Version }}-arm64" + use: buildx + goarch: arm64 + dockerfile: Dockerfile + build_flag_templates: + - "--platform=linux/arm64" + - "--build-arg=EXTERNAL=1" + extra_files: + - entrypoint.sh + skip_push: "{{ .Env.SKIP_PUSH }}" +docker_manifests: + - name_template: "farmer1992/sshpiperd:{{ .Version }}" + image_templates: + - "farmer1992/sshpiperd:{{ .Version }}-amd64" + - "farmer1992/sshpiperd:{{ .Version }}-arm64" + skip_push: "{{ .Env.SKIP_PUSH }}" + - name_template: "farmer1992/sshpiperd:latest" + image_templates: + - "farmer1992/sshpiperd:{{ .Version }}-amd64" + - "farmer1992/sshpiperd:{{ .Version }}-arm64" + skip_push: "{{ .Env.SKIP_PUSH }}" + - name_template: "ghcr.io/tg123/sshpiperd:latest" + image_templates: + - "ghcr.io/tg123/sshpiperd:{{ .Version }}-amd64" + - "ghcr.io/tg123/sshpiperd:{{ .Version }}-arm64" + skip_push: "{{ .Env.SKIP_PUSH }}" + - name_template: "ghcr.io/tg123/sshpiperd:{{ .Version }}" + image_templates: + - "ghcr.io/tg123/sshpiperd:{{ .Version }}-amd64" + - "ghcr.io/tg123/sshpiperd:{{ .Version }}-arm64" + skip_push: "{{ .Env.SKIP_PUSH }}" + # full + - name_template: "farmer1992/sshpiperd:full-{{ .Version }}" + image_templates: + - "farmer1992/sshpiperd:full-{{ .Version }}-amd64" + - "farmer1992/sshpiperd:full-{{ .Version }}-arm64" + skip_push: "{{ .Env.SKIP_PUSH }}" + - name_template: "ghcr.io/tg123/sshpiperd:full-{{ .Version }}" + image_templates: + - "ghcr.io/tg123/sshpiperd:full-{{ .Version }}-amd64" + - "ghcr.io/tg123/sshpiperd:full-{{ .Version }}-arm64" + skip_push: "{{ .Env.SKIP_PUSH }}" +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}" + +release: + draft: true + replace_existing_draft: true + diff --git a/Dockerfile b/Dockerfile index bec8243d..a5ed8539 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,14 @@ FROM golang:1.20-bullseye as builder ARG VER=devel ARG BUILDTAGS="" +ARG EXTERNAL="0" ENV CGO_ENABLED=0 RUN mkdir -p /sshpiperd/plugins WORKDIR /src -RUN --mount=target=/src,type=bind,source=. --mount=type=cache,target=/root/.cache/go-build go build -o /sshpiperd -ldflags "-X main.mainver=$VER" ./cmd/... -RUN --mount=target=/src,type=bind,source=. --mount=type=cache,target=/root/.cache/go-build go build -o /sshpiperd/plugins -tags "$BUILDTAGS" ./plugin/... +RUN --mount=target=/src,type=bind,source=. --mount=type=cache,target=/root/.cache/go-build if [ "$EXTERNAL" = "1" ]; then cp sshpiperd /sshpiperd; else go build -o /sshpiperd -ldflags "-X main.mainver=$VER" ./cmd/... ; fi +RUN --mount=target=/src,type=bind,source=. --mount=type=cache,target=/root/.cache/go-build if [ "$EXTERNAL" = "1" ]; then cp * /sshpiperd/plugins; rm /sshpiperd/plugins/Dockerfile; rm /sshpiperd/plugins/entrypoint.sh; rm /sshpiperd/plugins/sshpiperd ; else go build -o /sshpiperd/plugins -tags "$BUILDTAGS" ./plugin/...; fi ADD entrypoint.sh /sshpiperd FROM busybox