Skip to content

Commit b30b78b

Browse files
authored
Merge pull request #53 from appscode/x7
2 parents a59afa0 + f00236a commit b30b78b

35 files changed

+691
-140
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
13+
build:
14+
name: Build
15+
runs-on: ubuntu-latest
16+
steps:
17+
18+
- name: Set up Go 1.14
19+
uses: actions/setup-go@v1
20+
with:
21+
go-version: 1.14
22+
id: go
23+
24+
- name: Check out code into the Go module directory
25+
uses: actions/checkout@v1
26+
27+
- name: Run checks
28+
run: |
29+
sudo apt-get -qq update || true
30+
sudo apt-get install -y bzr
31+
make ci

.github/workflows/release.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*.*'
7+
8+
jobs:
9+
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
15+
- name: Check out code into the Go module directory
16+
uses: actions/checkout@v1
17+
18+
- name: Print version info
19+
id: semver
20+
run: |
21+
make version
22+
23+
- name: Set up Docker Buildx
24+
id: buildx
25+
uses: crazy-max/ghaction-docker-buildx@v1
26+
with:
27+
buildx-version: latest
28+
qemu-version: latest
29+
30+
- name: Available platforms
31+
run: echo ${{ steps.buildx.outputs.platforms }}
32+
33+
- name: Build
34+
env:
35+
APPSCODE_ENV: prod
36+
run: |
37+
make release
38+
39+
- name: Release
40+
uses: softprops/action-gh-release@v1
41+
if: startsWith(github.ref, 'refs/tags/')
42+
with:
43+
draft: true
44+
files: |
45+
bin/osm-linux-amd64
46+
bin/osm-linux-arm
47+
bin/osm-linux-arm64
48+
bin/osm-windows-amd64.exe
49+
bin/osm-darwin-amd64
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- uses: actions/upload-artifact@master
54+
with:
55+
name: osm-binaries
56+
path: bin

Makefile

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
SHELL=/bin/bash -o pipefail
1717

18-
# The binary to build (just the basename).
18+
GO_PKG := github.com/appscode
19+
REPO := $(notdir $(shell pwd))
1920
BIN := osm
2021
COMPRESS ?= no
2122

@@ -46,7 +47,8 @@ endif
4647
### These variables should not need tweaking.
4748
###
4849

49-
SRC_DIRS := cmds context *.go # directories which hold app source (not vendored)
50+
SRC_PKGS := cmds context
51+
SRC_DIRS := $(SRC_PKGS) *.go hack/gendocs # directories which hold app source (not vendored)
5052

5153
DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64
5254
BIN_PLATFORMS := $(DOCKER_PLATFORMS) windows/amd64 darwin/amd64
@@ -68,9 +70,10 @@ TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH)
6870
GO_VERSION ?= 1.14
6971
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)
7072

71-
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
73+
OUTBIN = bin/$(BIN)-$(OS)-$(ARCH)
7274
ifeq ($(OS),windows)
73-
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN).exe
75+
OUTBIN := bin/$(BIN)-$(OS)-$(ARCH).exe
76+
BIN := $(BIN).exe
7477
endif
7578

7679
# Directories that we need created to build/test.
@@ -81,6 +84,8 @@ BUILD_DIRS := bin/$(OS)_$(ARCH) \
8184
DOCKERFILE_PROD = hack/docker/Dockerfile.in
8285
DOCKERFILE_DBG = hack/docker/Dockerfile.dbg
8386

87+
DOCKER_REPO_ROOT := /go/src/$(GO_PKG)/$(REPO)
88+
8489
# If you want to build all binaries, see the 'all-build' rule.
8590
# If you want to build all containers, see the 'all-container' rule.
8691
# If you want to build AND push all containers, see the 'all-push' rule.
@@ -114,13 +119,14 @@ all-container: $(addprefix container-, $(subst /,_, $(DOCKER_PLATFORMS)))
114119
all-push: $(addprefix push-, $(subst /,_, $(DOCKER_PLATFORMS)))
115120

116121
version:
117-
@echo version=$(VERSION)
118-
@echo version_strategy=$(version_strategy)
119-
@echo git_tag=$(git_tag)
120-
@echo git_branch=$(git_branch)
121-
@echo commit_hash=$(commit_hash)
122-
@echo commit_timestamp=$(commit_timestamp)
123-
122+
@echo ::set-output name=version::$(VERSION)
123+
@echo ::set-output name=version_strategy::$(version_strategy)
124+
@echo ::set-output name=git_tag::$(git_tag)
125+
@echo ::set-output name=git_branch::$(git_branch)
126+
@echo ::set-output name=commit_hash::$(commit_hash)
127+
@echo ::set-output name=commit_timestamp::$(commit_timestamp)
128+
129+
.PHONY: gen
124130
gen:
125131
@true
126132

@@ -137,7 +143,10 @@ fmt: $(BUILD_DIRS)
137143
--env HTTP_PROXY=$(HTTP_PROXY) \
138144
--env HTTPS_PROXY=$(HTTPS_PROXY) \
139145
$(BUILD_IMAGE) \
140-
./hack/fmt.sh $(SRC_DIRS)
146+
/bin/bash -c " \
147+
REPO_PKG=$(GO_PKG) \
148+
./hack/fmt.sh $(SRC_DIRS) \
149+
"
141150

142151
build: $(OUTBIN)
143152

@@ -189,27 +198,27 @@ $(OUTBIN): .go/$(OUTBIN).stamp
189198
--env HTTP_PROXY=$(HTTP_PROXY) \
190199
--env HTTPS_PROXY=$(HTTPS_PROXY) \
191200
$(BUILD_IMAGE) \
192-
upx --brute /go/$(OUTBIN); \
201+
upx --brute /go/bin/$(BIN); \
193202
fi
194-
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
195-
mv .go/$(OUTBIN) $(OUTBIN); \
196-
date >$@; \
203+
@if ! cmp -s .go/bin/$(OS)_$(ARCH)/$(BIN) $(OUTBIN); then \
204+
mv .go/bin/$(OS)_$(ARCH)/$(BIN) $(OUTBIN); \
205+
date >$@; \
197206
fi
198207
@echo
199208

200209
# Used to track state in hidden files.
201210
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
202211

203212
container: bin/.container-$(DOTFILE_IMAGE)-PROD bin/.container-$(DOTFILE_IMAGE)-DBG
204-
bin/.container-$(DOTFILE_IMAGE)-%: bin/$(OS)_$(ARCH)/$(BIN) $(DOCKERFILE_%)
213+
bin/.container-$(DOTFILE_IMAGE)-%: $(OUTBIN) $(DOCKERFILE_%)
205214
@echo "container: $(IMAGE):$(TAG_$*)"
206215
@sed \
207-
-e 's|{ARG_BIN}|$(BIN)|g' \
208-
-e 's|{ARG_ARCH}|$(ARCH)|g' \
209-
-e 's|{ARG_OS}|$(OS)|g' \
210-
-e 's|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
211-
$(DOCKERFILE_$*) > bin/.dockerfile-$*-$(OS)_$(ARCH)
212-
@docker build --pull -t $(IMAGE):$(TAG_$*) -f bin/.dockerfile-$*-$(OS)_$(ARCH) .
216+
-e 's|{ARG_BIN}|$(BIN)|g' \
217+
-e 's|{ARG_ARCH}|$(ARCH)|g' \
218+
-e 's|{ARG_OS}|$(OS)|g' \
219+
-e 's|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
220+
$(DOCKERFILE_$*) > bin/.dockerfile-$*-$(OS)_$(ARCH)
221+
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform $(OS)/$(ARCH) --load --pull -t $(IMAGE):$(TAG_$*) -f bin/.dockerfile-$*-$(OS)_$(ARCH) .
213222
@docker images -q $(IMAGE):$(TAG_$*) > $@
214223
@echo
215224

@@ -225,7 +234,10 @@ docker-manifest-%:
225234
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a $(IMAGE):$(VERSION_$*) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION_$*)_$(subst /,_,$(PLATFORM)))
226235
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(IMAGE):$(VERSION_$*)
227236

228-
test: $(BUILD_DIRS)
237+
.PHONY: test
238+
test: unit-tests e2e-tests
239+
240+
unit-tests: $(BUILD_DIRS)
229241
@docker run \
230242
-i \
231243
--rm \
@@ -237,12 +249,12 @@ test: $(BUILD_DIRS)
237249
-v $$(pwd)/.go/cache:/.cache \
238250
--env HTTP_PROXY=$(HTTP_PROXY) \
239251
--env HTTPS_PROXY=$(HTTPS_PROXY) \
240-
$(BUILD_IMAGE) \
252+
$(BUILD_IMAGE) \
241253
/bin/bash -c " \
242254
ARCH=$(ARCH) \
243255
OS=$(OS) \
244256
VERSION=$(VERSION) \
245-
./hack/test.sh $(SRC_DIRS) \
257+
./hack/test.sh $(SRC_PKGS) \
246258
"
247259

248260
ADDTL_LINTERS := goconst,gofmt,goimports,unparam
@@ -264,16 +276,59 @@ lint: $(BUILD_DIRS)
264276
--env GO111MODULE=on \
265277
--env GOFLAGS="-mod=vendor" \
266278
$(BUILD_IMAGE) \
267-
golangci-lint run --enable $(ADDTL_LINTERS)
279+
golangci-lint run --enable $(ADDTL_LINTERS) --deadline=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default --skip-dirs=client,vendor
268280

269281
$(BUILD_DIRS):
270282
@mkdir -p $@
271283

272284
.PHONY: dev
273285
dev: gen fmt push
274286

287+
.PHONY: verify
288+
verify: verify-modules verify-gen
289+
290+
.PHONY: verify-modules
291+
verify-modules:
292+
GO111MODULE=on go mod tidy
293+
GO111MODULE=on go mod vendor
294+
@if !(git diff --exit-code HEAD); then \
295+
echo "go module files are out of date"; exit 1; \
296+
fi
297+
298+
.PHONY: verify-gen
299+
verify-gen: gen fmt
300+
@if !(git diff --exit-code HEAD); then \
301+
echo "files are out of date, run make gen fmt"; exit 1; \
302+
fi
303+
304+
.PHONY: add-license
305+
add-license:
306+
@echo "Adding license header"
307+
@docker run --rm \
308+
-u $$(id -u):$$(id -g) \
309+
-v /tmp:/.cache \
310+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
311+
-w $(DOCKER_REPO_ROOT) \
312+
--env HTTP_PROXY=$(HTTP_PROXY) \
313+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
314+
$(BUILD_IMAGE) \
315+
ltag -t "./hack/license" --excludes "vendor contrib" -v
316+
317+
.PHONY: check-license
318+
check-license:
319+
@echo "Checking files for license header"
320+
@docker run --rm \
321+
-u $$(id -u):$$(id -g) \
322+
-v /tmp:/.cache \
323+
-v $$(pwd):$(DOCKER_REPO_ROOT) \
324+
-w $(DOCKER_REPO_ROOT) \
325+
--env HTTP_PROXY=$(HTTP_PROXY) \
326+
--env HTTPS_PROXY=$(HTTPS_PROXY) \
327+
$(BUILD_IMAGE) \
328+
ltag -t "./hack/license" --excludes "vendor contrib" --check -v
329+
275330
.PHONY: ci
276-
ci: lint test build #cover
331+
ci: verify check-license lint build unit-tests #cover
277332

278333
.PHONY: qa
279334
qa:

cmds/config/config.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright The osm Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package config
218

319
import "github.com/spf13/cobra"
@@ -9,7 +25,7 @@ func NewCmdConfig() *cobra.Command {
925
Example: "osm config view",
1026
DisableAutoGenTag: true,
1127
Run: func(cmd *cobra.Command, args []string) {
12-
cmd.Help()
28+
_ = cmd.Help()
1329
},
1430
}
1531

cmds/config/current.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright The osm Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package config
218

319
import (
@@ -16,7 +32,7 @@ func newCmdCurrent() *cobra.Command {
1632
DisableAutoGenTag: true,
1733
Run: func(cmd *cobra.Command, args []string) {
1834
if len(args) > 0 {
19-
cmd.Help()
35+
_ = cmd.Help()
2036
os.Exit(1)
2137
}
2238
currentContext(otx.GetConfigPath(cmd))

cmds/config/get.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright The osm Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package config
218

319
import (
@@ -18,7 +34,7 @@ func newCmdGet() *cobra.Command {
1834
DisableAutoGenTag: true,
1935
Run: func(cmd *cobra.Command, args []string) {
2036
if len(args) > 0 {
21-
cmd.Help()
37+
_ = cmd.Help()
2238
os.Exit(1)
2339
}
2440
getContexts(otx.GetConfigPath(cmd))

0 commit comments

Comments
 (0)