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 <dsmith@goodwaygroup.com>
  • Loading branch information
clok committed Apr 2, 2021
1 parent f03387c commit d168331
Show file tree
Hide file tree
Showing 9 changed files with 288 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/gwsm:edge
15 changes: 14 additions & 1 deletion .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,10 +17,19 @@ 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:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ gen

build/
.DS_Store
bin/
bin/
dist/
gwsm
11 changes: 9 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ changelog:
snapshot:
name_template: "{{ .Tag }}-next"

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

brews:
- tap:
owner: GoodwayGroup
name: homebrew-gwsm
homepage: "https://goodwaygroup.github.io/gwsm/"
description: "Kubernetes ConfigMaps + https://github.com/cyberark/summon + AWS Secrets Manager"
description: "A set of commands to audit AWS usage to identify cost savings and security issues."
license: "MIT"
test: |
system "#{bin}/gwsm --help"
install: |
bin.install "gwsm"
bin.install "gwsm"
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 gwsm /usr/local/bin/gwsm
RUN chmod +x /usr/local/bin/gwsm

RUN mkdir /workdir
WORKDIR /workdir

ENTRYPOINT [ "/usr/local/bin/gwsm" ]
114 changes: 97 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,106 @@
NAME=gwsm
# Build Variables
NAME = gwsm
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 gwsm
@ $(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)

docs:
DOCS_MD=1 go run ./main.go > docs/gwsm.md
DOCS_MAN=1 go run ./main.go > docs/gwsm.8
.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

clean:
@rm -rf bin/ && rm -rf build/ && rm -rf dist/
########
##@ Help

lint:
@golangci-lint run
.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 build clean docs lint
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 @@ -66,6 +66,20 @@ brew install gwsm
$ curl https://i.jpillora.com/GoodwayGroup/gwsm! | 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/gwsm).
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/gwsm/releases)
- `x.y.z` (versions): Images that are build from the tagged versions within Github.

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

### man page

To install `man` page:
Expand Down
Loading

0 comments on commit d168331

Please sign in to comment.