-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(docker): add goreleaser docker GitHub Container Registry support
Signed-off-by: Derek Smith <dsmith@goodwaygroup.com>
- Loading branch information
Showing
9 changed files
with
288 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,6 @@ gen | |
|
||
build/ | ||
.DS_Store | ||
bin/ | ||
bin/ | ||
dist/ | ||
gwsm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.