Share
Embed
Transcript
53 slides
-
Intro to GoReleaser 1 — Go Community Monthly @ Schwarz
- October, 2021 - carlosbecker.dev/talks/ -
Who am I? → SRE @ totvslabs → @caarlos0 almost
everywhere → carlosbecker.dev/talks/ → goreleaser.com → nfpm.goreleaser.com 2 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
What is GoReleaser? → an automation tool to build and
release Go projects → setup via a yaml file once → release anytime with git tag + goreleaser release 3 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
What can it do? → Build a matrix of GOOS,
GOARCH, GOARM, etc → Build macOS universal binaries → Create archives for each platform 4 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
What can it do? → Create Linux packages: deb, rpm,
apk, snap → Create Homebrew taps, Gofish rigs and Scoop buckets → Create and sign Docker images and manifests 5 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
What can it do? → Create checksum files → Sign
release files and checksums → Upload files to Artifactory, Fury, blob storage, and basically anything that accepts a PUT request 6 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
What can it do? → Create a release on GitHub/GitLab/Gitea
and upload artifacts there → Run custom publishers (aka shell scripts) → Announce new releases to several places 7 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
What can it do? All integrated with your favorite CI:
GitHub Actions, Azure Pipelines, CircleCI, Google CloudBuild, GitLab CI and many others... Full list: goreleaser.com/ci 8 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Let's see it in practice! 9 — Go Community Monthly
@ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
<demo> 10 — Go Community Monthly @ Schwarz - October,
2021 - carlosbecker.dev/talks/ -
What will we cover? → Initial project setup → Changelog
→ Go mod proxying → Universal macOS binaries → Linux packaging → Docker images → Signing with cosign 11 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Creating a project 12 — Go Community Monthly @ Schwarz
- October, 2021 - carlosbecker.dev/talks/ -
Creating a project First, lets create a new GitHub project:
mkdir example-schwarz cd example-schwarz git init gh repo create caarlos0/example-schwarz -y -l MIT git pull origin main 13 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Creating a project Next step is to make it a
Go project: go mod init github.com/caarlos0/example-schwarz With a main.go file like this: package main import ( "fmt" ) func main() { fmt.Println("hello golang community") } 14 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Creating a project Next step: create and verify a .goreleaser.yml
file: goreleaser -h goreleaser init goreleaser check goreleaser release -h goreleaser release --rm-dist --snapshot 15 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Creating a project Finally, lets try a real release: git
add -A git commit -am 'feat: first commit' git tag v1.0.0 git push origin HEAD --tags goreleaser release --rm-dist gh release view v1.0.0 -w 16 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Better changelog 17 — Go Community Monthly @ Schwarz -
October, 2021 - carlosbecker.dev/talks/ -
Better changelog changelog: use: github sort: asc filters: exclude: -
'^docs:' - '^test:' 18 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Better changelog Let's release to check it out: git commit
-am 'ci: changelog' git tag `svu n --force-patch-increment` git push origin HEAD --tags goreleaser release --rm-dist ./dist/example-schwarz_darwin_amd64/example-schwarz 19 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Go Mod Proxy 20 — Go Community Monthly @ Schwarz
- October, 2021 - carlosbecker.dev/talks/ -
Go Mod Proxy First, lets enable the feature on .goreleaser.yml:
# ... gomod: proxy: true env: - GOPRIVATE=github.com/caarlos0 # ... 21 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Go Mod Proxy Then, lets use it on our main.go:
package main import ( "fmt" "runtime/debug" ) func main() { fmt.Println("hello golang community") if info, ok := debug.ReadBuildInfo(); ok { fmt.Println(info.Main.Path, info.Main.Version, info.Main.Sum) } } 22 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Go Mod Proxy Let's try it out first: go run
. 23 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Go Mod Proxy Let's release it: git commit -am 'ci:
go mod proxy' git tag `svu n --force-patch-increment` git push origin HEAD --tags goreleaser release --rm-dist ./dist/example-schwarz_darwin_amd64/example-schwarz 24 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Universal macOS Binaries 25 — Go Community Monthly @ Schwarz
- October, 2021 - carlosbecker.dev/talks/ -
Universal macOS Binaries Just need a simple config change: #
... universal_binaries: - replace: true # ... 26 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Universal macOS Binaries And then we can release it again:
git commit -am 'ci: universal binaries' git tag `svu n --force-patch-increment` git push origin HEAD --tags goreleaser release --rm-dist ./dist/example-schwarz_darwin_all/example-schwarz 27 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Linux Packages 28 — Go Community Monthly @ Schwarz -
October, 2021 - carlosbecker.dev/talks/ -
Linux Packages Minimal config: # ... nfpms: - formats: [deb,
apk, rpm] # ... 29 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Linux Packages Then we just need to release them: git
commit -am 'ci: nfpm packages' git tag `svu n --force-patch-increment` git push origin HEAD --tags goreleaser release --rm-dist tree dist 30 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Linux Packages Let's test! docker run --rm -v $PWD/dist:/tmp/ alpine
sh -c \ 'apk add -q --allow-untrusted /tmp/*_amd64.apk && example-schwarz' docker run --rm -v $PWD/dist:/tmp/ ubuntu sh -c \ 'dpkg -i /tmp/*_amd64.deb && example-schwarz' docker run --rm -v $PWD/dist:/tmp/ fedora sh -c \ 'rpm -i /tmp/*_amd64.rpm && example-schwarz' 31 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Docker images 32 — Go Community Monthly @ Schwarz -
October, 2021 - carlosbecker.dev/talks/ -
Docker images Minimal config: # ... dockers: - image_templates: -
caarlos0/{{ .ProjectName }}:{{ .Tag }} - caarlos0/{{ .ProjectName }}:latest # ... 33 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Docker images A simple Dockerfile: FROM alpine COPY *.apk /tmp/
RUN apk add --allow-untrusted /tmp/*.apk ENTRYPOINT ["/usr/local/bin/example-schwarz"] 34 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Docker images Release: git add -A git commit -am 'ci:
docker imgs' git tag `svu n --force-patch-increment` git push origin HEAD --tags goreleaser release --rm-dist 35 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Docker images Test it: docker run --rm caarlos0/example-schwarz 36 —
Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Signing with cosign 37 — Go Community Monthly @ Schwarz
- October, 2021 - carlosbecker.dev/talks/ -
Signing with cosign Cosign is a new simpler way to
sign files, and specially, Docker images and manifests. cosign generate-key-pair 38 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Signing with cosign # ... signs: - artifacts: checksum stdin:
'{{ .Env.COSIGN_PWD }}' cmd: cosign args: ["sign-blob", "-key=cosign.key", "-output=${signature}", "${artifact}"] docker_signs: - artifacts: images stdin: '{{ .Env.COSIGN_PWD }}' # ... 39 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Signing with cosign Let's release! git add -A git commit
-am 'ci: sign' git tag `svu n --force-patch-increment` git push origin HEAD --tags COSIGN_PWD=asd goreleaser release --rm-dist 40 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Signing with cosign Now we can verify the signature and
checksum with cosign and sha256sum: cosign verify-blob -key cosign.pub \ -signature dist/checksums.txt.sig \ dist/checksums.txt cd dist; sha256sum --ignore-missing -c checksums.txt; cd - 41 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Signing with cosign Let's verify our Docker image as well:
cosign verify -key cosign.pub \ caarlos0/example-schwarz:latest 42 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
</demo> 43 — Go Community Monthly @ Schwarz - October,
2021 - carlosbecker.dev/talks/ -
Contributing 44 — Go Community Monthly @ Schwarz - October,
2021 - carlosbecker.dev/talks/ -
Contributing: code → There are always issues to fix, PRs
to review and questions to answer → All help is welcome → https://github.com/goreleaser 45 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Contributing: donate → Sponsor @caarlos0 on GitHub → GoReleaser OpenCollective
→ https://goreleaser.com/sponsors 46 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Contributing: pro license → nightly builds → prebuilt builder →
config reuse (aka includes) → monorepo support → and more! goreleaser.com/pro 47 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Learning more 48 — Go Community Monthly @ Schwarz -
October, 2021 - carlosbecker.dev/talks/ -
Learning more The website has a lot of documentation, examples,
and cookbooks → goreleaser.com 49 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Learning more I occasionally highlight new features et al at
on my blog → carlosbecker.dev 50 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
Learning more If you want only the Linux packaging stuff,
you might be interested in nFPM → nfpm.goreleaser.com 51 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/ -
52 — Go Community Monthly @ Schwarz - October, 2021
- carlosbecker.dev/talks/ -
Thanks! 53 — Go Community Monthly @ Schwarz - October,
2021 - carlosbecker.dev/talks/