diff --git a/.air.toml b/.air.toml new file mode 100644 index 000000000..6e7c00ba4 --- /dev/null +++ b/.air.toml @@ -0,0 +1,52 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = ".tmp" + +[build] + args_bin = [] + bin = "./dist/portainer" + cmd = "SKIP_GO_GET=true make build-server" + delay = 1000 + exclude_dir = [] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "./dist/portainer --log-level=DEBUG" + include_dir = ["api"] + include_ext = ["go"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + silent = false + time = false + +[misc] + clean_on_exit = false + +[proxy] + app_port = 0 + enabled = false + proxy_port = 0 + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/Makefile b/Makefile index 9f9346f12..47c29001e 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,13 @@ GOTESTSUM=go run gotest.tools/gotestsum@latest ##@ Building -.PHONY: init-dist build-storybook build build-client build-server build-image devops +.PHONY: all init-dist build-storybook build build-client build-server build-image devops init-dist: @mkdir -p dist -build-all: deps build-server build-client ## Build the client, server and download external dependancies (doesn't build an image) +all: tidy deps build-server build-client ## Build the client, server and download external dependancies (doesn't build an image) + +build-all: all ## Alias for the 'all' target (used by CI) build-client: init-dist ## Build the client export NODE_ENV=$(ENV) && yarn build --config $(WEBPACK_CONFIG) @@ -50,7 +52,7 @@ client-deps: ## Install client dependencies yarn tidy: ## Tidy up the go.mod file - cd api && go mod tidy + @go mod tidy ##@ Cleanup diff --git a/build/build_binary.sh b/build/build_binary.sh index 402323923..6f87cd939 100755 --- a/build/build_binary.sh +++ b/build/build_binary.sh @@ -32,8 +32,14 @@ cp -r "./mustache-templates" "./dist" cd api || exit 1 -# the go get adds 8 seconds -go get -t -d -v ./... + +# Conditionally run go get based on the SKIP_GO_GET environment variable +# This process adds a bit of time to the build +# This is useful in the CI/CD pipeline to ensure that all dependencies are available +if [ "${SKIP_GO_GET:-false}" = false ]; then + echo "Running go get -t -v ./..." + go get -t -v ./... +fi ldflags="-s -X 'github.com/portainer/liblicense.LicenseServerBaseURL=https://api.portainer.io' \ @@ -51,7 +57,6 @@ ldflags="-s -X 'github.com/portainer/liblicense.LicenseServerBaseURL=https://api echo "$ldflags" -# the build takes 2 seconds GOOS=${1:-$(go env GOOS)} GOARCH=${2:-$(go env GOARCH)} CGO_ENABLED=0 go build \ -trimpath \ --installsuffix cgo \ diff --git a/build/download_binaries.sh b/build/download_binaries.sh index 815f878f9..75e571a20 100755 --- a/build/download_binaries.sh +++ b/build/download_binaries.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash set -euo pipefail - PLATFORM=${1:-"linux"} ARCH=${2:-"amd64"} @@ -14,10 +13,49 @@ mingitVersion=$(jq -r '.mingit' < "${BINARY_VERSION_FILE}") mkdir -p dist -echo "Downloading binaries for docker ${dockerVersion}, helm ${helmVersion}, kubectl ${kubectlVersion} and mingit ${mingitVersion}" +echo "Checking and downloading binaries for docker ${dockerVersion}, helm ${helmVersion}, kubectl ${kubectlVersion} and mingit ${mingitVersion} (Windows only)" -./build/download_docker_binary.sh "$PLATFORM" "$ARCH" "$dockerVersion" & -./build/download_helm_binary.sh "$PLATFORM" "$ARCH" "$helmVersion" & -./build/download_kubectl_binary.sh "$PLATFORM" "$ARCH" "$kubectlVersion" & -./build/download_mingit_binary.sh "$PLATFORM" "$ARCH" "$mingitVersion" & -wait +# Determine the binary file names based on the platform +dockerBinary="dist/docker" +helmBinary="dist/helm" +kubectlBinary="dist/kubectl" + +if [ "$PLATFORM" == "windows" ]; then + dockerBinary="dist/docker.exe" + helmBinary="dist/helm.exe" + kubectlBinary="dist/kubectl.exe" +fi + +# Check and download docker binary +if [ ! -f "$dockerBinary" ]; then + echo "Downloading docker binary..." + /usr/bin/env bash ./build/download_docker_binary.sh "$PLATFORM" "$ARCH" "$dockerVersion" +else + echo "Docker binary already exists, skipping download." +fi + +# Check and download helm binary +if [ ! -f "$helmBinary" ]; then + echo "Downloading helm binary..." + /usr/bin/env bash ./build/download_helm_binary.sh "$PLATFORM" "$ARCH" "$helmVersion" +else + echo "Helm binary already exists, skipping download." +fi + +# Check and download kubectl binary +if [ ! -f "$kubectlBinary" ]; then + echo "Downloading kubectl binary..." + /usr/bin/env bash ./build/download_kubectl_binary.sh "$PLATFORM" "$ARCH" "$kubectlVersion" +else + echo "Kubectl binary already exists, skipping download." +fi + +# Check and download mingit binary only for Windows +if [ "$PLATFORM" == "windows" ]; then + if [ ! -f "dist/mingit" ]; then + echo "Downloading mingit binary..." + /usr/bin/env bash ./build/download_mingit_binary.sh "$PLATFORM" "$ARCH" "$mingitVersion" + else + echo "Mingit binary already exists, skipping download." + fi +fi diff --git a/lint-staged.config.js b/lint-staged.config.js index 2dca01137..0f6be7f5d 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,6 +1,6 @@ module.exports = { - '*.(js|ts){,x}': 'eslint --cache --fix', + '*.(js|ts){,x}': 'yarn lint', '*.(ts){,x}': () => 'tsc --noEmit', - '*.{js,ts,tsx,css,md,html,json}': 'prettier --write', + '*.{js,ts,tsx,css,md,html,json}': 'yarn format', '*.go': () => 'make lint-server', }; diff --git a/package.json b/package.json index e38f098c5..a10a1c945 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "build": "webpack", "format": "prettier --log-level warn --write \"**/*.{js,css,html,jsx,tsx,ts,json}\"", "lint": "eslint --cache --fix './**/*.{js,jsx,ts,tsx}'", - "test": "vitest", + "test": "vitest run", "sb": "yarn storybook", "storybook": "storybook dev -p 6006", "storybook:build": "storybook build -o ./dist/storybook",