diff --git a/.github/workflows/golang-test-darwin.yml b/.github/workflows/golang-test-darwin.yml new file mode 100644 index 000000000..7bfbe02cd --- /dev/null +++ b/.github/workflows/golang-test-darwin.yml @@ -0,0 +1,32 @@ +name: Test Code Darwin + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: macos-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: macos-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + macos-go- + + - name: Install modules + run: go mod tidy + + - name: Test + run: go test -exec 'sudo --preserve-env=CI' -timeout 5m -p 1 ./... diff --git a/.github/workflows/golang-test-linux.yml b/.github/workflows/golang-test-linux.yml new file mode 100644 index 000000000..b198009be --- /dev/null +++ b/.github/workflows/golang-test-linux.yml @@ -0,0 +1,92 @@ +name: Test Code Linux + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + strategy: + matrix: + arch: ['386','amd64'] + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install dependencies + run: sudo apt update && sudo apt install -y -q libgtk-3-dev libayatana-appindicator3-dev libgl1-mesa-dev xorg-dev gcc-multilib + + - name: Install modules + run: go mod tidy + + - name: Test + run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} go test -exec 'sudo --preserve-env=CI' -timeout 5m -p 1 ./... + + test_client_on_docker: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install dependencies + run: sudo apt update && sudo apt install -y -q libgtk-3-dev libayatana-appindicator3-dev libgl1-mesa-dev xorg-dev + + - name: Install modules + run: go mod tidy + + - name: Generate Iface Test bin + run: go test -c -o iface-testing.bin ./iface/ + + - name: Generate RouteManager Test bin + run: go test -c -o routemanager-testing.bin ./client/internal/routemanager/... + + - name: Generate Engine Test bin + run: go test -c -o engine-testing.bin ./client/internal + + - name: Generate Peer Test bin + run: go test -c -o peer-testing.bin ./client/internal/peer/... + + - run: chmod +x *testing.bin + + - name: Run Iface tests in docker + run: docker run -t --cap-add=NET_ADMIN --privileged --rm -v $PWD:/ci -w /ci/iface --entrypoint /busybox/sh gcr.io/distroless/base:debug -c /ci/iface-testing.bin -test.timeout 5m -test.parallel 1 + + - name: Run RouteManager tests in docker + run: docker run -t --cap-add=NET_ADMIN --privileged --rm -v $PWD:/ci -w /ci/client/internal/routemanager --entrypoint /busybox/sh gcr.io/distroless/base:debug -c /ci/routemanager-testing.bin -test.timeout 5m -test.parallel 1 + + - name: Run Engine tests in docker + run: docker run -t --cap-add=NET_ADMIN --privileged --rm -v $PWD:/ci -w /ci/client/internal --entrypoint /busybox/sh gcr.io/distroless/base:debug -c /ci/engine-testing.bin -test.timeout 5m -test.parallel 1 + + - name: Run Peer tests in docker + run: docker run -t --cap-add=NET_ADMIN --privileged --rm -v $PWD:/ci -w /ci/client/internal/peer --entrypoint /busybox/sh gcr.io/distroless/base:debug -c /ci/peer-testing.bin -test.timeout 5m -test.parallel 1 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..956d37936 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,18 @@ +name: golangci-lint +on: [pull_request] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + - name: Install dependencies + run: sudo apt update && sudo apt install -y -q libgtk-3-dev libayatana-appindicator3-dev libgl1-mesa-dev xorg-dev + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + args: --timeout=6m \ No newline at end of file diff --git a/.github/workflows/install-test-darwin.yml b/.github/workflows/install-test-darwin.yml new file mode 100644 index 000000000..cdf0cae5a --- /dev/null +++ b/.github/workflows/install-test-darwin.yml @@ -0,0 +1,58 @@ +name: Test installation Darwin + +on: + push: + branches: + - main + pull_request: + paths: + - "release_files/install.sh" + +jobs: + install-cli-only: + runs-on: macos-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Rename brew package + if: ${{ matrix.check_bin_install }} + run: mv /opt/homebrew/bin/brew /opt/homebrew/bin/brew.bak + + - name: Run install script + run: | + sh ./release_files/install.sh + env: + SKIP_UI_APP: true + + - name: Run tests + run: | + if ! command -v netbird &> /dev/null; then + echo "Error: netbird is not installed" + exit 1 + fi + install-all: + runs-on: macos-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Rename brew package + if: ${{ matrix.check_bin_install }} + run: mv /opt/homebrew/bin/brew /opt/homebrew/bin/brew.bak + + - name: Run install script + run: | + sh ./release_files/install.sh + + - name: Run tests + run: | + if ! command -v netbird &> /dev/null; then + echo "Error: netbird is not installed" + exit 1 + fi + + if [[ $(mdfind "kMDItemContentType == 'com.apple.application-bundle' && kMDItemFSName == '*NetBird UI.app'") ]]; then + echo "Error: NetBird UI is not installed" + exit 1 + fi diff --git a/.github/workflows/install-test-linux.yml b/.github/workflows/install-test-linux.yml new file mode 100644 index 000000000..d4246881c --- /dev/null +++ b/.github/workflows/install-test-linux.yml @@ -0,0 +1,36 @@ +name: Test installation Linux + +on: + push: + branches: + - main + pull_request: + paths: + - "release_files/install.sh" + +jobs: + install-cli-only: + runs-on: ubuntu-latest + strategy: + matrix: + check_bin_install: [true, false] + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Rename apt package + if: ${{ matrix.check_bin_install }} + run: | + sudo mv /usr/bin/apt /usr/bin/apt.bak + sudo mv /usr/bin/apt-get /usr/bin/apt-get.bak + + - name: Run install script + run: | + sh ./release_files/install.sh + + - name: Run tests + run: | + if ! command -v netbird &> /dev/null; then + echo "Error: netbird is not installed" + exit 1 + fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..699b867eb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,197 @@ +name: Release + +on: + push: + tags: + - 'v*' + branches: + - main + pull_request: + +env: + SIGN_PIPE_VER: "v0.0.5" + GORELEASER_VER: "v1.14.1" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 # It is required for GoReleaser to work properly + + - name: Generate syso with DLL + run: bash -x wireguard_nt.sh + working-directory: client + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + - + name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - + name: Install modules + run: go mod tidy + - + name: check git status + run: git --no-pager diff --exit-code + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to Docker hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: netbirdio + password: ${{ secrets.DOCKER_TOKEN }} + - name: Install OS build dependencies + run: sudo apt update && sudo apt install -y -q gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: ${{ env.GORELEASER_VER }} + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} + UPLOAD_DEBIAN_SECRET: ${{ secrets.PKG_UPLOAD_SECRET }} + UPLOAD_YUM_SECRET: ${{ secrets.PKG_UPLOAD_SECRET }} + - + name: upload non tags for debug purposes + uses: actions/upload-artifact@v2 + with: + name: release + path: dist/ + retention-days: 3 + + release_ui: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 # It is required for GoReleaser to work properly + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-ui-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-ui-go- + + - name: Install modules + run: go mod tidy + + - name: check git status + run: git --no-pager diff --exit-code + + - name: Install dependencies + run: sudo apt update && sudo apt install -y -q libgtk-3-dev libayatana-appindicator3-dev libgl1-mesa-dev xorg-dev gcc-mingw-w64-x86-64 + - name: Install rsrc + run: go install github.com/akavel/rsrc@v0.10.2 + - name: Generate windows rsrc + run: rsrc -arch amd64 -ico client/ui/netbird.ico -manifest client/ui/manifest.xml -o client/ui/resources_windows_amd64.syso + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: ${{ env.GORELEASER_VER }} + args: release --config .goreleaser_ui.yaml --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} + UPLOAD_DEBIAN_SECRET: ${{ secrets.PKG_UPLOAD_SECRET }} + UPLOAD_YUM_SECRET: ${{ secrets.PKG_UPLOAD_SECRET }} + - name: upload non tags for debug purposes + uses: actions/upload-artifact@v2 + with: + name: release-ui + path: dist/ + retention-days: 3 + + release_ui_darwin: + runs-on: macos-11 + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 # It is required for GoReleaser to work properly + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + - + name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-ui-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-ui-go- + - + name: Install modules + run: go mod tidy + - + name: Run GoReleaser + id: goreleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: ${{ env.GORELEASER_VER }} + args: release --config .goreleaser_ui_darwin.yaml --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: upload non tags for debug purposes + uses: actions/upload-artifact@v2 + with: + name: release-ui-darwin + path: dist/ + retention-days: 3 + + trigger_windows_signer: + runs-on: ubuntu-latest + needs: [release,release_ui] + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Trigger Windows binaries sign pipeline + uses: benc-uk/workflow-dispatch@v1 + with: + workflow: Sign windows bin and installer + repo: netbirdio/sign-pipelines + ref: ${{ env.SIGN_PIPE_VER }} + token: ${{ secrets.SIGN_GITHUB_TOKEN }} + inputs: '{ "tag": "${{ github.ref }}" }' + + trigger_darwin_signer: + runs-on: ubuntu-latest + needs: release_ui_darwin + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Trigger Darwin App binaries sign pipeline + uses: benc-uk/workflow-dispatch@v1 + with: + workflow: Sign darwin ui app with dispatch + repo: netbirdio/sign-pipelines + ref: ${{ env.SIGN_PIPE_VER }} + token: ${{ secrets.SIGN_GITHUB_TOKEN }} + inputs: '{ "tag": "${{ github.ref }}" }' \ No newline at end of file diff --git a/.github/workflows/test-docker-compose-linux.yml b/.github/workflows/test-docker-compose-linux.yml new file mode 100644 index 000000000..c28e94a4f --- /dev/null +++ b/.github/workflows/test-docker-compose-linux.yml @@ -0,0 +1,92 @@ +name: Test Docker Compose Linux + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Install jq + run: sudo apt-get install -y jq + + - name: Install curl + run: sudo apt-get install -y curl + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Checkout code + uses: actions/checkout@v2 + + - name: cp setup.env + run: cp infrastructure_files/tests/setup.env infrastructure_files/ + + - name: run configure + working-directory: infrastructure_files + run: bash -x configure.sh + env: + CI_NETBIRD_DOMAIN: localhost + CI_NETBIRD_AUTH_CLIENT_ID: testing.client.id + CI_NETBIRD_AUTH_AUDIENCE: testing.ci + CI_NETBIRD_AUTH_OIDC_CONFIGURATION_ENDPOINT: https://example.eu.auth0.com/.well-known/openid-configuration + CI_NETBIRD_USE_AUTH0: true + + - name: check values + working-directory: infrastructure_files + env: + CI_NETBIRD_DOMAIN: localhost + CI_NETBIRD_AUTH_CLIENT_ID: testing.client.id + CI_NETBIRD_AUTH_AUDIENCE: testing.ci + CI_NETBIRD_AUTH_OIDC_CONFIGURATION_ENDPOINT: https://example.eu.auth0.com/.well-known/openid-configuration + CI_NETBIRD_USE_AUTH0: true + CI_NETBIRD_AUTH_SUPPORTED_SCOPES: "openid profile email offline_access api email_verified" + CI_NETBIRD_AUTH_AUTHORITY: https://example.eu.auth0.com/ + CI_NETBIRD_AUTH_JWT_CERTS: https://example.eu.auth0.com/.well-known/jwks.json + CI_NETBIRD_AUTH_TOKEN_ENDPOINT: https://example.eu.auth0.com/oauth/token + CI_NETBIRD_AUTH_DEVICE_AUTH_ENDPOINT: https://example.eu.auth0.com/oauth/device/code + CI_NETBIRD_AUTH_REDIRECT_URI: "/peers" + CI_NETBIRD_TOKEN_SOURCE: "idToken" + CI_NETBIRD_AUTH_USER_ID_CLAIM: "email" + CI_NETBIRD_AUTH_DEVICE_AUTH_AUDIENCE: "super" + + run: | + grep AUTH_CLIENT_ID docker-compose.yml | grep $CI_NETBIRD_AUTH_CLIENT_ID + grep AUTH_AUTHORITY docker-compose.yml | grep $CI_NETBIRD_AUTH_AUTHORITY + grep AUTH_AUDIENCE docker-compose.yml | grep $CI_NETBIRD_AUTH_AUDIENCE + grep AUTH_SUPPORTED_SCOPES docker-compose.yml | grep "$CI_NETBIRD_AUTH_SUPPORTED_SCOPES" + grep USE_AUTH0 docker-compose.yml | grep $CI_NETBIRD_USE_AUTH0 + grep NETBIRD_MGMT_API_ENDPOINT docker-compose.yml | grep "$CI_NETBIRD_DOMAIN:33073" + grep AUTH_REDIRECT_URI docker-compose.yml | grep $CI_NETBIRD_AUTH_REDIRECT_URI + grep AUTH_SILENT_REDIRECT_URI docker-compose.yml | egrep 'AUTH_SILENT_REDIRECT_URI=$' + grep LETSENCRYPT_DOMAIN docker-compose.yml | egrep 'LETSENCRYPT_DOMAIN=$' + grep NETBIRD_TOKEN_SOURCE docker-compose.yml | grep $CI_NETBIRD_TOKEN_SOURCE + grep AuthUserIDClaim management.json | grep $CI_NETBIRD_AUTH_USER_ID_CLAIM + grep -A 1 ProviderConfig management.json | grep Audience | grep $CI_NETBIRD_AUTH_DEVICE_AUTH_AUDIENCE + + - name: run docker compose up + working-directory: infrastructure_files + run: | + docker-compose up -d + sleep 5 + docker-compose ps + docker-compose logs --tail=20 + + - name: test running containers + run: | + count=$(docker compose ps --format json | jq '.[] | select(.Project | contains("infrastructure_files")) | .State' | grep -c running) + test $count -eq 4 + working-directory: infrastructure_files