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

Zango project setup for cypress #318

Open
wants to merge 12 commits into
base: test/cypress
Choose a base branch
from
75 changes: 62 additions & 13 deletions .github/workflows/e2e-cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: End to End Cypress Test
on:
push:
branches:
- test/cypress
paths:
- "frontend/**"
- zango_setup_for_cypress
# paths:
# - "frontend/**"

jobs:
cypress-run:
Expand All @@ -16,18 +16,67 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# Step 2: Set up Node.js environment
# Step 2: Set up python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Build latest Zango image
run: docker build -t local/zango-base:latest .

# Step 3: Start up environment variables
- name: Set up environment variables
run: |
echo "
[email protected]
PLATFORM_USER_PASSWORD=Zango@123
PROJECT_NAME=zango_project
POSTGRES_USER=zango_admin
POSTGRES_PASSWORD=zangopass
POSTGRES_DB=zango
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
REDIS_HOST=redis
REDIS_PORT=6379
PLATFORM_DOMAIN_URL=localhost
" >> deploy/.env

# Step 4: Build and start zango project server
- name: Build and start Zango project
run: |
export HOST_UID=$(id -u)
export HOST_GID=$(id -g)
DOCKER_BUILDKIT=0 docker-compose -f deploy/docker_compose.test.yml build
docker-compose -f deploy/docker_compose.test.yml up -d

# Step 5: Map localhost to domain
- name: Setup local domain
run: echo '0.0.0.0 test.zango.local' | sudo tee -a /etc/hosts

# Step 6: Verify zango project is up and running
- name: Verify zango project is up and running
run: |
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -L http://localhost:8000/platform)
if [ "$RESPONSE" -eq 200 ]; then
echo "Backend is up and running at http://localhost:8000"
else
echo "Backend is not responding as expected. HTTP response code: $RESPONSE" >&2
exit 1
fi

# Step 6: Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

# Step 3: Install dependencies
- name: Install dependencies
# Step 7: Install dependencies
- name: Install cypress dependencies
run: npm install
working-directory: e2e-tests

# Step 4: Run Cypress tests and record results
# Step 8: Run Cypress tests and record results
- name: Run Cypress tests
uses: cypress-io/[email protected]
with:
Expand All @@ -36,12 +85,12 @@ jobs:
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}

# Step 5: Generate Cucumber HTML Report
# Step 9: Generate Cucumber HTML Report
- name: Generate Cucumber HTML Report
run: node cucumber-html-report.js
working-directory: e2e-tests

# Step 6: Upload Cypress screenshots on failure
# Step 10: Upload Cypress screenshots on failure
- name: Upload Cypress screenshots
uses: actions/upload-artifact@v3
if: failure()
Expand All @@ -50,18 +99,18 @@ jobs:
path: e2e-tests/cypress/screenshots
if-no-files-found: ignore

# Step 7: Upload Cypress videos
# Step 11: Upload Cypress videos
- name: Upload Cypress videos
uses: actions/upload-artifact@v3
with:
name: cypress-videos
path: e2e-tests/cypress/videos
if-no-files-found: ignore

# Step 8: Upload Cucumber HTML Report
# Step 12: Upload Cucumber HTML Report
- name: Upload Cucumber HTML Report
uses: actions/upload-artifact@v3
with:
name: cucumber-html-report
path: e2e-tests/cucumber-html-report.html
if-no-files-found: ignore
if-no-files-found: ignore
4 changes: 2 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ tasks:
- name: Setup and start the project
command: |
cd /workspace/zango-sandbox/zango
export UID=$(id -u)
export GID=$(id -g)
export HOST_UID=$(id -u)
export HOST_GID=$(id -g)
# Run the gp info --json containing workspace info like workspace_id, url
info=$(gp info --json)

Expand Down
8 changes: 4 additions & 4 deletions deploy/dev.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ RUN apt update
RUN apt-get install -y net-tools
RUN apt install ffmpeg -y

ARG UID
ARG GID
ARG HOST_UID
ARG HOST_GID

# Update the package list, install sudo, create a non-root user, and grant password-less sudo permissions
RUN apt update && \
apt install -y sudo && \
groupadd -o -g ${GID} -r zango_user && \
adduser --uid $UID --gid $GID --disabled-password --gecos "" zango_user && \
groupadd -o -g $HOST_GID -r zango_user && \
adduser --uid $HOST_UID --gid $HOST_GID --disabled-password --gecos "" zango_user && \
echo 'zango_user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

# Set the non-root user as the default user
Expand Down
8 changes: 4 additions & 4 deletions deploy/docker_compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ services:
context: .
dockerfile: dev.dockerfile
args:
- UID=${UID}
- GID=${GID}
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
ports:
- "8000:8000"
depends_on:
Expand All @@ -47,8 +47,8 @@ services:
context: .
dockerfile: dev.dockerfile
args:
- UID=${UID}
- GID=${GID}
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
command: /bin/sh -c "cd ${PROJECT_NAME} && celery -A ${PROJECT_NAME} worker -l info"
volumes:
- .:/zango/
Expand Down
8 changes: 4 additions & 4 deletions deploy/docker_compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ services:
context: .
dockerfile: prod.dockerfile
args:
- UID=${UID}
- GID=${GID}
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
ports:
- "8000:8000"
depends_on:
Expand Down Expand Up @@ -58,8 +58,8 @@ services:
context: .
dockerfile: prod.dockerfile
args:
- UID=${UID}
- GID=${GID}
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
command: /bin/sh -c "cd ${PROJECT_NAME} && celery -A ${PROJECT_NAME} worker -l info"
volumes:
- .:/zango/
Expand Down
88 changes: 88 additions & 0 deletions deploy/docker_compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: "3.8"

services:
postgres:
image: postgres
env_file:
- .env
ports:
- "5432:5432"
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB} -p ${POSTGRES_PORT}",
]
interval: 5s
timeout: 5s
retries: 5
volumes:
- dev_db:/var/lib/postgresql/data

app:
build:
context: .
dockerfile: test.dockerfile
args:
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
ports:
- "8000:8000"
depends_on:
postgres:
condition: service_healthy
env_file:
- .env
environment:
ENV: dev
volumes:
- .:/zango/
healthcheck:
test: ["CMD-SHELL", "netstat -ltn | grep -q 8000"]
timeout: 5s
retries: 3

celery:
build:
context: .
dockerfile: test.dockerfile
args:
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
command: /bin/sh -c "cd ${PROJECT_NAME} && celery -A ${PROJECT_NAME} worker -l info"
volumes:
- .:/zango/
env_file:
- .env
depends_on:
app:
condition: service_healthy
redis:
condition: service_healthy

redis:
image: redis
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 3

celery_beat:
image: local/zango-base:latest
command: /bin/sh -c "cd ${PROJECT_NAME} && celery -A ${PROJECT_NAME} beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler"
volumes:
- .:/zango/
env_file:
- .env
depends_on:
app:
condition: service_healthy
redis:
condition: service_healthy


volumes:
dev_db:
8 changes: 4 additions & 4 deletions deploy/prod.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ RUN pip install gunicorn
RUN apt-get install -y net-tools
RUN apt install ffmpeg -y

ARG UID
ARG GID
ARG HOST_UID
ARG HOST_GID

# Update the package list, install sudo, create a non-root user, and grant password-less sudo permissions
RUN apt update && \
apt install -y sudo && \
groupadd -o -g ${GID} -r zango_user && \
adduser --uid $UID --gid $GID --disabled-password --gecos "" zango_user && \
groupadd -o -g ${HOST_GID} -r zango_user && \
adduser --uid $HOST_UID --gid $HOST_GID --disabled-password --gecos "" zango_user && \
echo 'zango_user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

# Set the non-root user as the default user
Expand Down
6 changes: 3 additions & 3 deletions deploy/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ To begin using Zango through Docker installation, ensure that Docker and Docker
- `--platform_username`: The user email of the platform user (Default: `[email protected]`).
- `--platform_user_password`: The password for the platform user (Default: `Zango@123`).

5. Docker is started as a non root user, run the below commands to export the host UID and GID
5. Docker is started as a non root user, run the below commands to export the host HOST_UID and HOST_GID

```bash
export UID=$(id -u)
export GID=$(id -g)
export HOST_UID=$(id -u)
export HOST_GID=$(id -g)
```

6. Run `docker compose up` in the project directory to start the project
Expand Down
22 changes: 22 additions & 0 deletions deploy/test.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM local/zango-base:latest

RUN apt update
RUN apt-get install -y net-tools
RUN apt install ffmpeg -y

ARG HOST_UID
ARG HOST_GID

# Update the package list, install sudo, create a non-root user, and grant password-less sudo permissions
RUN apt update && \
apt install -y sudo && \
groupadd -o -g $HOST_GID -r zango_user && \
adduser --uid $HOST_UID --gid $HOST_GID --disabled-password --gecos "" zango_user && \
echo 'zango_user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

# Set the non-root user as the default user
USER zango_user

COPY init.sh /zango/
WORKDIR /zango/
CMD ["/bin/sh", "init.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ To begin using Zango through Docker installation, ensure that Docker and Docker

5. Navigate to ``project_dir`` to start the project.

6. Docker is started as a non root user, run the below commands to export the host UID and GID
6. Docker is started as a non root user, run the below commands to export the host HOST_UID and HOST_GID

```bash
export UID=$(id -u)
export GID=$(id -g)
export HOST_UID=$(id -u)
export HOST_GID=$(id -g)
```

7. Run `docker compose up` in the project directory to start the project
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/e2e/stepDefinitions/appLaunch.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let appData = "";
Given(
"Admin logins successfully and lands on the home page of App panel",
() => {
cy.login("[email protected]", "Zelthy@123");
cy.login("[email protected]", "Zango@123");
const dynamicData = {
app_name: `app_${Math.floor(Math.random() * 10000)}`, //To create random text
app_description: `app_${Math.floor(Math.random() * 10000)}`, //To create random text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const time_zone = "Africa/Accra";
const date_format = "04 October 2017";
const date_time_format = "04 October 2017 01:48 PM";
Given("Admin logins successfully and lands on the details view of App", () => {
cy.login("[email protected]", "Zelthy@123");
cy.login("[email protected]", "Zango@123");
// cy.visit("http://localhost:3000/platform/apps/");
cy.fixture("appData").then(function (data) {
appData = data;
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/e2e/stepDefinitions/package.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import appPanelPageObjects from "../../support/pageObjectModel/appPanelPageObjec
let appData = "";

Given("User navigates to Package tab", () => {
cy.login("[email protected]", "Zelthy@123");
cy.login("[email protected]", "Zango@123");
cy.fixture("appData").then(function (data) {
appData = data;
cy.log(appData);
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/e2e/stepDefinitions/policies.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import appPanelPageObjects from "../../support/pageObjectModel/appPanelPageObjec
let appData = "";

Given("User navigates to policies tab", () => {
cy.login("[email protected]", "Zelthy@123");
cy.login("[email protected]", "Zango@123");
cy.fixture("appData").then(function (data) {
appData = data;
cy.log(appData);
Expand Down
Loading
Loading