diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ad765df2c..31951e023 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -139,7 +139,7 @@ jobs: version: ${{ env.GOLANGCI_VERSION }} check-diff: - runs-on: ubuntu-20.04 + runs-on: aliyun needs: detect-noop if: needs.detect-noop.outputs.noop != 'true' @@ -164,25 +164,11 @@ jobs: - name: Check code formatting run: go install golang.org/x/tools/cmd/goimports && make fmt - - name: Check Diff - run: make check-diff - - build-cli: - runs-on: ubuntu-latest - needs: detect-noop - if: needs.detect-noop.outputs.noop != 'true' - - steps: - - name: Set up Go 1.16 - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - name: Run cross-build run: make cross-build - - name: Run compress binary - run: make compress - - name: Run make reviewable - run: make reviewable + + - name: Check Diff + run: make check-diff + + - name: Cleanup binary + run: make build-cleanup diff --git a/Makefile b/Makefile index c89be499f..78a7977b7 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,9 @@ cross-build: $(GOBUILD_ENV) $(GOX) -ldflags $(LDFLAGS) -parallel=2 -output="_bin/kubectl-vela/{{.OS}}-{{.Arch}}/kubectl-vela" -osarch='$(TARGETS)' ./cmd/plugin $(GOBUILD_ENV) $(GOX) -ldflags $(LDFLAGS) -parallel=2 -output="_bin/apiserver/{{.OS}}-{{.Arch}}/apiserver" -osarch="$(TARGETS)" ./cmd/apiserver +build-cleanup: + rm -rf _bin + compress: ( \ echo "\n## Release Info\nVERSION: $(VELA_VERSION)" >> README.md && \ diff --git a/charts/vela-core/templates/defwithtemplate/apply-component.yaml b/charts/vela-core/templates/defwithtemplate/apply-component.yaml new file mode 100644 index 000000000..c49a987ef --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/apply-component.yaml @@ -0,0 +1,26 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/apply-component.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + definition.oam.dev/description: Apply components and traits for your workflow steps + name: apply-component + namespace: {{.Values.systemDefinitionNamespace}} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + // apply components and traits + apply: op.#ApplyComponent & { + component: parameter.component + } + parameter: { + // +usage=Declare the name of the component + component: string + } + diff --git a/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml b/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml new file mode 100644 index 000000000..44ae7ae8e --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/apply-remaining.yaml @@ -0,0 +1,36 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/apply-remaining.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + definition.oam.dev/description: Apply remaining components and traits + name: apply-remaining + namespace: {{.Values.systemDefinitionNamespace}} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + // apply remaining components and traits + apply: op.#ApplyRemaining & { + parameter + } + parameter: { + // +usage=Declare the name of the component + exceptions?: [componentName=string]: { + // +usage=skipApplyWorkload indicates whether to skip apply the workload resource + skipApplyWorkload: *true | bool + + // +usage=skipAllTraits indicates to skip apply all resources of the traits. + // +usage=If this is true, skipApplyTraits will be ignored + skipAllTraits: *true | bool + + // +usage=skipApplyTraits specifies the names of the traits to skip apply + skipApplyTraits: [...string] + } + } + diff --git a/charts/vela-core/templates/defwithtemplate/multi-env.yaml b/charts/vela-core/templates/defwithtemplate/multi-env.yaml new file mode 100644 index 000000000..13fb22f8c --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/multi-env.yaml @@ -0,0 +1,33 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/multi-env.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + definition.oam.dev/description: Apply env binding component + name: multi-env + namespace: {{.Values.systemDefinitionNamespace}} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + component: op.#ApplyEnvBindComponent & { + env: parameter.env + policy: parameter.policy + component: parameter.component + // context.namespace indicates the namespace of the app + namespace: context.namespace + } + parameter: { + // +usage=Declare the name of the component + component: string + // +usage=Declare the name of the policy + policy: string + // +usage=Declare the name of the env in policy + env: string + } + diff --git a/vela-templates/definitions/internal/apply-component.cue b/vela-templates/definitions/internal/apply-component.cue new file mode 100644 index 000000000..e661d35fe --- /dev/null +++ b/vela-templates/definitions/internal/apply-component.cue @@ -0,0 +1,21 @@ +import ( + "vela/op" +) + +"apply-component": { + type: "workflow-step" + annotations: {} + labels: {} + description: "Apply components and traits for your workflow steps" +} +template: { + // apply components and traits + apply: op.#ApplyComponent & { + component: parameter.component + } + + parameter: { + // +usage=Declare the name of the component + component: string + } +} diff --git a/vela-templates/definitions/internal/apply-remaining.cue b/vela-templates/definitions/internal/apply-remaining.cue new file mode 100644 index 000000000..368c8de92 --- /dev/null +++ b/vela-templates/definitions/internal/apply-remaining.cue @@ -0,0 +1,31 @@ +import ( + "vela/op" +) + +"apply-remaining": { + type: "workflow-step" + annotations: {} + labels: {} + description: "Apply remaining components and traits" +} +template: { + // apply remaining components and traits + apply: op.#ApplyRemaining & { + parameter + } + + parameter: { + // +usage=Declare the name of the component + exceptions?: [componentName=string]: { + // +usage=skipApplyWorkload indicates whether to skip apply the workload resource + skipApplyWorkload: *true | bool + + // +usage=skipAllTraits indicates to skip apply all resources of the traits. + // +usage=If this is true, skipApplyTraits will be ignored + skipAllTraits: *true | bool + + // +usage=skipApplyTraits specifies the names of the traits to skip apply + skipApplyTraits: [...string] + } + } +} diff --git a/vela-templates/definitions/internal/multi-env.cue b/vela-templates/definitions/internal/multi-env.cue new file mode 100644 index 000000000..236ad70e1 --- /dev/null +++ b/vela-templates/definitions/internal/multi-env.cue @@ -0,0 +1,28 @@ +import ( + "vela/op" +) + +"multi-env": { + type: "workflow-step" + annotations: {} + labels: {} + description: "Apply env binding component" +} +template: { + component: op.#ApplyEnvBindComponent & { + env: parameter.env + policy: parameter.policy + component: parameter.component + // context.namespace indicates the namespace of the app + namespace: context.namespace + } + + parameter: { + // +usage=Declare the name of the component + component: string + // +usage=Declare the name of the policy + policy: string + // +usage=Declare the name of the env in policy + env: string + } +} diff --git a/vela-templates/gen_definitions.sh b/vela-templates/gen_definitions.sh index 334aeec57..e4f605493 100755 --- a/vela-templates/gen_definitions.sh +++ b/vela-templates/gen_definitions.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash set -e +export IGNORE_KUBE_CONFIG=true LIGHTGRAY='\033[0;37m' GREEN='\033[0;32m' YELLOW='\033[1;33m' +RED='\033[0;31m' NC='\033[0m' HEAD_PROMPT="${LIGHTGRAY}[${0}]${NC} " @@ -17,16 +19,42 @@ REGISTRY_DEFINITION_DIR="definitions/registry" INTERNAL_TEMPLATE_DIR="../charts/vela-core/templates/defwithtemplate" REGISTRY_TEMPLATE_DIR="registry/auto-gen" +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH="" +case $(uname -m) in + i386) ARCH="386" ;; + i686) ARCH="386" ;; + x86_64) ARCH="amd64" ;; + arm) ARCH="arm64" ;; +esac + +VELA_CMD="../bin/vela" +if [ ! -f "$VELA_CMD" ]; then + VELA_CMD="../_bin/vela/$OS-$ARCH/vela" + echo -e "${HEAD_PROMPT}${LIGHTGRAY}Search cross build vela binary in ${VELA_CMD}.${NC}" +fi +if [ ! -f "$VELA_CMD" ]; then + echo -e "${HEAD_PROMPT}${YELLOW}Failed to get vela command, fallback to use \`go run\`.${NC}" + VELA_CMD="go run ../references/cmd/cli/main.go" +else + echo -e "${HEAD_PROMPT}${GREEN}Got vela command binary." + $VELA_CMD version +fi + function render { inputDir=$1 outputDir=$2 rm "$outputDir"/* 2>/dev/null || true mkdir -p "$outputDir" - go run ../references/cmd/cli/main.go def render "$inputDir" -o "$outputDir" --message "Definition source cue file: vela-templates/$inputDir/{{INPUT_FILENAME}}" + $VELA_CMD def render "$inputDir" -o "$outputDir" --message "Definition source cue file: vela-templates/$inputDir/{{INPUT_FILENAME}}" + retVal=$? + if [ $retVal -ne 0 ]; then + echo -ne "${RED}Failed. Exit code: ${retVal}.${NC}\n" + exit $retVal + fi } echo -e "${HEAD_PROMPT}Start generating definitions at ${LIGHTGRAY}${SCRIPT_DIR}${NC} ..." -export IGNORE_KUBE_CONFIG=true echo -ne "${HEAD_PROMPT}${YELLOW}(0/2) Generating internal definitions from ${LIGHTGRAY}${INTERNAL_DEFINITION_DIR}${YELLOW} to ${LIGHTGRAY}${INTERNAL_TEMPLATE_DIR}${YELLOW} ... " export AS_HELM_CHART=true render $INTERNAL_DEFINITION_DIR $INTERNAL_TEMPLATE_DIR