Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/keploy experimental 2 #151

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ ACCESS_TOKEN_SECRET=4cd7234152590dcfe77e1b6fc52e84f4d30c06fddadd0dd2fb42cbc51fa1
NODE_ENV=production
ENVIRONMENT_NAME=docker
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PORT=6379
APP_PATH=/home/runner/work/node-express-graphql-template/node-express-graphql-template
IS_KEPLOY=true
56 changes: 56 additions & 0 deletions .github/workflows/keploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Keploy

on:
pull_request:
branches:
- develop
push:
branches:
- develop

jobs:
node_linux:
runs-on: ubuntu-latest
environment: secrets # Ensure you specify the environment if it's an environment-level secret
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js 20
uses: actions/setup-node@v2
with:
node-version: '20'

- name: Print all environment variables for debugging
run: printenv

- name: Install dependencies
run: yarn install

- name: Install nyc
run: yarn add nyc@15.1.0 --dev

- name: Install Docker
uses: docker/setup-buildx-action@v2

- name: Install Docker Compose
run: |
mkdir -p $HOME/.docker/cli-plugins
curl -L "https://github.com/docker/compose/releases/download/v2.6.1/docker-compose-linux-x86_64" -o $HOME/.docker/cli-plugins/docker-compose
chmod +x $HOME/.docker/cli-plugins/docker-compose
echo "$HOME/.docker/cli-plugins" >> $GITHUB_PATH
docker-compose --version

- name: Run the node-express-graphql template
run: |
chmod +x /home/runner/work/node-express-graphql-template/node-express-graphql-template/.github/workflows/test_workflows/keploy.sh
/home/runner/work/node-express-graphql-template/node-express-graphql-template/.github/workflows/test_workflows/keploy.sh
env:
KEPLOY_API_KEY: ${{ secrets.KEPLOY_API_KEY }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
verbose: true
48 changes: 48 additions & 0 deletions .github/workflows/test_workflows/keploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
curl --silent -O -L https://keploy.io/ent/install.sh


sudo docker compose --env-file .env.docker build
curl --silent -o keployE --location "https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/enterprise_linux_amd64"
sudo chmod a+x keployE && sudo mkdir -p /usr/local/bin && sudo mv keployE /usr/local/bin


# Build the project locally
echo "Project built successfully"

echo $(pwd)


sudo -E env PATH="$PATH" /usr/local/bin/keployE test -c "sudo docker compose --env-file .env.docker up" --containerName "node-express-graphql-template-app-1" --delay 90 --apiTimeout 30 --generateGithubActions=false --testsets="test-set-3"
echo "Keploy started in test mode"

all_passed=true

# Loop through test sets
for i in {3..3}
do
# Define the report file for each test set
report_file="./keploy/reports/test-run-0/test-set-$i-report.yaml"

# Extract the test status
test_status=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')

# Print the status for debugging
echo "Test status for test-set-$i: $test_status"

# Check if any test set did not pass
if [ "$test_status" != "PASSED" ]; then
all_passed=false
echo "Test-set-$i did not pass."
break # Exit the loop early as all tests need to pass
fi
done

# Check the overall test status and exit accordingly
if [ "$all_passed" = true ]; then
docker cp node-express-graphql-template-app-1:$(pwd)/.nyc_output $(pwd)/.nyc_output
npx nyc report
echo "All tests passed"
exit 0
else
exit 1
fi
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,10 @@ typings/
# DS_Store
.DS_Store
report.json
reports/test-report.xml
reports/test-report.xml

# Keploy test reports
dedupData.yaml
duplicates.yaml
keploy/reports
docker-compose-tmp.yaml
36 changes: 25 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM node:20
ARG ENVIRONMENT_NAME
ARG BUILD_NAME
ARG APP_PATH
ARG PLATFORM

RUN mkdir -p /app-build
ADD . /app-build
WORKDIR /app-build
# RUN mkdir -p /app-build
# ADD . /app-build
# WORKDIR /app-build
RUN mkdir -p ${APP_PATH}
ADD . ${APP_PATH}
WORKDIR ${APP_PATH}
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn --frozen-lockfile
RUN yarn
RUN yarn build:$BUILD_NAME
Expand All @@ -13,16 +18,25 @@ RUN yarn build:$BUILD_NAME
FROM node:20-alpine
ARG ENVIRONMENT_NAME
ARG BUILD_NAME
ARG APP_PATH
ARG PLATFORM

RUN mkdir -p /dist
WORKDIR ${APP_PATH}
RUN mkdir -p ${APP_PATH}/dist
RUN apk add yarn
RUN yarn global add sequelize-cli@6.2.0
RUN yarn add shelljs dotenv pg sequelize@6.6.5
ADD scripts/migrate-and-run.sh /
ADD package.json /
ADD . /
COPY --from=0 /app-build/dist ./dist

RUN yarn global add sequelize-cli@6.2.0 nyc@15.1.0
RUN yarn add shelljs dotenv pg sequelize@6.6.5
RUN apk add --no-cache dumb-init
ADD scripts/migrate-and-run.sh ${APP_PATH}/
ADD package.json ${APP_PATH}/
ADD . ./
COPY --from=0 ${APP_PATH}/dist ${APP_PATH}/dist
ADD https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/assets/freeze_time_$PLATFORM.so /lib/keploy/freeze_time_$PLATFORM.so
RUN chmod +x /lib/keploy/freeze_time_$PLATFORM.so
ENV LD_PRELOAD=/lib/keploy/freeze_time_$PLATFORM.so
ENTRYPOINT ["dumb-init", "--"]
STOPSIGNAL SIGINT

CMD ["sh", "./migrate-and-run.sh"]
EXPOSE 9000
EXPOSE 9000
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = function(api) {
const plugins = [
'@babel/plugin-proposal-throw-expressions',
'@babel/plugin-proposal-class-properties',
'@babel/transform-runtime'
'@babel/transform-runtime',
'babel-plugin-istanbul'
];

// Environment-specific configuration
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ services:
args:
ENVIRONMENT_NAME: .docker
BUILD_NAME: docker
PLATFORM: amd64
APP_PATH: ${APP_PATH}
restart: always
depends_on:
- db_postgres
- redis
ports:
- 9000:9000
environment:
ENABLE_DEDUP: "false"
env_file:
- ./.env.docker
volumes:
- ${APP_PATH}/dedupData.yaml:${APP_PATH}/dedupData.yaml
stop_grace_period: 50s
18 changes: 18 additions & 0 deletions keploy-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -x -i -e

# Command to be executed
alias keploy="docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v debugfs:/sys/kernel/debug:rw -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v /Users/apple/.keploy:/root/.keploy --rm docker.io/keploy/enterprise"

# Number of times to run the command
ITERATIONS=10

# Loop to execute the command
for (( i=1; i<=$ITERATIONS; i++ ))
do
echo "Running iteration $i"
keploy test -c 'docker compose --env-file .env.docker up' --containerName "fast-api-app" --delay 30 --freezeTime --testsets='test-set-1'
echo "Iteration $i complete"
echo "----------------------------------------"
done

echo "Script execution complete"
52 changes: 52 additions & 0 deletions keploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
path: ""
appId: 0
appName: ""
command: ""
port: 0
proxyPort: 16789
dnsPort: 26789
debug: false
disableANSI: false
disableTele: false
inDocker: false
generateGithubActions: true
containerName: ""
networkName: ""
buildDelay: 30
test:
selectedTests: {}
globalNoise:
global:
body:
data.signIn.token: []
data.signUp.token: []
header:
Etag: []
Vary: []
test-sets: {}
delay: 5
apiTimeout: 5
coverage: false
goCoverage: false
coverageReportPath: ""
ignoreOrdering: true
mongoPassword: "default@123"
language: ""
removeUnusedMocks: false
basePath: ""
mocking: true
dedup: true
disableMockUpload: false
freezeTime: true
record:
recordTimer: 0s
filters: []
configPath: ""
bypassRules: []
cmdType: "native"
enableTesting: false
fallbackOnMiss: false
keployContainer: "keploy-v2"
keployNetwork: "keploy-network"

# Visit [https://keploy.io/docs/running-keploy/configuration-file/] to learn about using keploy through configration file.
6 changes: 6 additions & 0 deletions keploy/test-set-0/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
testset:
pre_script: ""
post_script: ""
template: {}
mocks:
- daa16f86fded81299cb178aec234e127a08ad8a9174ce8b4e8f8ee23d7eebf0d.yaml
Loading
Loading