From 5eb5e37b238c7926fe8bcafcf9bfc66ae103fbff Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Sun, 19 Jan 2025 00:23:17 +0100 Subject: [PATCH] enable for other workflows --- .github/workflows/golang-test-linux.yml | 137 +++++++++++++++++++++++- management/server/store/store.go | 2 +- 2 files changed, 134 insertions(+), 5 deletions(-) diff --git a/.github/workflows/golang-test-linux.yml b/.github/workflows/golang-test-linux.yml index 5be7b0e7605..21997c282df 100644 --- a/.github/workflows/golang-test-linux.yml +++ b/.github/workflows/golang-test-linux.yml @@ -309,8 +309,51 @@ jobs: if: matrix.store == 'mysql' run: docker pull mlsmaycon/warmed-mysql:8 + - name: Start Postgres + if: matrix.store == 'postgres' + run: | + docker run -d \ + -e POSTGRES_USER=root \ + -e POSTGRES_PASSWORD=netbird \ + -e POSTGRES_DB=netbird \ + -p 5432:5432 \ + --name my-postgres \ + postgres:15-alpine + + - name: Wait for Postgres + if: matrix.store == 'postgres' + run: | + for i in {1..10}; do + if nc -z localhost 5432; then + break + fi + echo "Waiting for Postgres..." + sleep 3 + done + + - name: Start MySQL + if: matrix.store == 'mysql' + run: | + docker run -d \ + -e MYSQL_ROOT_PASSWORD=netbird \ + -e MYSQL_DATABASE=netbird \ + -p 3306:3306 \ + --name my-mysql \ + mlsmaycon/warmed-mysql:8 + + - name: Wait for MySQL + if: matrix.store == 'mysql' + run: | + for i in {1..10}; do + if nc -z localhost 3306; then + break + fi + echo "Waiting for MySQL..." + sleep 3 + done + - name: Test - run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -tags devcert -run=^$ -bench=. -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE' -timeout 20m ./... + run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -tags devcert -run=^$ -bench=. -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,NETBIRD_STORE_ENGINE_POSTGRES_DSN,NETBIRD_STORE_ENGINE_MYSQL_DSN' -timeout 20m ./... api_benchmark: needs: [ build-cache ] @@ -368,9 +411,52 @@ jobs: - name: download mysql image if: matrix.store == 'mysql' run: docker pull mlsmaycon/warmed-mysql:8 - + + - name: Start Postgres + if: matrix.store == 'postgres' + run: | + docker run -d \ + -e POSTGRES_USER=root \ + -e POSTGRES_PASSWORD=netbird \ + -e POSTGRES_DB=netbird \ + -p 5432:5432 \ + --name my-postgres \ + postgres:15-alpine + + - name: Wait for Postgres + if: matrix.store == 'postgres' + run: | + for i in {1..10}; do + if nc -z localhost 5432; then + break + fi + echo "Waiting for Postgres..." + sleep 3 + done + + - name: Start MySQL + if: matrix.store == 'mysql' + run: | + docker run -d \ + -e MYSQL_ROOT_PASSWORD=netbird \ + -e MYSQL_DATABASE=netbird \ + -p 3306:3306 \ + --name my-mysql \ + mlsmaycon/warmed-mysql:8 + + - name: Wait for MySQL + if: matrix.store == 'mysql' + run: | + for i in {1..10}; do + if nc -z localhost 3306; then + break + fi + echo "Waiting for MySQL..." + sleep 3 + done + - name: Test - run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -tags=benchmark -run=^$ -bench=. -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE' -timeout 10m $(go list ./... | grep /management) + run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -tags=benchmark -run=^$ -bench=. -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,NETBIRD_STORE_ENGINE_POSTGRES_DSN,NETBIRD_STORE_ENGINE_MYSQL_DSN' -timeout 10m $(go list ./... | grep /management) api_integration_test: needs: [ build-cache ] @@ -418,8 +504,51 @@ jobs: - name: check git status run: git --no-pager diff --exit-code + - name: Start Postgres + if: matrix.store == 'postgres' + run: | + docker run -d \ + -e POSTGRES_USER=root \ + -e POSTGRES_PASSWORD=netbird \ + -e POSTGRES_DB=netbird \ + -p 5432:5432 \ + --name my-postgres \ + postgres:15-alpine + + - name: Wait for Postgres + if: matrix.store == 'postgres' + run: | + for i in {1..10}; do + if nc -z localhost 5432; then + break + fi + echo "Waiting for Postgres..." + sleep 3 + done + + - name: Start MySQL + if: matrix.store == 'mysql' + run: | + docker run -d \ + -e MYSQL_ROOT_PASSWORD=netbird \ + -e MYSQL_DATABASE=netbird \ + -p 3306:3306 \ + --name my-mysql \ + mlsmaycon/warmed-mysql:8 + + - name: Wait for MySQL + if: matrix.store == 'mysql' + run: | + for i in {1..10}; do + if nc -z localhost 3306; then + break + fi + echo "Waiting for MySQL..." + sleep 3 + done + - name: Test - run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -p 1 -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE' -timeout 10m -tags=integration $(go list ./... | grep /management) + run: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} NETBIRD_STORE_ENGINE=${{ matrix.store }} CI=true go test -p 1 -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,NETBIRD_STORE_ENGINE_POSTGRES_DSN,NETBIRD_STORE_ENGINE_MYSQL_DSN' -timeout 10m -tags=integration $(go list ./... | grep /management) test_client_on_docker: needs: [ build-cache ] diff --git a/management/server/store/store.go b/management/server/store/store.go index 82d7806202e..d59f5ccc41e 100644 --- a/management/server/store/store.go +++ b/management/server/store/store.go @@ -389,7 +389,7 @@ func getSqlStoreEngine(ctx context.Context, store *SqlStore, kind Engine) (Store return nil, nil, fmt.Errorf("%s is not set", mysqlDsnEnv) } - db, err := gorm.Open(mysql.Open(dsn+"?charset=utf8&parseTime=True&loc=Local"), getGormConfig()) + db, err := gorm.Open(mysql.Open(dsn), getGormConfig()) if err != nil { return nil, cleanUp, fmt.Errorf("failed to open mysql connection: %v", err) }