From 6135f18ac0e22f0148a074ee4d0e4244ffe35dd7 Mon Sep 17 00:00:00 2001 From: pasha1coil Date: Wed, 30 Jul 2025 15:14:48 +0300 Subject: [PATCH] added test docker file compouse and gitea workflow --- .gitea/workflows/deployTests.yml | 21 +++++ TestsDockerfile | 7 -- deployments/test/docker-compose.yaml | 121 ++++++--------------------- tests/main_test.go | 6 +- testsDockerfile | 7 ++ 5 files changed, 55 insertions(+), 107 deletions(-) delete mode 100644 TestsDockerfile create mode 100644 testsDockerfile diff --git a/.gitea/workflows/deployTests.yml b/.gitea/workflows/deployTests.yml index e69de29..f8f88aa 100644 --- a/.gitea/workflows/deployTests.yml +++ b/.gitea/workflows/deployTests.yml @@ -0,0 +1,21 @@ +name: Deploy +run-name: ${{ gitea.actor }} build image and push to container registry + +on: + push: + branches: + - 'renew_tests' + +jobs: + CreateImage: + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p + with: + runner: hubstaging + secrets: + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + DeployService: + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/deploy.yml@v1.1.4-p7 + with: + runner: hubstaging + actionid: ${{ gitea.run_id }} \ No newline at end of file diff --git a/TestsDockerfile b/TestsDockerfile deleted file mode 100644 index 25846f2..0000000 --- a/TestsDockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM golang:alpine -WORKDIR /app -RUN apk add git -COPY . . -RUN git config --global url."https://forgomod:glpat-uzHiaztQGzR1BL8RiQTK@penahub.gitlab.yandexcloud.net/".insteadOf "https://penahub.gitlab.yandexcloud.net/" -RUN apk add --no-cache git && go mod download -CMD ["go", "test", "./tests"] diff --git a/deployments/test/docker-compose.yaml b/deployments/test/docker-compose.yaml index b66713c..65091d6 100644 --- a/deployments/test/docker-compose.yaml +++ b/deployments/test/docker-compose.yaml @@ -1,102 +1,29 @@ -version: '3' +version: '3.8' + services: - test-postgres: - image: postgres - environment: - POSTGRES_PASSWORD: Redalert2 - POSTGRES_USER: squiz - POSTGRES_DB: squiz - volumes: - - test-postgres:/var/lib/postgresql/data - ports: - - 35432:5432 - networks: - - penatest - healthcheck: - test: pg_isready -U squiz - interval: 2s - timeout: 2s - retries: 10 - -# need update! -# test-pena-auth-service: -# image: penahub.gitlab.yandexcloud.net:5050/pena-services/pena-auth-service:staging.872 -# container_name: test-pena-auth-service -# init: true -# env_file: auth.env.test -# healthcheck: -# test: wget -T1 --spider http://localhost:8000/user -# interval: 2s -# timeout: 2s -# retries: 5 -# environment: -# - DB_HOST=test-pena-auth-db -# - DB_PORT=27017 -# - ENVIRONMENT=staging -# - HTTP_HOST=0.0.0.0 -# - HTTP_PORT=8000 -# - DB_USERNAME=test -# - DB_PASSWORD=test -# - DB_NAME=admin -# - DB_AUTH=admin -# # ports: -# # - 8000:8000 -# depends_on: -# - test-pena-auth-db -# # - pena-auth-migration -# networks: -# - penatest -# -# test-pena-auth-db: -# container_name: test-pena-auth-db -# init: true -# image: "mongo:6.0.3" -# command: mongod --quiet --logpath /dev/null -# volumes: -# - test-mongodb:/data/db -# - test-mongoconfdb:/data/configdb -# environment: -# MONGO_INITDB_ROOT_USERNAME: test -# MONGO_INITDB_ROOT_PASSWORD: test -# # ports: -# # - 27017:27017 -# networks: -# - penatest - - test-minio: - container_name: test-minio - init: true - image: quay.io/minio/minio - volumes: - - test-minio:/data - command: [ "minio", "--quiet", "server", "/data" ] - networks: - - penatest - - test-squiz: - container_name: test-squiz - init: true + app: build: - context: ../.. - dockerfile: TestsDockerfile - depends_on: - test-postgres: - condition: service_healthy -# test-pena-auth-service: -# condition: service_healthy - # volumes: - # - ./../..:/app:ro - # command: [ "go", "test", "./tests", "-run", "TestFoo" ] - command: [ "go", "test", "-parallel", "1", "./tests" ] + context: . + dockerfile: testsDockerfile + container_name: squiz-core-test-app + environment: + - IS_TEST=true + - IS_PROD_LOG=false + - IS_PROD=false + - CLIENT_HTTP_URL=localhost:1488 + - GRPC_URL=localhost:9000 + - POSTGRES_URL=host=test-postgres port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable + - REDIS_HOST=test-redis:6379 + - REDIS_PASSWORD=admin + - REDIS_DB=2 + - CLICKHOUSE_URL=clickhouse://clickhouse.pena:9000/default?sslmode=disable + ports: + - "1488:1488" + - "9000:9000" + restart: unless-stopped networks: - - penatest + - app-network networks: - penatest: - - -volumes: - test-minio: - test-postgres: - test-mongodb: - test-mongoconfdb: + app-network: + driver: bridge \ No newline at end of file diff --git a/tests/main_test.go b/tests/main_test.go index 7e183de..e4a1944 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -24,9 +24,9 @@ import ( var validQuizIDForTestingClickHouse = 21211 var PublicKey = `-----BEGIN PUBLIC KEY-----MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHgnvr7O2tiApjJfid1orFnIGm6980fZp+Lpbjo+NC/0whMFga2Biw5b1G2Q/B2u0tpO1Fs/E8z7Lv1nYfr5jx2S8x6BdA4TS2kB9Kf0wn0+7wSlyikHoKhbtzwXHZl17GsyEi6wHnsqNBSauyIWhpha8i+Y+3GyaOY536H47qyXAgMBAAE=-----END PUBLIC KEY-----` -var postgresCred = "postgres://squiz:Redalert2@localhost:35432/squiz?sslmode=disable" //os.Getenv("POSTGRES_CRED") -var baseURL = "http://127.0.0.1:1488" //os.Getenv("API_BASE_URL") -var validToken = CreateJWT(validUserID) // validUserID +var postgresCred = "postgres://squiz:Redalert2@10.7.0.2:35432/squiz?sslmode=disable" //os.Getenv("POSTGRES_CRED") +var baseURL = "http://localhost:1488" //os.Getenv("API_BASE_URL") +var validToken = CreateJWT(validUserID) // validUserID var expiredToken = CreateExpiredToken(validUserID) // todo diff --git a/testsDockerfile b/testsDockerfile new file mode 100644 index 0000000..a79e1b1 --- /dev/null +++ b/testsDockerfile @@ -0,0 +1,7 @@ +FROM gitea.pena/penadevops/container-images/golang:main +WORKDIR /app +COPY . . +RUN go mod download +RUN apk add tzdata curl + +CMD go run ./cmd/main.go & sleep 30 && go test ./tests && kill %1