From 113e0554aa9410c079ab11f2f8d2409f0a9dfad5 Mon Sep 17 00:00:00 2001 From: Oleg <97077423+RobotSail@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:55:41 -0400 Subject: [PATCH 1/2] use os.Stdout.WriteString instead of fmt.Printf Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com> --- pkg/cmd/utils.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/utils.go b/pkg/cmd/utils.go index 2ebde18..f5cb771 100644 --- a/pkg/cmd/utils.go +++ b/pkg/cmd/utils.go @@ -135,8 +135,10 @@ func PrintOrWriteOut(r *Request) error { if err != nil { return err } - // stringOut := strings.ReplaceAll(fmOutput, "\\n", "\n") - fmt.Printf("%s\n", fmOutput) + _, err = os.Stdout.WriteString(fmOutput) + if err != nil { + return fmt.Errorf("could not write to stdout: %w", err) + } return nil } From 2d46a4e222e609b15623e8ea6c04ce9a7f7dbb7a Mon Sep 17 00:00:00 2001 From: Oleg <97077423+RobotSail@users.noreply.github.com> Date: Mon, 7 Nov 2022 11:43:50 -0500 Subject: [PATCH 2/2] add container build step to CI Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com> --- .github/workflows/ci.yaml | 22 +++++++++++++++++- Makefile | 47 ++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0c7fa37..e91303b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,8 +20,11 @@ on: - ".github/workflows/bot.yaml" - ".github/workflows/todo-issue.yaml" -jobs: +env: + COPILOT_OPS_IMG: "quay.io/copilot-ops/copilot-ops" + COPILOT_OPS_IMG_TAG: "latest" +jobs: test: runs-on: ubuntu-latest steps: @@ -77,3 +80,20 @@ jobs: with: name: copilot-ops-darwin-arm64 path: copilot-ops-darwin-arm64 + + build-image: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout Source + uses: actions/checkout@v3 + - name: Build Container Image + run: IMG="${COPILOT_OPS_IMG}"; IMG_TAG="${COPILOT_OPS_IMG_TAG}"; make docker-build + - name: Export Container Image + run: docker save -o /tmp/image.tar "${COPILOT_OPS_IMG}:${COPILOT_OPS_IMG_TAG}" + - name: Save Container Image as Artifact + uses: actions/upload-artifact@v3 + with: + name: copilot-ops-image + path: /tmp/image.tar + diff --git a/Makefile b/Makefile index bf5e407..3bb8297 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,41 @@ -build: +##@ General + +IMG ?= quay.io/copilot-ops/copilot-ops +IMG_TAG ?= latest + +# The help target prints out all targets with their descriptions organized +# beneath their categories. The categories are represented by '##@' and the +# target descriptions by '##'. The awk commands is responsible for reading the +# entire set of makefiles included in this invocation, looking for lines of the +# file as xyz: ## something, and then pretty-format the target and help. Then, +# if there's a line with ##@ something, that gets pretty-printed as a category. +# More info on the usage of ANSI control characters for terminal formatting: +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters +# More info on the awk command: +# http://linuxcommand.org/lc3_adv_awk.php + +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +##@ Build + +build: ## Build the copilot-ops file. @ echo ▶️ go build go build @ echo ✅ go build @ echo ./copilot-ops -h "# run me!" .PHONY: build -image: - docker build -t quay.io/copilot-ops/copilot-ops . - @ echo ✅ docker build .PHONY: image +image: ## Build a container image of the current project. + docker build -t ${IMG}:${IMG_TAG} . + @ echo ✅ docker build -publish: image - docker push quay.io/copilot-ops/copilot-ops - @ echo ✅ docker push .PHONY: publish +publish: image ## Publish the container image into Quay.io. + docker push ${IMG}:${IMG_TAG} + @ echo ✅ docker push ##@ Development @@ -29,17 +51,9 @@ test: lint ginkgo ## Run tests. $(GINKGO) --coverprofile "cover.out" ./... @ echo "✅ ginkgo test" -##@ Build Dependencies - -## Location to install dependencies to -LOCALBIN ?= $(shell pwd)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - ##@ Download utilities -# for performing lints -.PHONY: golangci-lint +.PHONY: golangci-lint GOLANGCILINT := $(LOCALBIN)/golangci-lint GOLANGCI_URL := https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh golangci-lint: $(GOLANGCILINT) ## Download golangci-lint @@ -58,6 +72,7 @@ $(GINKGO): $(LOCALBIN) ##@ Build Dependencies + LOCALBIN ?= $(shell pwd)/bin $(LOCALBIN): @ echo "▶️ Local binary directory not present, creating..."