Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to GoReleaser

Intro to GoReleaser

Go Community Monthly @ Schwarz

Carlos Alexandro Becker

October 22, 2021
Tweet

More Decks by Carlos Alexandro Becker

Other Decks in Programming

Transcript

  1. Intro to GoReleaser 1 — Go Community Monthly @ Schwarz

    - October, 2021 - carlosbecker.dev/talks/
  2. 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/
  3. 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/
  4. 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/
  5. 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/
  6. 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/
  7. 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/
  8. 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/
  9. Let's see it in practice! 9 — Go Community Monthly

    @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  10. 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/
  11. Creating a project 12 — Go Community Monthly @ Schwarz

    - October, 2021 - carlosbecker.dev/talks/
  12. 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/
  13. 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/
  14. 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/
  15. 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/
  16. Better changelog 17 — Go Community Monthly @ Schwarz -

    October, 2021 - carlosbecker.dev/talks/
  17. Better changelog changelog: use: github sort: asc filters: exclude: -

    '^docs:' - '^test:' 18 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  18. 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/
  19. Go Mod Proxy 20 — Go Community Monthly @ Schwarz

    - October, 2021 - carlosbecker.dev/talks/
  20. 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/
  21. 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/
  22. Go Mod Proxy Let's try it out first: go run

    . 23 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  23. 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/
  24. Universal macOS Binaries 25 — Go Community Monthly @ Schwarz

    - October, 2021 - carlosbecker.dev/talks/
  25. Universal macOS Binaries Just need a simple config change: #

    ... universal_binaries: - replace: true # ... 26 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  26. 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/
  27. Linux Packages 28 — Go Community Monthly @ Schwarz -

    October, 2021 - carlosbecker.dev/talks/
  28. Linux Packages Minimal config: # ... nfpms: - formats: [deb,

    apk, rpm] # ... 29 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  29. 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/
  30. 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/
  31. Docker images 32 — Go Community Monthly @ Schwarz -

    October, 2021 - carlosbecker.dev/talks/
  32. Docker images Minimal config: # ... dockers: - image_templates: -

    caarlos0/{{ .ProjectName }}:{{ .Tag }} - caarlos0/{{ .ProjectName }}:latest # ... 33 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  33. 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/
  34. 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/
  35. Docker images Test it: docker run --rm caarlos0/example-schwarz 36 —

    Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  36. Signing with cosign 37 — Go Community Monthly @ Schwarz

    - October, 2021 - carlosbecker.dev/talks/
  37. 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/
  38. 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/
  39. 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/
  40. 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/
  41. 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/
  42. 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/
  43. Contributing: donate → Sponsor @caarlos0 on GitHub → GoReleaser OpenCollective

    → https://goreleaser.com/sponsors 46 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  44. 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/
  45. Learning more 48 — Go Community Monthly @ Schwarz -

    October, 2021 - carlosbecker.dev/talks/
  46. Learning more The website has a lot of documentation, examples,

    and cookbooks → goreleaser.com 49 — Go Community Monthly @ Schwarz - October, 2021 - carlosbecker.dev/talks/
  47. 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/
  48. 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/