diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 2e90a2a..66d9401 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -32,4 +32,35 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max tags: | - kubeshop/demo-pokemon-api:latest \ No newline at end of file + kubeshop/demo-pokemon-api:latest + + tracet-tests: + needs: [build] + name: Tracetests + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Tracetest + uses: kubeshop/tracetest-agent-action@v1 + with: + apiKey: ${{ secrets.TRACETEST_API_KEY }} + token: ${{ secrets.TRACETEST_TOKEN}} + + - name: Start pokeshop services + run: | + docker compose -f docker-compose.agent.yml up -d \ + || (docker compose -f docker-compose.agent.yml logs; exit 1) + - name: Wait for pokeshop services + run: | + sleep 15 # it might take some time for docker compose to start up + timeout 60 bash -c 'until nc -z -w 1 localhost '8081' > /dev/null 2>&1; do sleep 1; done; echo "pokeshop http api ready"' + - name: Run tracetests + run: | + tracetest run \ + --file ./tracetest/tests/testsuite.yaml \ + --vars ./tracetest/tests/vars.agent.yaml \ + || (docker compose -f docker-compose.agent.yml logs; exit 1) + diff --git a/Dockerfile b/Dockerfile index f04d03f..67c430f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,9 @@ FROM node:20.5.1-alpine as build-ui WORKDIR /ui ENV PATH /ui/node_modules/.bin:$PATH -COPY ./web/package.json ./ -COPY ./web/package-lock.json ./ +COPY ./web/package*.json ./ -RUN npm ci --silent +RUN npm ci --maxsockets 1 --silent COPY ./web ./ RUN npm run build @@ -16,7 +15,7 @@ FROM node:alpine as build WORKDIR /build RUN npm i -g typescript COPY ./api/package*.json ./ -RUN npm ci +RUN npm ci --maxsockets 1 --silent COPY ./api ./ @@ -27,12 +26,11 @@ FROM node:alpine as app WORKDIR /app COPY ./api/package.json ./api/package-lock.json ./ -RUN npm clean-install - EXPOSE 80 ENV NPM_RUN_COMMAND=api +COPY --from=build /build/node_modules ./node_modules COPY --from=build /build/.build/* ./ COPY --from=build /build/migrations/* ./migrations/ COPY --from=build-ui /ui/build ./ui diff --git a/docker-compose.agent.yml b/docker-compose.agent.yml new file mode 100644 index 0000000..e908ea3 --- /dev/null +++ b/docker-compose.agent.yml @@ -0,0 +1,122 @@ +services: + db: + image: postgres:14 + environment: + POSTGRES_USER: ashketchum + POSTGRES_PASSWORD: squirtle123 + POSTGRES_DB: pokeshop + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB'] + interval: 1s + timeout: 5s + retries: 60 + + cache: + image: redis:6 + healthcheck: + test: ['CMD', 'redis-cli', 'ping'] + interval: 1s + timeout: 3s + retries: 60 + + queue: + image: cloudamqp/lavinmq:1.2.5 + restart: unless-stopped + + stream: + image: confluentinc/cp-kafka:latest-ubi8 + ports: + - 29092:29092 + - 9092:9092 + environment: + - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://stream:9092,PLAINTEXT_HOST://127.0.0.1:29092 + - KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093,PLAINTEXT_HOST://:29092 + - KAFKA_CONTROLLER_QUORUM_VOTERS=1@0.0.0.0:9093 + - KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER + - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + - KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 + - KAFKA_PROCESS_ROLES=controller,broker + - KAFKA_NODE_ID=1 + - KAFKA_METADATA_LOG_SEGMENT_MS=15000 + - KAFKA_METADATA_MAX_RETENTION_MS=60000 + - KAFKA_METADATA_LOG_MAX_RECORD_BYTES_BETWEEN_SNAPSHOTS=2800 + - KAFKA_AUTO_CREATE_TOPICS_ENABLE=true + - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 + - KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 + - KAFKA_HEAP_OPTS=-Xmx200m -Xms200m + - CLUSTER_ID=ckjPoprWQzOf0-FuNkGfFQ + healthcheck: + test: nc -z stream 9092 + start_period: 10s + interval: 5s + timeout: 10s + retries: 10 + + api: + image: kubeshop/demo-pokemon-api:latest + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + REDIS_URL: cache + DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public + RABBITMQ_HOST: guest:guest@queue + POKE_API_BASE_URL: https://pokeapi.co/api/v2 + COLLECTOR_ENDPOINT: http://host.docker.internal:4317 + ZIPKIN_URL: http://localhost:9411 + healthcheck: + test: ['CMD', 'wget', '--spider', 'localhost:8081/pokemon/healthcheck'] + interval: 1s + timeout: 3s + retries: 60 + ports: + - 8081:8081 + - 8082:8082 + depends_on: + db: + condition: service_healthy + cache: + condition: service_healthy + queue: + condition: service_healthy + + worker: + image: kubeshop/demo-pokemon-api:latest + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + REDIS_URL: cache + DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public + RABBITMQ_HOST: guest:guest@queue + POKE_API_BASE_URL: https://pokeapi.co/api/v2 + COLLECTOR_ENDPOINT: http://host.docker.internal:4317 + ZIPKIN_URL: http://localhost:9411 + NPM_RUN_COMMAND: worker + depends_on: + db: + condition: service_healthy + cache: + condition: service_healthy + queue: + condition: service_healthy + + streaming-worker: + image: kubeshop/demo-pokemon-api:latest + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public + POKE_API_BASE_URL: https://pokeapi.co/api/v2 + COLLECTOR_ENDPOINT: http://host.docker.internal:4317 + ZIPKIN_URL: http://localhost:9411 + NPM_RUN_COMMAND: stream-worker + KAFKA_BROKER: 'stream:9092' + KAFKA_TOPIC: 'pokemon' + KAFKA_CLIENT_ID: 'streaming-worker' + REDIS_URL: cache + depends_on: + db: + condition: service_healthy + stream: + condition: service_healthy + cache: + condition: service_healthy diff --git a/docker-compose.yml b/docker-compose.yml index f1fb93c..46eabe5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,16 +27,11 @@ services: retries: 60 queue: - image: rabbitmq:3.12 + image: cloudamqp/lavinmq:1.2.5 restart: unless-stopped ports: - 5672:5672 - 15672:15672 - healthcheck: - test: rabbitmq-diagnostics -q check_running - interval: 1s - timeout: 5s - retries: 60 jaeger: image: jaegertracing/all-in-one:latest @@ -78,7 +73,7 @@ services: environment: REDIS_URL: cache DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public - RABBITMQ_HOST: queue + RABBITMQ_HOST: guest:guest@queue POKE_API_BASE_URL: https://pokeapi.co/api/v2 COLLECTOR_ENDPOINT: http://otel-collector:4317 ZIPKIN_URL: http://localhost:9411 @@ -100,13 +95,13 @@ services: condition: service_healthy otel-collector: condition: service_started - + rpc: build: . environment: REDIS_URL: cache DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public - RABBITMQ_HOST: queue + RABBITMQ_HOST: guest:guest@queue POKE_API_BASE_URL: https://pokeapi.co/api/v2 COLLECTOR_ENDPOINT: http://otel-collector:4317 ZIPKIN_URL: http://localhost:9411 @@ -135,7 +130,7 @@ services: environment: REDIS_URL: cache DATABASE_URL: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public - RABBITMQ_HOST: queue + RABBITMQ_HOST: guest:guest@queue POKE_API_BASE_URL: https://pokeapi.co/api/v2 COLLECTOR_ENDPOINT: http://otel-collector:4317 ZIPKIN_URL: http://localhost:9411 diff --git a/tracetest/docker-compose.yml b/tracetest/docker-compose.yml index 3a7be0b..7ab33f5 100644 --- a/tracetest/docker-compose.yml +++ b/tracetest/docker-compose.yml @@ -10,19 +10,21 @@ services: - type: bind source: ./tracetest/config/tracetest-cli.yaml target: /app/tracetest-cli.yaml - entrypoint: + entrypoint: - tracetest - command: + command: - run - testsuite - --config - /app/tracetest-cli.yaml - --file - /app/tracebased-tests/testsuite.yaml + - --vars + - /app/tracebased-tests/vars.docker.yaml depends_on: tracetest-server: condition: service_healthy - + tracetest-server: image: kubeshop/tracetest:${TAG:-latest} volumes: diff --git a/tracetest/tests/add.yaml b/tracetest/tests/add.yaml index 6ae7ec1..f4285ee 100644 --- a/tracetest/tests/add.yaml +++ b/tracetest/tests/add.yaml @@ -7,7 +7,7 @@ spec: type: http httpRequest: method: POST - url: http://api:8081/pokemon + url: http://${var:API_HOST}/pokemon body: | { "name": "meowth", diff --git a/tracetest/tests/importqueue.yaml b/tracetest/tests/importqueue.yaml index 6174b81..f3e7dbc 100644 --- a/tracetest/tests/importqueue.yaml +++ b/tracetest/tests/importqueue.yaml @@ -7,7 +7,7 @@ spec: type: http httpRequest: method: POST - url: http://api:8081/pokemon/import + url: http://${var:API_HOST}/pokemon/import body: | { "id": 143 diff --git a/tracetest/tests/importstream.yaml b/tracetest/tests/importstream.yaml index 866dd02..08ff46e 100644 --- a/tracetest/tests/importstream.yaml +++ b/tracetest/tests/importstream.yaml @@ -7,7 +7,7 @@ spec: type: kafka kafka: brokerUrls: - - stream:9092 + - ${env:KAFKA_HOST} topic: pokemon headers: [] messageKey: snorlax-key @@ -20,4 +20,4 @@ spec: - selector: span[tracetest.span.type="general" name="import pokemon"] name: Import Pokemon use case was triggered assertions: - - attr:name = "import pokemon" \ No newline at end of file + - attr:name = "import pokemon" diff --git a/tracetest/tests/list.yaml b/tracetest/tests/list.yaml index c0fc9fe..7397907 100644 --- a/tracetest/tests/list.yaml +++ b/tracetest/tests/list.yaml @@ -7,7 +7,7 @@ spec: type: http httpRequest: method: GET - url: http://api:8081/pokemon?take=20&skip=0 + url: http://${var:API_HOST}/pokemon?take=20&skip=0 headers: - key: Content-Type value: application/json diff --git a/tracetest/tests/testsuite.yaml b/tracetest/tests/testsuite.yaml index d7d660b..8105d4e 100644 --- a/tracetest/tests/testsuite.yaml +++ b/tracetest/tests/testsuite.yaml @@ -1,4 +1,4 @@ -type: Transaction +type: TestSuite spec: id: ILYjqDQ4g name: Running all tests @@ -7,4 +7,4 @@ spec: - ./add.yaml - ./importqueue.yaml - ./importstream.yaml - - ./list.yaml \ No newline at end of file + - ./list.yaml diff --git a/tracetest/tests/vars.agent.yaml b/tracetest/tests/vars.agent.yaml new file mode 100644 index 0000000..740a45f --- /dev/null +++ b/tracetest/tests/vars.agent.yaml @@ -0,0 +1,9 @@ +type: VariableSet +spec: + id: agent + name: Agent Values + values: + - key: API_HOST + value: localhost:8081 + - key: KAFKA_HOST + value: localhost:29092 diff --git a/tracetest/tests/vars.docker.yaml b/tracetest/tests/vars.docker.yaml new file mode 100644 index 0000000..149505b --- /dev/null +++ b/tracetest/tests/vars.docker.yaml @@ -0,0 +1,9 @@ +type: VariableSet +spec: + id: docker + name: Docker Values + values: + - key: API_HOST + value: api:8081 + - key: KAFKA_HOST + value: stream:9092