From d00f7763f4fa34c51e9cc6e39987dbcc18d1b471 Mon Sep 17 00:00:00 2001 From: Filipe Pina Date: Sun, 11 Dec 2022 02:01:43 +0000 Subject: [PATCH 1/2] release with github actions (and arm builds) --- .github/workflows/release.yml | 40 ++++++++++++++++++++++++ .gitignore | 1 + .goreleaser.yml | 57 +++++++++++++++++++++++++++++++++++ Dockerfile | 5 +++ Dockerfile.release | 12 ++++++++ Makefile | 15 +++++++++ 6 files changed, 130 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile.release create mode 100644 Makefile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7519388 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +name: goreleaser + +on: + push: + branches-ignore: + - '**' + tags: + - '*.*.*' + - '*.*.*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 1120626..575d167 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ smtp_to_telegram +dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..1307738 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,57 @@ +project_name: smtp_to_telegram + +release: + prerelease: auto + +builds: + - id: smtp_to_telegram + env: + - CGO_ENABLED=0 + goos: + - windows + - darwin + - linux + goarch: + - amd64 + - arm64 + - arm + goarm: + - '7' + ldflags: + - -s -w -X main.Version={{.Version}} + +snapshot: + name_template: "{{ .Tag }}-next" + +dockers: + - &xdocker + image_templates: + - kostyaesmukov/{{ .ProjectName }}:{{ .Version }}-amd64 + dockerfile: Dockerfile.release + use: buildx + goos: linux + goarch: amd64 + build_flag_templates: + - --platform=linux/amd64 + + - <<: *xdocker + image_templates: + - kostyaesmukov/{{ .ProjectName }}:{{ .Version }}-arm64 + goarch: arm64 + build_flag_templates: + - --platform=linux/arm64/v8 + + - <<: *xdocker + image_templates: + - kostyaesmukov/{{ .ProjectName }}:{{ .Version }}-armv7 + goarch: arm + goarm: 7 + build_flag_templates: + - --platform=linux/arm/v7 + +docker_manifests: + - name_template: kostyaesmukov/{{ .ProjectName }}:latest + image_templates: + - kostyaesmukov/{{ .ProjectName }}:{{ .Version }}-amd64 + - kostyaesmukov/{{ .ProjectName }}:{{ .Version }}-arm64 + - kostyaesmukov/{{ .ProjectName }}:{{ .Version }}-armv7 diff --git a/Dockerfile b/Dockerfile index 8e60f10..05e8350 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,11 @@ RUN apk add --no-cache git ca-certificates mailcap WORKDIR /app +COPY go.mod . +COPY go.sum . + +RUN go mod download + COPY . . # The image should be built with diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000..2bb3910 --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,12 @@ +FROM alpine:3.16 + +RUN apk add --no-cache ca-certificates mailcap + +COPY smtp_to_telegram /smtp_to_telegram + +USER daemon + +ENV ST_SMTP_LISTEN="0.0.0.0:2525" +EXPOSE 2525 + +ENTRYPOINT ["/smtp_to_telegram"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..695293d --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +GOLANG_CROSS_VERSION ?= v1.18.1 + +test-release: + @docker run \ + --rm \ + --privileged \ + -v ${PWD}:/smtp_to_telegram \ + -w /smtp_to_telegram \ + -e GITHUB_TOKEN \ + -e DOCKER_USERNAME \ + -e DOCKER_PASSWORD \ + -e DOCKER_REGISTRY \ + -v /var/run/docker.sock:/var/run/docker.sock \ + goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ + --rm-dist --skip-validate --timeout=1h --snapshot From a393c92df9585edbf56189dd5741857f7c679c19 Mon Sep 17 00:00:00 2001 From: Filipe Pina Date: Tue, 13 Dec 2022 10:19:40 +0000 Subject: [PATCH 2/2] add build tag `urfave_cli_no_docs` stripping about 300kb from binary --- .goreleaser.yml | 2 ++ Dockerfile | 1 + 2 files changed, 3 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 1307738..9677ef7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -19,6 +19,8 @@ builds: - '7' ldflags: - -s -w -X main.Version={{.Version}} + tags: + - urfave_cli_no_docs snapshot: name_template: "{{ .Tag }}-next" diff --git a/Dockerfile b/Dockerfile index 05e8350..bddac24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ ARG GOPROXY=direct RUN CGO_ENABLED=0 GOOS=linux go build \ -ldflags "-s -w \ -X main.Version=${ST_VERSION:-UNKNOWN_RELEASE}" \ + -tags urfave_cli_no_docs \ -a -o smtp_to_telegram