Skip to content

Commit

Permalink
Merge pull request #4 from chensheng0/master
Browse files Browse the repository at this point in the history
update to baetyl v2.0.0
  • Loading branch information
zxxf18 authored Nov 4, 2020
2 parents 3f18955 + 17b2bdc commit 2939877
Show file tree
Hide file tree
Showing 28 changed files with 1,225 additions and 1,209 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v1
- name: Run unittest
run: make test
run: cd baetyl-remote-object && make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
file: ./baetyl-remote-object/coverage.txt
fail_ci_if_error: true
30 changes: 30 additions & 0 deletions .github/workflows/image-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: image-develop
on:
push:
branches:
- master

jobs:
image:
name: docker build images
runs-on: ubuntu-latest
steps:
- name: Install deps
run: sudo apt update -y && sudo apt install -y qemu qemu-user-static
- name: Install Docker CE for buildx
run: |
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce
docker -v
- name: Checkout code
uses: actions/checkout@v1
- name: docker login
run: |
docker login -u ${{ secrets.DOCKER_REGISTRY_ID }} -p ${{ secrets.DOCKER_REGISTRY_PASS }}
- name: build and publish image
run: |
cd baetyl-remote-object && make image PLATFORMS=all XFLAGS='--push --cache-to=type=local,dest=/tmp/main' REGISTRY=baetyltechtest/
31 changes: 31 additions & 0 deletions .github/workflows/image-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: image-release
on:
push:
tags:
- 'v*'

jobs:
image:
name: docker build images
runs-on: ubuntu-latest
steps:
- name: Install deps
run: sudo apt update -y && sudo apt install -y qemu qemu-user-static
- name: Install Docker CE for buildx
run: |
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce
docker -v
- name: Checkout code
uses: actions/checkout@v1
- name: docker login
run: |
docker login -u ${{ secrets.DOCKER_REGISTRY_ID }} -p ${{ secrets.DOCKER_REGISTRY_PASS }}
- name: build and publish image
run: |
cd baetyl-remote-object && make image PLATFORMS=all XFLAGS='--push --cache-to=type=local,dest=/tmp/main' REGISTRY=baetyltech/
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
- name: Checkout code
uses: actions/checkout@v1
- name: Run unittest
run: make test
run: cd baetyl-remote-object && make test
29 changes: 25 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@
*.dll
*.so
*.dylib
/**/coverage.out
/**/coverage.html
/.idea
/.vscode
/**/coverage.*
/**/.DS_Store
/output

/**/*.log
/vendor
# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Other
*~
*.swp
*.a
*.jar
*.iml
/.idea
/.vscode
/output*
/**/*.zip
/**/.DS_Store
/**/*.db
/**/*.db.lock
/**/*debug.test
/**/debug
/**/*.log
baetyl-remote-object
/**/baetyl-remote-object
/**/output/
55 changes: 0 additions & 55 deletions Makefile

This file was deleted.

12 changes: 6 additions & 6 deletions baetyl-remote-object/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Code generated by github.com/baetyl/baetyl/sdk/baetyl-go/generate.go. DO NOT EDIT.
# source: github.com/baetyl/baetyl/sdk/baetyl-go/templates/Dockerfile-go
FROM --platform=$TARGETPLATFORM golang:1.13.5-stretch as devel
ARG BUILD_ARGS
COPY / /go/src/
RUN cd /go/src/baetyl-remote-object && make build-local BUILD_ARGS=$BUILD_ARGS

FROM --platform=$TARGETPLATFORM busybox
ARG TARGETPLATFORM
ARG MODULE=baetyl-remote-object
COPY $TARGETPLATFORM/$MODULE/*.pem /etc/ssl/certs/
COPY $TARGETPLATFORM/$MODULE/bin/$MODULE /bin/
COPY --from=devel /go/src/baetyl-remote-object/pem/*.pem /etc/ssl/certs/
COPY --from=devel /go/src/baetyl-remote-object/baetyl-remote-object /bin/
ENTRYPOINT ["baetyl-remote-object"]
3 changes: 3 additions & 0 deletions baetyl-remote-object/Dockerfile-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox
COPY baetyl-remote-object /bin/
ENTRYPOINT ["baetyl-remote-object"]
116 changes: 70 additions & 46 deletions baetyl-remote-object/Makefile
Original file line number Diff line number Diff line change
@@ -1,73 +1,97 @@
# Code generated by github.com/baetyl/baetyl/sdk/baetyl-go/generate.go. DO NOT EDIT.
# source: github.com/baetyl/baetyl/sdk/baetyl-go/templates/Makefile-go

MODULE:=baetyl-remote-object
MODULE:=remote-object
BIN:=baetyl-$(MODULE)
SRC_FILES:=$(shell find . -type f -name '*.go')
PEM_FILES:=$(shell find pem -type f -name '*.pem' | sed 's/ /\\ /g')
BIN_FILE:=baetyl-remote-object
BIN_CMD=$(shell echo $(@:$(OUTPUT)/%/$(MODULE)/bin/$(BIN_FILE)=%) | sed 's:/v:/:g' | awk -F '/' '{print "CGO_ENABLED=0 GOOS="$$1" GOARCH="$$2" GOARM="$$3" go build"}') -o $@ ${GO_FLAGS} .
COPY_DIR:=../output
PLATFORM_ALL:=darwin/amd64 linux/amd64 linux/arm64 linux/386 linux/arm/v7 linux/arm/v6 linux/arm/v5 linux/ppc64le linux/s390x
PLATFORM_ALL:=darwin/amd64 linux/amd64 linux/arm64 linux/arm/v7

export DOCKER_CLI_EXPERIMENTAL=enabled

GIT_TAG:=$(shell git tag --contains HEAD)
GIT_TAG:=$(shell git tag --contains HEAD|awk 'END {print}')
GIT_REV:=git-$(shell git rev-parse --short HEAD)
VERSION:=$(if $(GIT_TAG),$(GIT_TAG),$(GIT_REV))
GO_TEST_FLAGS?=
GO_TEST_PKGS?=$(shell go list ./...)
ifeq ($(findstring race,$(BUILD_ARGS)),race)
VERSION:=$(VERSION)-race
endif

GO_OS:=$(shell go env GOOS)
GO_ARCH:=$(shell go env GOARCH)
GO_ARM:=$(shell go env GOARM)

ifndef PLATFORMS
GO_OS:=$(shell go env GOOS)
GO_ARCH:=$(shell go env GOARCH)
GO_ARM:=$(shell go env GOARM)
PLATFORMS:=$(if $(GO_ARM),$(GO_OS)/$(GO_ARCH)/$(GO_ARM),$(GO_OS)/$(GO_ARCH))
ifeq ($(GO_OS),darwin)
PLATFORMS+=linux/amd64
endif
PLATFORMS:=$(if $(GO_ARM),$(GO_OS)/$(GO_ARCH)/$(GO_ARM),$(GO_OS)/$(GO_ARCH))
ifeq ($(GO_OS),darwin)
PLATFORMS+=linux/amd64
endif
else ifeq ($(PLATFORMS),all)
override PLATFORMS:=$(PLATFORM_ALL)
override PLATFORMS:=$(PLATFORM_ALL)
endif

REGISTRY?=
XFLAGS?=--load
XPLATFORMS:=$(shell echo $(filter-out darwin/amd64,$(PLATFORMS)) | sed 's: :,:g')

YML_FILE=$(wildcard *.yml)
GO := go
GO_MOD := $(GO) mod
GO_ENV := env GO111MODULE=on GOPROXY=https://goproxy.cn CGO_ENABLED=0
GO_FLAGS := $(BUILD_ARGS) -ldflags '-X "github.com/baetyl/baetyl-go/v2/utils.REVISION=$(GIT_REV)" -X "github.com/baetyl/baetyl-go/v2/utils.VERSION=$(VERSION)"'
ifeq ($(findstring race,$(BUILD_ARGS)),race)
GO_ENV := env GO111MODULE=on GOPROXY=https://goproxy.cn CGO_ENABLED=1
GO_FLAGS := $(BUILD_ARGS) -ldflags '-s -w -X "github.com/baetyl/baetyl-go/v2/utils.REVISION=$(GIT_REV)" -X "github.com/baetyl/baetyl-go/v2/utils.VERSION=$(VERSION)" -linkmode external -w -extldflags "-static"'
override PLATFORMS:= $(filter-out linux/arm/v7,$(PLATFORMS))
endif
GO_BUILD := $(GO_ENV) $(GO) build $(GO_FLAGS)
GOTEST := $(GO) test
GOPKGS := $$($(GO) list ./... | grep -vE "vendor")

REGISTRY:=
XFLAGS:=--load
XPLATFORMS:=$(shell echo $(filter-out darwin/amd64,$(PLATFORMS)) | sed 's: :,:g')

OUTPUT:=../output
OUTPUT_MODS:=$(PLATFORMS:%=$(OUTPUT)/%/$(MODULE))
OUTPUT_BINS:=$(OUTPUT_MODS:%=%/bin/$(BIN_FILE))
OUTPUT_PKGS:=$(OUTPUT_MODS:%=%/$(MODULE)-$(VERSION).zip) # TODO: switch to tar
OUTPUT :=output
OUTPUT_DIRS:=$(PLATFORMS:%=$(OUTPUT)/%/$(BIN))
OUTPUT_BINS:=$(OUTPUT_DIRS:%=%/$(BIN))
PKG_PLATFORMS := $(shell echo $(PLATFORMS) | sed 's:/:-:g')
OUTPUT_PKGS:=$(PKG_PLATFORMS:%=$(OUTPUT)/$(BIN)_%_$(VERSION).zip)

.PHONY: all
all: $(OUTPUT_BINS) $(OUTPUT_PKGS)
all: build test

.PHONY: build
build: $(OUTPUT_BINS)

$(OUTPUT_BINS): $(SRC_FILES)
@echo "BUILD $@"
@install -d -m 0755 $(dir $@)
$(BIN_CMD)
@mkdir -p $(dir $@)
@cp program.yml $(dir $@)
@$(shell echo $(@:$(OUTPUT)/%/$(BIN)/$(BIN)=%) | sed 's:/v:/:g' | awk -F '/' '{print "GOOS="$$1" GOARCH="$$2" GOARM="$$3""}') $(GO_BUILD) -o $@ .

$(OUTPUT_PKGS): $(OUTPUT_BINS) $(YML_FILE) $(PEM_FILES)
@echo "PACKAGE $@"
@install -m 0755 $(YML_FILE) $(dir $@)
@install -m 0755 $(PEM_FILES) $(dir $@)
@cd $(dir $@) && zip -q -r $(notdir $@) bin $(YML_FILE)
.PHONY: build-local
build-local: $(SRC_FILES)
@echo "BUILD $(BIN)"
$(GO_BUILD) -o $(BIN) .
@chmod +x $(BIN)

.PHONY: image
image: $(OUTPUT_BINS)
image:
@echo "BUILDX: $(REGISTRY)$(MODULE):$(VERSION)"
@-docker buildx create --name baetyl
@docker buildx use baetyl
docker buildx build $(XFLAGS) --platform $(XPLATFORMS) -t $(REGISTRY)$(MODULE):$(VERSION) -f Dockerfile $(COPY_DIR)
@docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx build $(XFLAGS) --platform $(XPLATFORMS) -t $(REGISTRY)$(MODULE):$(VERSION) --build-arg BUILD_ARGS=$(BUILD_ARGS) -f Dockerfile ..

.PHONY: test
test: fmt
$(GOTEST) -race -short -covermode=atomic -coverprofile=coverage.txt $(GOPKGS)
@go tool cover -func=coverage.txt | grep total

.PHONY: rebuild
rebuild: clean all
.PHONY: fmt
fmt:
$(GO_MOD) tidy
@go fmt ./...

.PHONY: clean
clean:
@find $(OUTPUT) -type d -name $(MODULE) | xargs rm -rf
@rm -rf $(OUTPUT) $(BIN)

.PHONY: test
test:
@go test ${GO_TEST_FLAGS} -coverprofile=coverage.out ${GO_TEST_PKGS}
@go tool cover -func=coverage.out | grep total
@go tool cover -html=coverage.out -o coverage.html
.PHONY: package
package: build $(OUTPUT_PKGS)

$(OUTPUT_PKGS):
@echo "PACKAGE $@"
@cd $(OUTPUT)/$(shell echo $(@:$(OUTPUT)/$(BIN)_%_$(VERSION).zip=%) | sed 's:-:/:g')/$(BIN) && zip -q -r $(notdir $@) $(BIN) program.yml
Loading

0 comments on commit 2939877

Please sign in to comment.