Skip to content

Commit

Permalink
Add release tooling. (#8)
Browse files Browse the repository at this point in the history
This fixes #5.

Signed-off-by: James Peach <[email protected]>
  • Loading branch information
jpeach authored Jul 20, 2020
1 parent 1126a62 commit daede34
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 2 deletions.
56 changes: 56 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
project_name: contour-authserver
before:
hooks:
- go mod download
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goarch:
- amd64
goos:
- linux
- darwin
ldflags:
- -s
- -w
- -X github.com/projectcontour/contour-authserver/pkg/version.Progname={{ .ProjectName }}
- -X github.com/projectcontour/contour-authserver/pkg/version.Version={{ .Env.VERSION }}
- -X github.com/projectcontour/contour-authserver/pkg/version.Sha={{ .Env.SHA }}
- -X github.com/projectcontour/contour-authserver/pkg/version.BuildDate={{ .Date }}
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
dockers:
- goarch: amd64
goos: linux
dockerfile: hack/Dockerfile.release
skip_push: true
image_templates:
- "projectcontour/{{ .ProjectName }}:{{ .Env.VERSION }}"
- "projectcontour/{{ .ProjectName }}:latest"
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Env.VERSION}}"
- "--label=org.opencontainers.image.url=https://projectcontour.io/"
- "--label=org.opencontainers.image.documentation=https://projectcontour.io/"
- "--label=org.opencontainers.image.vendor=Project Contour"
- "--label=org.opencontainers.image.licenses=Apache-2.0"
- "--label=org.opencontainers.image.title=Contour Authserver"
- "--label=org.opencontainers.image.description=Contour Authorization Server"
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Build the manager binary
# Build the contour-authserver binary.
#
# Note that this is not used for releasing, since goreleaser handles that.

FROM golang:1.14 as base

ENV GO111MODULE=on
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ docker-build: ## Build the docker image
docker-push: ## Push the docker image
docker push ${IMG}

.PHONY: release
release: ## Build and publish a release to Github
# Check there is a token.
[[ -n "$$GITHUB_TOKEN" ]] || [[ -r ~/.config/goreleaser/github_token ]]
# Check we are on a tag.
git describe --exact-match >/dev/null
# Do a full dry-run.
goreleaser check
SHA=$(SHA) VERSION=$(VERSION) goreleaser release --rm-dist

.PHONY: clean
clean:
@rm -rf cover.out
@rm bin/$(BIN)
@rm -rf bin
@rm -rf dist

.PHONY: help
help:
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ the `testserver` and `htpasswd` backends. For developer deployments,

There are no versioned releases or container images yet.

# Releasing `contour-authserver`

Maintainers who need to release a new version of `contour-authserver`
can follow the following steps:

```bash
# Ensure that you have a Github token either in $GITHUB_TOKEN or in ~/.config/goreleaser/github_token.
# Ensure that goreleaser is installed.

# Tag the release.
$ ./hack/make-release-tag.sh $OLDVERS $NEWVERS

# Push the release tag to Github.
$ git push origin $NEWVERS

# Build and release binaries and Docker images.
$ make release

# Log in with the Contour build account to push the images.
$ docker login -u projectcontourbuilder
$ docker push projectcontour/contour-authserver:$NEWVERS
$ docker push projectcontour/contour-authserver:latest

# Log out of the Contour build account.
$ docker logout
```

[1]: https://httpd.apache.org/docs/current/programs/htpasswd.html
[2]: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#authentication
[3]: https://tools.ietf.org/html/rfc7617
Expand Down
3 changes: 3 additions & 0 deletions hack/Dockerfile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY contour-authserver /
ENTRYPOINT ["/contour-authserver"]
42 changes: 42 additions & 0 deletions hack/make-release-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#! /usr/bin/env bash

# Copyright Project Contour Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

readonly PROGNAME=$(basename "$0")
readonly OLDVERS="$1"
readonly NEWVERS="$2"

if [ -z "$OLDVERS" ] || [ -z "$NEWVERS" ]; then
printf "Usage: %s OLDVERS NEWVERS\n" PROGNAME
exit 1
fi

set -o errexit
set -o nounset
set -o pipefail

if [ -n "$(git tag --list "$NEWVERS")" ]; then
printf "%s: tag '%s' already exists\n" "$PROGNAME" "$NEWVERS"
exit 1
fi

git tag -F - "$NEWVERS" <<EOF
Tag $NEWVERS release.
$(git shortlog "$OLDVERS..HEAD")
EOF

printf "Created tag '%s'\n" "$NEWVERS"
printf "Run 'git push %s %s' to push the tag if you are happy\n" '$REMOTE' "$NEWVERS"

0 comments on commit daede34

Please sign in to comment.