From dc22cc0cf0a0c84efd77e976f536370e35a5645f Mon Sep 17 00:00:00 2001 From: Fernando ike Date: Wed, 20 Oct 2021 05:53:15 -0300 Subject: [PATCH] Added arm64 arch (#670) * Added arm64 arch Signed-off-by: Fernando Ike * Added missed files generated in release action into goreleaser * Commented var env GOARCH in the e2e test Signed-off-by: Fernando Ike (cherry picked from commit 693bf32589f94ca66538ae30367d9e503df17ff7) --- .github/workflows/build.yaml | 8 +-- .github/workflows/release.yml | 30 +++++++++++ Makefile | 61 +++++++++++++++++++---- deployments/scripts/install.sh | 12 +++++ e2e/scan_languages/scan_languages_test.go | 2 +- goreleaser.yml | 13 ++++- 6 files changed, 110 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2a4b23f81..541567a5b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -26,6 +26,8 @@ jobs: go-version: 1.17 - name: build run: | - CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o "tmp/horusec-linux" ./cmd/app/main.go - CGO_ENABLED=0 GOOS=darwin go build -a -installsuffix cgo -o "tmp/horusec-darwin" ./cmd/app/main.go - env GOOS=windows GOARCH=amd64 go build -o "tmp/horusec-win.exe" ./cmd/app/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -installsuffix cgo -o "tmp/horusec-linux-x64" ./cmd/app/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o "tmp/horusec-linux-arm64" ./cmd/app/main.go + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -installsuffix cgo -o "tmp/horusec-darwin-x64" ./cmd/app/main.go + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -installsuffix cgo -o "tmp/horusec-darwin-arm64" ./cmd/app/main.go + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -installsuffix cgo -o "tmp/horusec-win.exe" ./cmd/app/main.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 142c8cbaa..11ff0ef92 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,6 +91,16 @@ jobs: cosign sign-blob -key=$COSIGN_KEY_LOCATION \ -output=./tmp/horusec_linux_x64_stand_alone.sig ./tmp/horusec_linux_x64_stand_alone + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags \ + "-X 'github.com/ZupIT/horusec/config/dist.standAlone=true' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Version=${{ steps.updated-version.outputs.version }}' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Commit=${{ github.sha }}' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Date=${{ steps.date.outputs.date }}'" \ + -o ./tmp/horusec_linux_arm64_stand_alone ./cmd/app/main.go + + cosign sign-blob -key=$COSIGN_KEY_LOCATION \ + -output=./tmp/horusec_linux_arm64_stand_alone.sig ./tmp/horusec_linux_arm64_stand_alone + CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags \ "-X 'github.com/ZupIT/horusec/config/dist.standAlone=true' \ -X 'github.com/ZupIT/horusec/cmd/app/version.Version=${{ steps.updated-version.outputs.version }}' \ @@ -111,6 +121,16 @@ jobs: cosign sign-blob -key=$COSIGN_KEY_LOCATION \ -output=./tmp/horusec_windows_x64_stand_alone.exe.sig ./tmp/horusec_windows_x64_stand_alone.exe + CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -ldflags \ + "-X 'github.com/ZupIT/horusec/config/dist.standAlone=true' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Version=${{ steps.updated-version.outputs.version }}' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Commit=${{ github.sha }}' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Date=${{ steps.date.outputs.date }}'" \ + -o ./tmp/horusec_windows_arm64_stand_alone.exe ./cmd/app/main.go + + cosign sign-blob -key=$COSIGN_KEY_LOCATION \ + -output=./tmp/horusec_windows_arm64_stand_alone.exe.sig ./tmp/horusec_windows_x64_stand_alone.exe + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags \ "-X 'github.com/ZupIT/horusec/config/dist.standAlone=true' \ -X 'github.com/ZupIT/horusec/cmd/app/version.Version=${{ steps.updated-version.outputs.version }}' \ @@ -120,6 +140,16 @@ jobs: cosign sign-blob -key=$COSIGN_KEY_LOCATION \ -output=./tmp/horusec_mac_x64_stand_alone.sig ./tmp/horusec_mac_x64_stand_alone + + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags \ + "-X 'github.com/ZupIT/horusec/config/dist.standAlone=true' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Version=${{ steps.updated-version.outputs.version }}' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Commit=${{ github.sha }}' \ + -X 'github.com/ZupIT/horusec/cmd/app/version.Date=${{ steps.date.outputs.date }}'" \ + -o ./tmp/horusec_mac_arm64_stand_alone ./cmd/app/main.go + + cosign sign-blob -key=$COSIGN_KEY_LOCATION \ + -output=./tmp/horusec_mac_arm64_stand_alone.sig ./tmp/horusec_mac_arm64_stand_alone env: COSIGN_PASSWORD: ${{ secrets.COSIGN_PWD }} diff --git a/Makefile b/Makefile index 3766805fb..7a8b6e863 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ ADDLICENSE ?= addlicense HORUSEC ?= horusec DOCKER_COMPOSE ?= docker-compose PATH_BINARY_BUILD_CLI ?= $(GOPATH)/bin +ARCH_ARM64 ?= arm64 +ARCH_AMD64 ?= amd64 MAIN = ./cmd/app fmt: @@ -62,6 +64,31 @@ security: build-dev: $(GO) build -o horusec $(MAIN) +build-install-cli-linux-amd64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_AMD64)" &> /dev/null + CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH_AMD64) $(GO) build -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_AMD64)" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_AMD64)" + horusec-linux-$(ARCH_AMD64) version + +build-install-cli-linux-arm64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_ARM64)" &> /dev/null + CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH_ARM64) $(GO) build -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_ARM64)" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_ARM64)" + horusec-linux-$(ARCH_ARM64) version + +build-install-cli-darwin-amd64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_AMD64)" &> /dev/null + CGO_ENABLED=0 GOOS=darwin GOARCH=$(ARCH_AMD64) $(GO) build -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_AMD64)" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_AMD64)" + horusec-mac-$(ARCH_AMD64) version + +build-install-cli-darwin-arm64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_ARM64)" &> /dev/null + CGO_ENABLED=0 GOOS=darwin GOARCH=$(ARCH_ARM64) $(GO) build -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_ARM64)" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_ARM64)" + horusec-mac-$(ARCH_ARM64) version + + build-install-cli-linux: rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-linux" &> /dev/null CGO_ENABLED=0 GOOS=linux $(GO) build -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-linux" $(MAIN) @@ -78,17 +105,29 @@ build-install-cli-windows: rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-win.exe" &> /dev/null env GOOS=windows GOARCH=amd64 $(GO) build -o "$(PATH_BINARY_BUILD_CLI)/horusec-win.exe" $(MAIN) -build-install-stand-alone-cli-linux: - rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-linux" &> /dev/null - CGO_ENABLED=0 GOOS=linux $(GO) build -ldflags "-X github.com/ZupIT/horusec/config/dist.standAlone=true" -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-linux" $(MAIN) - chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-linux" - horusec-linux version - -build-install-stand-alone-cli-darwin: - rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-mac" &> /dev/null - CGO_ENABLED=0 GOOS=darwin $(GO) build -ldflags "-X github.com/ZupIT/horusec/config/dist.standAlone=true" -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-mac" $(MAIN) - chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-mac" - horusec-mac version +build-install-stand-alone-cli-linux-amd64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_AMD64)" &> /dev/null + CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH_AMD64) $(GO) build -ldflags "-X github.com/ZupIT/horusec/config/dist.standAlone=true" -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-linux-amd64" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_AMD64)" + horusec-linux-$(ARCH_AMD64) version + +build-install-stand-alone-cli-linux-arm64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_ARM64)" &> /dev/null + CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH_ARM64) $(GO) build -ldflags "-X github.com/ZupIT/horusec/config/dist.standAlone=true" -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-linux-arm64" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-linux-$(ARCH_ARM64)" + horusec-linux-$(ARCH_ARM64) version + +build-install-stand-alone-cli-darwin-amd64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_AMD64)" &> /dev/null + CGO_ENABLED=0 GOOS=darwin GOARCH=$(ARCH_ARM64) $(GO) build -ldflags "-X github.com/ZupIT/horusec/config/dist.standAlone=true" -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-mac" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_AMD64)" + horusec-mac-$(ARCH_AMD64) version + +build-install-stand-alone-cli-darwin-arm64: + rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-mac-$(ARCH_ARM64)" &> /dev/null + CGO_ENABLED=0 GOOS=darwin GOARCH=$(ARCH_ARM64) $(GO) build -ldflags "-X github.com/ZupIT/horusec/config/dist.standAlone=true" -a -installsuffix cgo -o "$(PATH_BINARY_BUILD_CLI)/horusec-mac" $(MAIN) + chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-mac-arm64" + horusec-mac-$(ARCH_ARM64) version build-install-stand-alone-cli-windows: rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-win.exe" &> /dev/null diff --git a/deployments/scripts/install.sh b/deployments/scripts/install.sh index fe1ce3f89..502fb263b 100755 --- a/deployments/scripts/install.sh +++ b/deployments/scripts/install.sh @@ -29,6 +29,9 @@ horusecIdentifyOSLatest () { if [ "$(uname -m)" = "x86_64" ]; then echo "Installing Horusec for Linux x64" URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/${VERSION_DOWNLOAD}/download/horusec_linux_x64" + elif [ "$(uname -m)" = "aarch64" ]; then + echo "Installing Horusec for Linux arm64" + URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/${VERSION_DOWNLOAD}/download/horusec_linux_arm64" else echo "Installing Horusec for Linux x86" URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/${VERSION_DOWNLOAD}/download/horusec_linux_x86" @@ -37,6 +40,9 @@ horusecIdentifyOSLatest () { if [ "$(uname -m)" = "x86_64" ]; then echo "Installing Horusec for Mac x64" URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/${VERSION_DOWNLOAD}/download/horusec_mac_x64" + elif [ "$(uname -m)" = "arm64" ]; then + echo "Installing Horusec for Mac arm64" + URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/${VERSION_DOWNLOAD}/download/horusec_mac_arm64" else echo "Not enable Horusec to Mac x86" exit 1 @@ -52,6 +58,9 @@ horusecIdentifyOSWithVersion () { if [ "$(uname -m)" = "x86_64" ]; then echo "Installing Horusec for Linux x64" URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_linux_x64" + elif [ "$(uname -m)" = "aarch64" ]; then + echo "Installing Horusec for Linux x64" + URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_linux_arm64" else echo "Installing Horusec for Linux x86" URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_linux_x64" @@ -60,6 +69,9 @@ horusecIdentifyOSWithVersion () { if [ "$(uname -m)" = "x86_64" ]; then echo "Installing Horusec for Mac x64" URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_mac_x64" + elif [ "$(uname -m)" = "x86_64" ]; then + echo "Installing Horusec for Mac M1" + URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_mac_arm64" else echo "Not enable Horusec to Mac x86" exit 1 diff --git a/e2e/scan_languages/scan_languages_test.go b/e2e/scan_languages/scan_languages_test.go index de07c57fa..009756c07 100644 --- a/e2e/scan_languages/scan_languages_test.go +++ b/e2e/scan_languages/scan_languages_test.go @@ -45,7 +45,7 @@ func TestMain(m *testing.M) { cmd := exec.Command("go", "build", fmt.Sprintf("-o=%s", bin), path.Join(wd, "..", "..", "cmd", "app")) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "GOOS=linux") - cmd.Env = append(cmd.Env, "GOARCH=amd64") + // cmd.Env = append(cmd.Env, "GOARCH=amd64") defer func() { if err := os.Remove(bin); err != nil { diff --git a/goreleaser.yml b/goreleaser.yml index cbeeaebc5..7fedde8c9 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -27,6 +27,7 @@ builds: - darwin goarch: - amd64 + - arm64 - 386 changelog: skip: true @@ -39,6 +40,7 @@ archives: replacements: amd64: x64 386: x86 + aarch64: arm64 darwin: mac windows: win checksum: @@ -51,12 +53,18 @@ release: - glob: ./tmp/horusec_linux_x86_stand_alone.sig - glob: ./tmp/horusec_linux_x64_stand_alone - glob: ./tmp/horusec_linux_x64_stand_alone.sig + - glob: ./tmp/horusec_linux_arm64_stand_alone + - glob: ./tmp/horusec_linux_arm64_stand_alone.sig - glob: ./tmp/horusec_windows_x86_stand_alone.exe - glob: ./tmp/horusec_windows_x86_stand_alone.exe.sig - glob: ./tmp/horusec_windows_x64_stand_alone.exe - glob: ./tmp/horusec_windows_x64_stand_alone.exe.sig + - glob: ./tmp/horusec_windows_arm64_stand_alone.exe + - glob: ./tmp/horusec_windows_arm64_stand_alone.exe.sig - glob: ./tmp/horusec_mac_x64_stand_alone - glob: ./tmp/horusec_mac_x64_stand_alone.sig + - glob: ./tmp/horusec_mac_arm64_stand_alone + - glob: ./tmp/horusec_mac_arm64_stand_alone.sig nfpms: - id: horusec package_name: horusec @@ -64,6 +72,7 @@ nfpms: replacements: amd64: 64-bit 386: 32-bit + arm64: arm64 darwin: mac windows: win homepage: https://horusec.io/ @@ -91,7 +100,9 @@ docker_signs: dockers: - id: horusec goos: linux - goarch: amd64 + goarch: + - amd64 + - arm64 ids: - horusec image_templates: