Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance external model reference, Makefile, and CI workflow #102

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
with:
go-version: ${{matrix.go-version}}

- name: Build
run: make
- name: Build binary
run: make build

# - name: Test
# run: go test -v ./...
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ log/
.venv/

# Files generated by system_info.py
system_info.yaml
system_info.yaml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN make prod
## Stage 2 - Application Setup
##############################################################

FROM ubuntu:22.04 as prod
FROM ubuntu:22.04 AS prod

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

Expand Down
93 changes: 77 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,84 @@
default:
cd cmd/cm-beetle && $(MAKE)
# Makefile for CM-Beetle in Cloud-Barista.

cc:
cd cmd/cm-beetle && $(MAKE)
MODULE_NAME := cm-beetle
PROJECT_NAME := github.com/cloud-barista/$(MODULE_NAME)
PKG_LIST := $(shell go list $(PROJECT_NAME)/... 2>&1)

run:
cd cmd/cm-beetle && $(MAKE) run
GOPROXY_OPTION := GOPROXY=direct # default: GOPROXY=https://proxy.golang.org,direct
GO := $(GOPROXY_OPTION) go
GOPATH := $(shell go env GOPATH)
SWAG := ~/go/bin/swag

runwithport:
cd cmd/cm-beetle && $(MAKE) runwithport --port=$(PORT)
.PHONY: all dependency lint update swag swagger build arm prod run stop clean help

clean:
cd cmd/cm-beetle && $(MAKE) clean
all: swag build ## Default target: build the project

prod:
cd cmd/cm-beetle && $(MAKE) prod
dependency: ## Get dependencies
@echo "Checking dependencies..."
@$(GO) mod tidy
@echo "Checked!"

onprem-model:
cd pkg/api/rest/model && $(MAKE) onprem-model
lint: dependency ## Lint the files
@echo "Running linter..."
@if [ ! -f "$(GOPATH)/bin/golangci-lint" ] && [ ! -f "$(shell go env GOROOT)/bin/golangci-lint" ]; then \
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@golangci-lint run -E contextcheck -D unused
@echo "Linter finished!"

swag swagger:
cd pkg/ && $(MAKE) swag
update: ## Update all module dependencies
@echo "Updating dependencies..."
@cd cmd/$(MODULE_NAME) && $(GO) get -u
@echo "Checking dependencies..."
@$(GO) mod tidy
@echo "Updated!"

swag swagger: ## Generate Swagger API documentation
@echo "Generating Swagger API documentation..."
@ln -sf cmd/$(MODULE_NAME)/main.go ./main.go
@$(SWAG) i --parseDependency --generalInfo ./main.go --dir ./ --output ./api
@rm ./main.go
@echo "Generated Swagger API documentation!"

# build: lint swag ## Build the binary file for amd64
build: ## Build the binary file for amd64
@echo "Building the binary for amd64..."
@cd cmd/$(MODULE_NAME) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o $(MODULE_NAME) main.go
@echo "Build finished!"

# arm: lint swag ## Build the binary file for ARM
arm: ## Build the binary file for ARM
@echo "Building the binary for ARM..."
@cd cmd/$(MODULE_NAME) && CGO_ENABLED=0 GOOS=linux GOARCH=arm $(GO) build -o $(MODULE_NAME)-arm main.go
@echo "Build finished!"

# prod: lint swag ## Build the binary file for production
prod: ## Build the binary file for production
@echo "Building the binary for amd64 production..."
# Note - Using cgo write normal Go code that imports a pseudo-package "C". I may not need on cross-compiling.
# Note - You can find possible platforms by 'go tool dist list' for GOOS and GOARCH
# Note - Using the -ldflags parameter can help set variable values at compile time.
# Note - Using the -s and -w linker flags can strip the debugging information.
@cd cmd/$(MODULE_NAME) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -ldflags '-s -w' -o $(MODULE_NAME) main.go
@echo "Build finished!"

run: build ## Run the built binary
@echo "Running the binary..."
@source conf/setup.env; \
cd cmd/$(MODULE_NAME) && \
(./$(MODULE_NAME) || { echo "Trying with sudo..."; sudo ./$(MODULE_NAME); })

stop: ## Stop the built binary
@echo "Stopping the binary..."
@sudo killall $(MODULE_NAME) 2>/dev/null || true
@echo "Stopped!"

clean: ## Remove previous build
@echo "Cleaning build..."
@rm -f coverage.out
@rm -f api/docs.go api/swagger.*
@cd cmd/$(MODULE_NAME) && $(GO) clean
@echo "Cleaned!"

help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Loading