Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghang8421 committed Oct 22, 2024
1 parent 5e2932b commit ad3d551
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 72 deletions.
1 change: 1 addition & 0 deletions .github/actions/setup-build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ runs:
- id: vars
shell: bash
run: |
ls -l
source scripts/export-config
CATTLE_KDM_BRANCH=$(grep -m1 'ARG CATTLE_KDM_BRANCH=' package/Dockerfile | cut -d '=' -f2)
CATTLE_K3S_VERSION=$(grep -m1 'ENV CATTLE_K3S_VERSION' package/Dockerfile | awk '{print $3}')
Expand Down
147 changes: 84 additions & 63 deletions .github/workflows/push-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: build-docker-images
on:
push:
branches:
- "master"
- "release/v*"
- "!release/v2.9-gha-test"
tags:
- "v*"
env:
Expand All @@ -13,11 +12,22 @@ env:
IMAGE_AGENT: ${{ github.repository_owner }}/rancher-agent
IMAGE_INSTALLER: ${{ github.repository_owner }}/system-agent-installer-rancher
jobs:
unit-tests:
uses: ./.github/workflows/unit-test.yml
# unit-tests:
# uses: ./.github/workflows/unit-test.yml
build-chart:
runs-on: ubuntu-latest
if: false
runs-on: test-runner-1
container: ubuntu:22.04
steps:
- name: Install tools
run: |
export TZ=Asia/Kolkata
export DEBIAN_FRONTEND=noninteractive
apt update && apt install -y --no-install-recommends curl git-all sudo
curl -sLf https://github.com/mikefarah/yq/releases/download/v4.40.2/yq_linux_amd64.tar.gz -o yq_linux_amd64.tar.gz
tar zxvf yq_linux_amd64.tar.gz
mv yq_linux_amd64 /usr/bin/yq
git config --global --add safe.directory '*'
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Tag Env Variables
Expand All @@ -30,7 +40,7 @@ jobs:
HELM_URL: https://get.helm.sh/helm-${{ steps.env.outputs.HELM_VERSION }}-linux-amd64.tar.gz
HELM_UNITTEST_VERSION: ${{ steps.env.outputs.HELM_UNITTEST_VERSION }}
run: |
sudo snap install yq
# sudo snap install yq
curl ${{ env.HELM_URL }} | tar xvzf - --strip-components=1 -C /tmp/ && \
sudo mv /tmp/helm /usr/bin/helm_v3 && \
sudo chmod +x /usr/bin/helm_v3
Expand All @@ -52,7 +62,7 @@ jobs:
retention-days: 1
overwrite: true
publish-chart:
runs-on: ubuntu-latest
runs-on: test-runner-1
needs: [build-chart, push-images]
if: github.event_name == 'push' && contains(github.ref, 'tags/') # Only run on push
permissions:
Expand Down Expand Up @@ -84,12 +94,22 @@ jobs:
headers: |-
cache-control: public,no-cache,proxy-revalidate
build-server:
runs-on: ubuntu-latest
# container: summerwind/actions-runner-dind:ubuntu-22.04
runs-on: test-runner-dind
strategy:
matrix:
os: [linux]
arch: [amd64, arm64]
arch: [amd64]
steps:
- name: Install tools
run: |
export TZ=Asia/Kolkata
export DEBIAN_FRONTEND=noninteractive
sudo apt update && sudo apt install -y --no-install-recommends curl git-all
sudo curl -sLf https://github.com/mikefarah/yq/releases/download/v4.40.2/yq_linux_amd64.tar.gz -o yq_linux_amd64.tar.gz
sudo tar zxvf yq_linux_amd64.tar.gz
sudo mv yq_linux_amd64 /usr/bin/yq
git config --global --add safe.directory '*'
- name: Checkout code
uses: actions/checkout@v4
# Cleaning the runner is important to free enough space to build rancher, otherwise the build will fail
Expand Down Expand Up @@ -152,7 +172,7 @@ jobs:
overwrite: false
build-agent:
needs: [build-server]
runs-on: ubuntu-latest
runs-on: test-runner-1
strategy:
matrix:
os: [linux]
Expand Down Expand Up @@ -236,45 +256,46 @@ jobs:
if-no-files-found: error
retention-days: 1
overwrite: false
integration-tests:
needs: [build-agent]
uses: ./.github/workflows/integration-tests.yml
with:
parent_run_id: ${{ github.run_id }}
build-agent-windows:
needs: [integration-tests]
strategy:
matrix:
os: [windows]
version: [2019, 2022]
runs-on: ${{ matrix.os }}-${{ matrix.version }}
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Environment Variables
uses: ./.github/actions/setup-tag-env
- name: Load Secrets from Vault
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Build Windows Server Image
run: |
docker build -t ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }} --build-arg VERSION=${{ env.TAG }} --build-arg SERVERCORE_VERSION=ltsc${{ matrix.version }} -f package/windows/Dockerfile.agent .
docker push ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }}
shell: bash
# integration-tests:
# needs: [build-agent]
# uses: ./.github/workflows/integration-tests.yml
# with:
# parent_run_id: ${{ github.run_id }}
# build-agent-windows:
# needs: [integration-tests]
# strategy:
# matrix:
# os: [windows]
# version: [2019, 2022]
# runs-on: ${{ matrix.os }}-${{ matrix.version }}
# permissions:
# contents: read
# id-token: write
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Environment Variables
# uses: ./.github/actions/setup-tag-env
# - name: Load Secrets from Vault
# uses: rancher-eio/read-vault-secrets@main
# with:
# secrets: |
# secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
# secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ env.DOCKER_USERNAME }}
# password: ${{ env.DOCKER_PASSWORD }}
# - name: Build Windows Server Image
# run: |
# docker build -t ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }} --build-arg VERSION=${{ env.TAG }} --build-arg SERVERCORE_VERSION=ltsc${{ matrix.version }} -f package/windows/Dockerfile.agent .
# docker push ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }}
# shell: bash
push-images:
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests]
runs-on: test-runner-1
# needs: [unit-tests]
if: false
permissions:
contents: read
id-token: write
Expand Down Expand Up @@ -323,7 +344,7 @@ jobs:
docker tag "$image_agent_id" docker.io/${{ env.IMAGE_AGENT }}:${{ env.TAG }}-${{ matrix.arch }}
docker push docker.io/${{ env.IMAGE_AGENT }}:${{ env.TAG }}-${{ matrix.arch }}
merge-server-manifest:
runs-on: ubuntu-latest
runs-on: test-runner-1
needs: [push-images]
permissions:
contents: read
Expand Down Expand Up @@ -358,8 +379,8 @@ jobs:
run: |
docker buildx imagetools inspect ${{ env.IMAGE }}:${{ env.TAG }}
merge-agent-manifest:
runs-on: ubuntu-latest
needs: [push-images, build-agent-windows]
runs-on: test-runner-1
needs: [push-images]
permissions:
contents: read
id-token: write
Expand All @@ -384,21 +405,21 @@ jobs:
- name: Create manifest list and push
run: |
# docker manifest is used with windows images to maintain os.version in the manifest
docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.TAG }} \
${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \
${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022
# docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.TAG }} \
# ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \
# ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022
docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.TAG }}
# docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.TAG }}
docker buildx imagetools create -t ${{ env.IMAGE_AGENT }}:${{ env.TAG }} \
--append ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-amd64 \
--append ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-arm64
if [[ "${{ github.ref_name }}" == release/v* ]]; then
docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} \
${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \
${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022
docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }}
# docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} \
# ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \
# ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022
# docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }}
docker buildx imagetools create -t ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} \
--append ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-amd64 \
Expand All @@ -411,7 +432,7 @@ jobs:
needs:
- merge-server-manifest
- build-chart
runs-on: ubuntu-latest
runs-on: test-runner-1
strategy:
matrix:
os: [linux]
Expand Down Expand Up @@ -470,7 +491,7 @@ jobs:
file: ./package/Dockerfile.installer
labels: "${{ steps.meta.outputs.labels }}"
merge-installer-manifest:
runs-on: ubuntu-latest
runs-on: test-runner-1
needs: [build-installer]
permissions:
contents: read
Expand Down Expand Up @@ -511,7 +532,7 @@ jobs:
docker buildx imagetools inspect ${{ env.IMAGE_INSTALLER }}:${{ env.TAG }}
create-images-files:
if: github.event_name == 'push' && contains(github.ref, 'tags/') # Only run on push
runs-on: ubuntu-latest
runs-on: test-runner-1
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -545,7 +566,7 @@ jobs:
run: gh release upload -R ${{ env.REPOSITORY_OWNER }}/rancher ${{ env.TAG }} ./dist/* --clobber
docker-image-digests:
if: github.event_name == 'push' && contains(github.ref, 'tags/') # Only run on tag
runs-on: ubuntu-latest
runs-on: test-runner-1
needs: [create-images-files]
env:
DOCKER_REGISTRY: "docker.io"
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Unit Tests
on: [workflow_dispatch, workflow_call]
jobs:
unit-test:
runs-on: ubuntu-latest
env:
GOLANG_VERSION: '1.22'
runs-on: test-runner-1
timeout-minutes: 60
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "${{ env.GOLANG_VERSION }}"
- name: Run unit tests
run: go test -cover -tags=test ./pkg/...

12 changes: 12 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ name: Validate
on: [pull_request, push]
jobs:
validate:
if: false
runs-on: test-runner-1
container: ubuntu:22.04
env:
GOLANG_CI_LINT_VERSION: v1.54.2
PYTHON_VERSION: '3.11'
GOLANG_VERSION: '1.22'
steps:
- name: Install tools
run: |
export TZ=Asia/Kolkata
export DEBIAN_FRONTEND=noninteractive
apt update && apt install -y --no-install-recommends unzip curl sudo ca-certificates git-all
git config --global --add safe.directory '/__w/rancher/rancher'
- name: Checkout code
uses: actions/checkout@v4
- name: Uninstall existing Python versions
Expand All @@ -30,6 +38,10 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "${{ env.GOLANG_VERSION }}"
- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin "v1.59.0"
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/spectrometer/master/install.sh | sh
- name: Install Python and dependencies
run: |
sudo apt-get update
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/verify-generated-code-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ env:

jobs:
check-changes:
runs-on: ubuntu-latest

if: false
runs-on: test-runner-1
container: ubuntu:22.04
steps:
- name: Install tools
run: |
export TZ=Asia/Kolkata
export DEBIAN_FRONTEND=noninteractive
apt update && apt install -y --no-install-recommends curl sudo ca-certificates git-all
git config --global --add safe.directory '/__w/rancher/rancher'
-
uses: actions/checkout@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions scripts/export-config
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ if [ -n "$DEBUG" ]; then
set -x
fi

echo "before git"

file="$(git rev-parse --show-toplevel)/build.yaml"

echo "after git"

CATTLE_RANCHER_WEBHOOK_VERSION=$(yq -e '.webhookVersion' "$file")
CATTLE_RANCHER_PROVISIONING_CAPI_VERSION=$(yq -e '.provisioningCAPIVersion' "$file")
CATTLE_CSP_ADAPTER_MIN_VERSION=$(yq -e '.cspAdapterMinVersion' "$file")
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if ! command -v golangci-lint; then
fi

echo Running: golangci-lint
golangci-lint run
golangci-lint run --timeout=20m

echo Tidying up modules
cd pkg/apis/
Expand Down
5 changes: 3 additions & 2 deletions tests/v2/validation/steve/vai/secret_sort_test_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package vai

import (
"fmt"
namegen "github.com/rancher/shepherd/pkg/namegenerator"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/url"
"sort"
"strings"

namegen "github.com/rancher/shepherd/pkg/namegenerator"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "k8s.io/api/core/v1"
)

Expand Down
5 changes: 3 additions & 2 deletions tests/v2/validation/steve/vai/vai.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package vai

import (
"fmt"
"github.com/rancher/shepherd/clients/rancher"
"github.com/rancher/shepherd/extensions/vai"
"strings"
"sync"

"github.com/rancher/shepherd/clients/rancher"
"github.com/rancher/shepherd/extensions/vai"
)

const (
Expand Down

0 comments on commit ad3d551

Please sign in to comment.