Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrareddyp committed Feb 16, 2024
1 parent 52e4099 commit 752d16e
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 53 deletions.
69 changes: 55 additions & 14 deletions .github/workflows/cli_core_e2e_windows_test_msys2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ jobs:
restore-keys: |
${{ runner.os }}-go-${{ steps.go.outputs.go-version }}-
- name: Set and Echo GOPATH and GOBIN
run: |
$GOPATH = go env GOPATH
$GOBIN = "$GOPATH\bin"
echo "GOPATH 1 is set to $GOPATH"
echo "GOBIN 1 is set to $GOBIN"
echo "GOPATH=$GOPATH" | Out-File -Append -FilePath $env:GITHUB_ENV
echo "GOBIN=$GOBIN" | Out-File -Append -FilePath $env:GITHUB_ENV
echo "GOPATH 2 is set to $GOPATH"
echo "GOBIN 2 is set to $GOBIN"
shell: pwsh

- name: Echo Go installation path
run: |
echo "Go installation path: $(go env GOROOT)"
ls "$(go env GOROOT)"
ls "$(go env GOROOT)\bin"
shell: bash

- name: Echo GOPATH and GOBIN
run: |
echo "GOPATH=$env:GOPATH"
echo "GOBIN=$env:GOBIN"
echo "Contents of GOPATH:"
Get-ChildItem -Path $env:GOPATH
echo "Contents of GOBIN:"
Get-ChildItem -Path $env:GOBIN
shell: pwsh

- name: Install MSYS2
run: choco install msys2
shell: powershell
Expand All @@ -49,30 +78,42 @@ jobs:
run: C:\tools\msys64\usr\bin\bash -lc "echo 'Hello from MSYS2'"
shell: powershell

- name: Install Make in MSYS2
- name: Install Make and Unzip in MSYS2
run: |
C:\tools\msys64\usr\bin\bash -lc "pacman -S make --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S unzip --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S make unzip --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S make wget --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S make bzip2 --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "wget --version"
C:\tools\msys64\usr\bin\bash -lc "bzip2 --version"
shell: powershell

- name: Run Unix Commands in MSYS2
run: |
C:\tools\msys64\usr\bin\bash -lc "echo 'Hello from MSYS2'"
C:\tools\msys64\usr\bin\bash -lc "ls"
C:\tools\msys64\usr\bin\bash -lc "pwd"
C:\tools\msys64\usr\bin\bash -lc "go version"
C:\tools\msys64\usr\bin\bash -lc "wget --version"
C:\tools\msys64\usr\bin\bash -lc "bzip2 --version"
$WGET = $(Get-Command wget).Source
$BZIP2 = $(Get-Command bzip2).Source
echo "WGET_PATH=$WGET" >> $env:GITHUB_ENV
echo "BZIP2_PATH=$BZIP2" >> $env:GITHUB_ENV
echo "WGET_PATH: $WGET"
echo "BZIP2_PATH: $BZIP2"
$msysBin = "C:\tools\msys64\usr\bin"
echo "MSYS_BIN=$msysBin" >> $env:GITHUB_ENV
echo "PATH info: $env:PATH"
echo "PATH info2: $PATH"
shell: powershell

- name: Setup dependencies
- name: Build CLI Core
run: |
topLevel=$(git rev-parse --show-toplevel)
echo "Top level: $topLevel"
make build
shell: powershell

# Set up PATH to include Go binaries
export PATH=$PATH:/c/go/bin:$(go env GOPATH)/bin
C:/tools/msys64/usr/bin/bash -lc "cd '$topLevel' && make tools"
- name: E2E Tests
run: |
C:\tools\msys64\usr\bin\bash -lc "wget --version"
C:\tools\msys64\usr\bin\bash -lc "bzip2 --version"
make e2e-cli-core
shell: powershell
env:
MSYS2_PATH_TYPE: inherit # This might help inheriting the PATH correctly

114 changes: 96 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ include ./plugin-tooling.mk
include ./test/e2e/Makefile

# Ensure Make is run with bash shell as some syntax below is bash-specific
SHELL := /usr/bin/env bash

ROOT_DIR := $(shell git rev-parse --show-toplevel)
ROOT_DIR := $(subst \,/,$(ROOT_DIR))
ARTIFACTS_DIR ?= $(ROOT_DIR)/artifacts

HOME := $(subst \,/,$(HOME))
XDG_CONFIG_HOME := ${HOME}/.config
export XDG_CONFIG_HOME

Expand All @@ -18,6 +19,34 @@ GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
HOST_OS=$(shell go env GOOS)

WGET := $(shell which wget)
BZIP2 := $(shell which bzip2)
TAR := $(shell which tar)

# Load environment variables from GitHub workflow
ifeq ($(GITHUB_ACTIONS),true)
ifeq ($(GOOS),windows)
# Use the values from GitHub Actions
MSYS_BIN ?= $(shell echo $MSYS_BIN)
WGET = $(MSYS_BIN)/wget
BZIP2 = $(MSYS_BIN)/bzip2
TAR = $(MSYS_BIN)/tar
GITHUB_INFO := Running in GitHub Actions on Windows
endif
endif

# Ensure $(GOPATH) uses forward slashes
WGET := $(subst \,/,$(WGET))
BZIP2 := $(subst \,/,$(BZIP2))
TAR := $(subst \,/,$(TAR))

$(info WGET after update: $(WGET))
$(info BZIP2 after update: $(BZIP2))
$(info TAR after update: $(TAR))
$(info $(GITHUB_INFO))


# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -54,7 +83,10 @@ VENDIR := $(TOOLS_BIN_DIR)/vendir
YQ := $(TOOLS_BIN_DIR)/yq

#TOOLING_BINARIES := $(GOIMPORTS) $(GOLANGCI_LINT) $(VALE) $(MISSPELL) $(CONTROLLER_GEN) $(IMGPKG) $(KUBECTL) $(KIND) $(GINKGO) $(COSIGN) $(GOJUNITREPORT)
TOOLING_BINARIES := $(GOLANGCI_LINT)
TOOLING_BINARIES := $(GOIMPORTS) $(GOLANGCI_LINT) $(VALE) $(MISSPELL) $(CONTROLLER_GEN) $(IMGPKG) $(KUBECTL) $(KIND) $(GINKGO) $(COSIGN) $(GOJUNITREPORT)
#TOOLING_BINARIES := $(GOIMPORTS)

#TOOLING_BINARIES := $(GOLANGCI_LINT)

# Build and version information

Expand Down Expand Up @@ -145,17 +177,19 @@ build-cli-%: ##Build the Tanzu Core CLI for a platform

@echo build $(OS)-$(ARCH) CLI with version: $(BUILD_VERSION)

@if [ "$(filter $(OS)-$(ARCH),$(ENVS))" = "" ]; then\
printf "\n\n======================================\n";\
printf "! $(OS)-$(ARCH) is not an officially supported platform!\n";\
printf "======================================\n\n";\
fi
@mkdir -p artifacts/$(OS)/$(ARCH)/cli/core/$(BUILD_VERSION)

@if [ "$(OS)" = "windows" ]; then \
GOOS=$(OS) GOARCH=$(ARCH) $(GO) build -gcflags=all="-l" --ldflags "$(LD_FLAGS)" -o "$(ARTIFACTS_DIR)/$(OS)/$(ARCH)/cli/core/$(BUILD_VERSION)/tanzu-cli-$(OS)_$(ARCH).exe" ./cmd/tanzu/main.go;\
else \
GOOS=$(OS) GOARCH=$(ARCH) $(GO) build -gcflags=all="-l" --ldflags "$(LD_FLAGS)" -o "$(ARTIFACTS_DIR)/$(OS)/$(ARCH)/cli/core/$(BUILD_VERSION)/tanzu-cli-$(OS)_$(ARCH)" ./cmd/tanzu/main.go;\
fi
@echo "Listing artifacts directory:"
@ls artifacts

@echo "BEfore build"
@echo "Windows build"
@pwd
@cd cmd/tanzu
@pwd
@go build -o $(ARTIFACTS_DIR)/$(OS)/$(ARCH)/cli/core/$(BUILD_VERSION)/tanzu-cli-$(OS)_$(ARCH).exe cmd/tanzu/main.go
@ls cmd/tanzu
@ls $(ARTIFACTS_DIR)/$(OS)/$(ARCH)/cli/core/$(BUILD_VERSION)

## --------------------------------------
## Plugins-specific
Expand Down Expand Up @@ -255,28 +289,54 @@ test-with-summary-report: tools
.PHONY: e2e-cli-core ## Execute all CLI Core E2E Tests
e2e-cli-core: tools crd-package-for-test start-test-central-repo start-airgapped-local-registry e2e-cli-core-all ## Execute all CLI Core E2E Tests


.PHONY: setup-custom-cert-for-test-central-repo
setup-custom-cert-for-test-central-repo: ## Setup up the custom ca cert for test-central-repo in the config file
@if [ ! -d $(ROOT_DIR)/hack/central-repo/certs ]; then \
wget https://storage.googleapis.com/tanzu-cli/data/testcerts/local-central-repo-testcontent.bz2 -O $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2;\
tar xjf $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2 -C $(ROOT_DIR)/hack/central-repo/;\
fi
@echo "ROOT_DIR inside setup-custom-cert-for-test-central-repo: $(ROOT_DIR)"
@echo "WGET inside setup-custom-cert-for-test-central-repo: $(WGET)"
@echo "BZIP2 inside setup-custom-cert-for-test-central-repo: $(BZIP2)"
$(WGET) https://storage.googleapis.com/tanzu-cli/data/testcerts/local-central-repo-testcontent.bz2 -O hack/central-repo/local-central-repo-testcontent.bz2
$(TAR) xjf hack/central-repo/local-central-repo-testcontent.bz2 -C hack/central-repo/
@echo "Listing the contents of the hack/central-repo"
@ls -l hack/central-repo
@echo "current directory: $(PWD) files: $(ls)"
@ls
echo "Adding docker test central repo cert to the config file"
TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="No" TANZU_CLI_EULA_PROMPT_ANSWER="Yes" $(ROOT_DIR)/bin/tanzu config cert delete localhost:9876 || true
$(ROOT_DIR)/bin/tanzu config cert add --host localhost:9876 --ca-cert $(ROOT_DIR)/hack/central-repo/certs/localhost.crt

.PHONY: start-test-central-repo
start-test-central-repo: stop-test-central-repo setup-custom-cert-for-test-central-repo ## Starts up a test central repository locally with docker
@if [ ! -d $(ROOT_DIR)/hack/central-repo/registry-content ]; then \
(cd $(ROOT_DIR)/hack/central-repo && $(TAR) xjf registry-content.bz2 || true;) \
fi
@echo "Starting docker test central repo"

@docker run --rm -d -p 9876:443 --name central \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/localhost.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/localhost.key \
-v "D:\a\tanzu-cli\tanzu-cli\hack\central-repo\registry-content:C:\registry" \
-v "D:\a\tanzu-cli\tanzu-cli\hack\central-repo\certs:C:\certs" \
stefanscherer/registry-windows:latest > /dev/null && \
echo "Started docker test central repo with images:" && \
$(ROOT_DIR)/hack/central-repo/upload-plugins.sh info

@echo "Docker test central repo started at localhost:9876"

.PHONY: start-test-central-repo-11
start-test-central-repo: stop-test-central-repo setup-custom-cert-for-test-central-repo ## Starts up a test central repository locally with docker
@if [ ! -d $(ROOT_DIR)/hack/central-repo/registry-content ]; then \
(cd $(ROOT_DIR)/hack/central-repo && tar xjf registry-content.bz2 || true;) \
fi
@echo "Starting docker test central repo"
@docker run --rm -d -p 9876:443 --name central \
-v $(ROOT_DIR)/hack/central-repo/certs:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/localhost.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/localhost.key \
-v $(ROOT_DIR)/hack/central-repo/registry-content:/var/lib/registry \
$(REGISTRY_IMAGE) > /dev/null && \
stefanscherer/registry-windows:latest > /dev/null && \
echo "Started docker test central repo with images:" && \
$(ROOT_DIR)/hack/central-repo/upload-plugins.sh info

Expand All @@ -285,7 +345,24 @@ stop-test-central-repo: ## Stops and removes the local test central repository
@docker container stop central > /dev/null 2>&1 && echo "Stopped docker test central repo" || true

.PHONY: start-airgapped-local-registry
start-airgapped-local-registry: stop-airgapped-local-registry
start-airgapped-local-registry-11: stop-airgapped-local-registry
@docker run --rm -d -p 6001:5000 --name temp-airgapped-local-registry \
$(REGISTRY_IMAGE) > /dev/null && \
echo "Started docker test airgapped repo at 'localhost:6001'."

@mkdir -p $(ROOT_DIR)/hack/central-repo/auth && docker run --entrypoint htpasswd httpd:2 -Bbn ${TANZU_CLI_E2E_AIRGAPPED_REPO_WITH_AUTH_USERNAME} ${TANZU_CLI_E2E_AIRGAPPED_REPO_WITH_AUTH_PASSWORD} > $(ROOT_DIR)/hack/central-repo/auth/htpasswd
@docker run --rm -d -p 6002:5000 --name temp-airgapped-local-registry-with-auth \
-v "D:\a\tanzu-cli\tanzu-cli\hack\central-repo\auth:C:\auth" \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
stefanscherer/registry-windows:latest > /dev/null && \
echo "Started docker test airgapped repo with authentication at 'localhost:6002'."

@docker logout localhost:6002 || true

.PHONY: start-airgapped-local-registry-11
start-airgapped-local-registry-11: stop-airgapped-local-registry
@docker run --rm -d -p 6001:5000 --name temp-airgapped-local-registry \
$(REGISTRY_IMAGE) > /dev/null && \
echo "Started docker test airgapped repo at 'localhost:6001'."
Expand All @@ -301,6 +378,7 @@ start-airgapped-local-registry: stop-airgapped-local-registry

@docker logout localhost:6002 || true


.PHONY: stop-airgapped-local-registry
stop-airgapped-local-registry:
@docker stop temp-airgapped-local-registry temp-airgapped-local-registry-with-auth > /dev/null 2>&1 && \
Expand Down
Loading

0 comments on commit 752d16e

Please sign in to comment.