Skip to content

Commit

Permalink
ci(docker): add goreleaser docker GitHub Container Registry support
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Smith <[email protected]>
  • Loading branch information
clok committed Apr 1, 2021
1 parent 045bb2d commit d32d153
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 30 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/edge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: docker

on:
push:
branches:
- main

env:
GO_VERSION: "1.16"
DOCKER_REGISTRY: "ghcr.io"

jobs:
edge:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push docker image
run: |
DOCKER_TAG=edge make docker
docker push ${{ env.DOCKER_REGISTRY }}/goodwaygroup/gwvault:edge
17 changes: 15 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
tags:
- '*'

env:
GO_VERSION: "1.16"
DOCKER_REGISTRY: "ghcr.io"

jobs:
goreleaser:
runs-on: ubuntu-20.04
Expand All @@ -13,14 +17,23 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: ${{ env.GO_VERSION }}

- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_CLOK_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GORELEASER_CLOK_TOKEN }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ testdata
vault-key
.idea
.DS_Store
bin
bin/
benchmark/results.html
dist/
dist/
gwvault
7 changes: 7 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ changelog:
snapshot:
name_template: "{{ .Tag }}-next"

dockers:
- ids:
- gwvault
image_templates:
- "ghcr.io/goodwaygroup/gwvault:{{ .RawVersion }}"
- "ghcr.io/goodwaygroup/gwvault:latest"

brews:
- tap:
owner: GoodwayGroup
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.13.4

COPY gwvault /usr/local/bin/gwvault
RUN chmod +x /usr/local/bin/gwvault

RUN mkdir /workdir
WORKDIR /workdir

ENTRYPOINT [ "/usr/local/bin/gwvault" ]
113 changes: 98 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,106 @@
NAME=gwvault
# Build Variables
NAME = gwvault
VERSION ?= $(shell git describe --tags --always)

VERSION=$$(git describe --tags --always)
SHORT_VERSION=$$(git describe --tags --always | awk -F '-' '{print $$1}')
# Go variables
GO ?= go
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
GOHOST ?= GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO)

LDFLAGS=-ldflags=all="-X main.version=${SHORT_VERSION}"
LDFLAGS ?= "-X main.version=$(VERSION)"

all: build
.PHONY: all
all: help

build:
###############
##@ Development

.PHONY: clean
clean: ## Clean workspace
@ $(MAKE) --no-print-directory log-$@
rm -rf bin/
rm -rf build/
rm -rf dist/
rm -rf cover.out
rm -f ./$(NAME)
go mod tidy

.PHONY: test
test: ## Run tests
@ $(MAKE) --no-print-directory log-$@
$(GOHOST) test -covermode atomic -coverprofile cover.out -v ./...

.PHONY: lint
lint: ## Run linters
@ $(MAKE) --no-print-directory log-$@
golangci-lint run

#########
##@ Build

.PHONY: build
build: clean ## Build gwvault
@ $(MAKE) --no-print-directory log-$@
@mkdir -p bin/
go get -t ./...
go test -v ./...
go build ${LDFLAGS} -o bin/${NAME} ./main.go
CGO_ENABLED=0 $(GOHOST) build -ldflags=$(LDFLAGS) -o bin/$(NAME) ./main.go

alpine: clean ## Build binary for alpine docker image
@ $(MAKE) --no-print-directory log-$@
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o $(NAME) ./main.go

.PHONY: docker
docker: DOCKER_TAG ?= dev
docker: alpine ## Build Docker image
@ $(MAKE) --no-print-directory log-$@
docker build --pull --tag ghcr.io/goodwaygroup/$(NAME):$(DOCKER_TAG) .
make clean

###########
##@ Release

.PHONY: changelog
changelog: ## Generate changelog
@ $(MAKE) --no-print-directory log-$@
git-chglog --next-tag $(VERSION) -o CHANGELOG.md

.PHONY: release
release: ## Release a new tag
@ $(MAKE) --no-print-directory log-$@
./release.sh $(VERSION)

.PHONY: docs
docs: ## Generate new docs
@ $(MAKE) --no-print-directory log-$@
DOCS_MD=1 go run ./main.go > docs/$(NAME).md
DOCS_MAN=1 go run ./main.go > docs/$(NAME).8

docs:
DOCS_MD=1 go run ./main.go > docs/${NAME}.md
DOCS_MAN=1 go run ./main.go > docs/${NAME}.8
########
##@ Help

clean:
@rm -rf bin/ && rm -rf build/ && rm -rf dist/
.PHONY: help
help: ## Display this help
@awk \
-v "col=\033[36m" -v "nocol=\033[0m" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Usage:\n make %s<target>%s\n", col, nocol \
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol \
} \
' $(MAKEFILE_LIST)

.PHONY: all tools build clean docs
log-%:
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \
awk \
'BEGIN { \
FS = ":.*?## " \
}; \
{ \
printf "\033[36m==> %s\033[0m\n", $$2 \
}'
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ brew install gwvault
$ curl https://i.jpillora.com/GoodwayGroup/gwvault! | bash
```

### [docker](https://www.docker.com/)

The compiled docker images are maintained on [GitHub Container Registry (ghcr.io)](https://github.com/orgs/GoodwayGroup/packages/container/package/gwvault).
We maintain the following tags:

- `edge`: Image that is build from the current `HEAD` of the main line branch.
- `latest`: Image that is built from the [latest released version](https://github.com/GoodwayGroup/gwvault/releases)
- `x.y.z` (versions): Images that are build from the tagged versions within Github.

```bash
docker pull ghcr.io/goodwaygroup/gwvault
docker run -v "$PWD":/workdir ghcr.io/goodwaygroup/gwvault --version
```

### man page

To install `man` page:
Expand Down
29 changes: 18 additions & 11 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set +e

NAME=gwvault

#
# Set Colors
#
Expand Down Expand Up @@ -64,29 +66,34 @@ if [ "x${VERSION}x" = "xx" ]; then
exit 1
fi

h1 "Preparing release of $VERSION"
if [[ "$(git tag -l | grep -c "$VERSION" 2>/dev/null)" != "0" ]]; then
error "Tag $VERSION already exists in this repo. Please use a different version."
exit 1
fi

h1 "Preparing release of $VERSION for $NAME"

h2 "Updating docs"
make docs
if [[ "$(git status -s docs/gwvault.* 2>/dev/null | wc -l)" == "0" ]]; then
if [[ "$(git status -s docs/${NAME}.* 2>/dev/null | wc -l)" == "0" ]]; then
note "No changes to docs"
else
note "Committing changes to docs"
git add docs/gwvault.*
git add docs/${NAME}.*
git commit -m "chore(docs): updating docs for version $VERSION"
fi

h2 "Updating CHANGELOG.md"
git-chglog --next-tag $VERSION -o CHANGELOG.md && git add CHANGELOG.md
git commit -m "feat(release): $VERSION"
make changelog
git add CHANGELOG.md
git commit -m "chore(release): $VERSION"

h2 "Tagging version: $VERSION"
git tag $VERSION
git tag "$VERSION"

note "Pushing branch: git push origin $(git rev-parse --abbrev-ref HEAD)"
git push origin $(git rev-parse --abbrev-ref HEAD)
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
note "Pushing branch: git push origin $BRANCH"
git push origin "$BRANCH"

note "Pushing tag: git push origin $VERSION"
git push origin $VERSION

success "Done!"
git push origin "$VERSION"

0 comments on commit d32d153

Please sign in to comment.