From e5daf06d24dc8c1d5fe5f31c61231c0e341f13f8 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Fri, 27 Aug 2021 11:18:43 +0200 Subject: [PATCH] Automate release with Github actions The current process according the README is manual. It requires to have access users to DockerHub. After small investigation, found that DockerHub is not actively internaly used and decided to switch container registry to Github. The relase part was done with [goreleaser](https://github.com/goreleaser/goreleaser). It can create Release in Github, Container registries and Homebrew. Update documentation to use Github container registry for new versions. --- .github/workflows/go.yml | 36 ------------------------ .github/workflows/release.yml | 47 +++++++++++++++++++++++++++++++ .github/workflows/test.yml | 53 +++++++++++++++++++++++++++++++++++ .goreleaser.yml | 29 +++++++++---------- README.md | 28 ++++++++---------- 5 files changed, 125 insertions(+), 68 deletions(-) delete mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 9e760bfd..00000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - runs-on: ubuntu-latest - strategy: - matrix: - go: [ '1.17', '1.16', '1.15', '1.14' ] - name: ${{ matrix.go }} - steps: - - uses: actions/checkout@v2 - - - - name: Setup go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} - - - - name: Test - run: make test - - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - with: - distribution: goreleaser - version: latest - args: build --snapshot --rm-dist --skip-post-hooks --skip-validate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..25e83641 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: Release + +on: + push: + tags: [ 'v*.*.*' ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - + name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - + name: Release + uses: goreleaser/goreleaser-action@5a54d7e660bda43b405e8463261b3d25631ffe86 + with: + distribution: goreleaser + version: v0.176.0 + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..46a7e435 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,53 @@ +name: Test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + go: [ '1.17', '1.16', '1.15', '1.14' ] + name: Go ${{ matrix.go }} + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - + name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - + name: Tests + run: make test + + build: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - + name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - + name: Build + uses: goreleaser/goreleaser-action@5a54d7e660bda43b405e8463261b3d25631ffe86 + with: + distribution: goreleaser + version: v0.176.0 + args: build --snapshot --rm-dist --skip-post-hooks --skip-validate diff --git a/.goreleaser.yml b/.goreleaser.yml index 528e3543..0f8ae239 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,5 @@ +project_name: toxiproxy + # This is an example .goreleaser.yml file with some sane defaults. # Make sure to check the documentation at http://goreleaser.com env: @@ -68,7 +70,6 @@ nfpms: dockers: - &docker use: buildx - skip_push: true dockerfile: Dockerfile ids: - server @@ -76,9 +77,9 @@ dockers: goos: linux goarch: amd64 image_templates: - - shopify/toxiproxy:{{ .Version }}-amd64 - - shopify/toxiproxy:v{{ .Major }}-amd64 - - shopify/toxiproxy:v{{ .Major }}.{{ .Minor }}-amd64 + - ghcr.io/shopify/toxiproxy:{{ .Version }}-amd64 + - ghcr.io/shopify/toxiproxy:v{{ .Major }}-amd64 + - ghcr.io/shopify/toxiproxy:v{{ .Major }}.{{ .Minor }}-amd64 build_flag_templates: - --platform=linux/amd64 - --no-cache @@ -93,9 +94,9 @@ dockers: - <<: *docker goarch: arm64 image_templates: - - shopify/toxiproxy:{{ .Version }}-arm64 - - shopify/toxiproxy:v{{ .Major }}-arm64 - - shopify/toxiproxy:v{{ .Major }}.{{ .Minor }}-arm64 + - ghcr.io/shopify/toxiproxy:{{ .Version }}-arm64 + - ghcr.io/shopify/toxiproxy:v{{ .Major }}-arm64 + - ghcr.io/shopify/toxiproxy:v{{ .Major }}.{{ .Minor }}-arm64 build_flag_templates: - --platform=linux/arm64/v8 - --no-cache @@ -110,17 +111,15 @@ dockers: docker_manifests: - - skip_push: true - name_template: shopify/{{ .ProjectName }}:{{ .Version }} + name_template: ghcr.io/shopify/{{ .ProjectName }}:{{ .Version }} image_templates: - - shopify/{{ .ProjectName }}:{{ .Version }}-amd64 - - shopify/{{ .ProjectName }}:{{ .Version }}-arm64 + - ghcr.io/shopify/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/shopify/{{ .ProjectName }}:{{ .Version }}-arm64 - - skip_push: true - name_template: shopify/{{ .ProjectName }}:latest + name_template: ghcr.io/shopify/{{ .ProjectName }}:latest image_templates: - - shopify/{{ .ProjectName }}:{{ .Version }}-amd64 - - shopify/{{ .ProjectName }}:{{ .Version }}-arm64 + - ghcr.io/shopify/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/shopify/{{ .ProjectName }}:{{ .Version }}-arm64 changelog: sort: asc diff --git a/README.md b/README.md index c8bd83b2..c4d20885 100644 --- a/README.md +++ b/README.md @@ -228,11 +228,12 @@ Toxiproxy for Windows is available for download at https://github.com/Shopify/to **Docker** -Toxiproxy is available on [Docker Hub](https://hub.docker.com/r/shopify/toxiproxy/). +Toxiproxy is available on [Github container registry](https://github.com/Shopify/toxiproxy/pkgs/container/toxiproxy). +Old versions `<= 2.1.4` are available on on [Docker Hub](https://hub.docker.com/r/shopify/toxiproxy/). ```bash -$ docker pull shopify/toxiproxy -$ docker run -it shopify/toxiproxy +$ docker pull ghcr.io/shopify/toxiproxy +$ docker run -it ghcr.io/shopify/toxiproxy ``` If using Toxiproxy from the host rather than other containers, enable host networking with `--net=host`. @@ -579,25 +580,18 @@ For example, `shopify_test_redis_master` or `shopify_development_mysql_1`. * `make`. Build a toxiproxy development binary for the current platform. * `make all`. Build Toxiproxy binaries and packages for all platforms. Requires to have Go compiled with cross compilation enabled on Linux and Darwin (amd64) - as well as [`fpm`](https://github.com/jordansissel/fpm) in your `$PATH` to - build the Debian package. + as well as [`goreleaser`](https://goreleaser.com/) in your `$PATH` to + build binaries the Linux package. * `make test`. Run the Toxiproxy tests. -* `make darwin`. Build binary for Darwin. -* `make linux`. Build binary for Linux. -* `make windows`. Build binary for Windows. ### Release 1. Ensure this release has run internally for `Shopify/shopify` for at least a day which is the best fuzzy test for robustness we have. -2. Update `CHANGELOG.md` -3. Bump `VERSION` -4. Change versions in `README.md` -5. Commit -6. Tag -7. `make release` to create binaries, packages and push new Docker image -8. Create [Github draft release](https://github.com/Shopify/toxiproxy/releases/new) against new tag and upload binaries and Debian package -9. [Bump version for Homebrew](https://github.com/Shopify/homebrew-shopify/blob/master/toxiproxy.rb#L9) - +1. Update `CHANGELOG.md` +1. Bump `VERSION` +1. Change versions in `README.md` +1. Commit, Tag, and Push +1. [Bump version for Homebrew](https://github.com/Shopify/homebrew-shopify/blob/master/toxiproxy.rb#L9) [blog]: https://shopifyengineering.myshopify.com/blogs/engineering/building-and-testing-resilient-ruby-on-rails-applications