init goreleaser (#169)

* init goreleaser

add dockerfile

add fetch tag

set next to snapshot

remove generate

skip val

add auto ver

revert ver

revert ver

force tag

* self tag

* self tag

* always tag

* change perm

* final
This commit is contained in:
Boshi Lian 2023-08-02 02:40:04 -07:00 committed by GitHub
parent 3a8de2746e
commit fefbb0ec99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 303 additions and 18 deletions

View file

@ -4,7 +4,6 @@ on:
push: push:
branches: [ master ] branches: [ master ]
pull_request: pull_request:
types: [assigned, opened, synchronize, reopened]
jobs: jobs:

View file

@ -1,8 +1,6 @@
name: golangci-lint name: golangci-lint
on: on:
push: push:
tags:
- v*
branches: branches:
- master - master
pull_request: pull_request:

69
.github/workflows/release.yaml vendored Normal file
View file

@ -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

View file

@ -4,18 +4,19 @@ on:
push: push:
branches: [ master ] branches: [ master ]
pull_request: pull_request:
types: [assigned, opened, synchronize, reopened]
permissions:
contents: read
jobs: jobs:
build: test-and-lint:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
fetch-depth: 0
submodules: 'recursive' submodules: 'recursive'
- name: Set up Go 1.x - name: Set up Go 1.x
@ -24,10 +25,6 @@ jobs:
go-version: 'stable' go-version: 'stable'
cache: true cache: true
- uses: dotnet/nbgv@master
with:
setAllVars: true
- name: Test lib ssh - name: Test lib ssh
run: go test -v -cover ./... run: go test -v -cover ./...
working-directory: crypto/ssh working-directory: crypto/ssh
@ -35,10 +32,9 @@ jobs:
- name: Test sshpiper - name: Test sshpiper
run: go test -v -race -cover -tags full ./... 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: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GOGC: "10"
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

2
.gitignore vendored
View file

@ -19,3 +19,5 @@ vendor/
# Go workspace file # Go workspace file
go.work go.work
dist/

220
.goreleaser.yaml Normal file
View file

@ -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

View file

@ -2,13 +2,14 @@ FROM golang:1.20-bullseye as builder
ARG VER=devel ARG VER=devel
ARG BUILDTAGS="" ARG BUILDTAGS=""
ARG EXTERNAL="0"
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
RUN mkdir -p /sshpiperd/plugins RUN mkdir -p /sshpiperd/plugins
WORKDIR /src 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 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 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/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 ADD entrypoint.sh /sshpiperd
FROM busybox FROM busybox