Skip to content

Commit 459a07a

Browse files
author
Rahul Kumar Yadav
committed
doc: improvement in one-click-dev.md and some changes in dockerFile
1 parent 8524177 commit 459a07a

11 files changed

+94
-403
lines changed

Dockerfile

+3-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ RUN pip install -r /tmp/requirements.txt --no-cache-dir --ignore-installed
3131
COPY --chown=app:root . .
3232

3333
FROM base as test
34-
ENTRYPOINT [ "python" ]
35-
CMD [ "-m", "pytest", "-v", "--cov", "--disable-warnings" ]
34+
CMD ["python" "-m", "pytest", "-v", "--cov", "--disable-warnings" ]
3635

3736

3837
FROM base as celery
39-
ENTRYPOINT [ "python" ]
40-
CMD ["-m","celery", "-A", "BrowserStackAutomation", "worker" ,"-n","worker1" ,"-l","DEBUG"]
38+
COPY ./docker-entrypoint-celery.sh /tmp/entrypoint-celery.sh
39+
ENTRYPOINT ["/tmp/entrypoint-celery.sh"]
4140

4241
FROM base as web
4342
COPY ./docker-entrypoint.sh /tmp/entrypoint.sh

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all: build test lint
55
## make dev : Build and start docker containers - (web/test/db)
66
.PHONY: dev
77
dev:
8-
@export DJANGO_SETTINGS_MODULE=BrowserStackAutomation.settings && docker-compose build && docker-compose up -d
8+
@docker-compose build && docker-compose up -d
99

1010
## make build : Build and start docker containers - (web and db)
1111
.PHONY: build

config.json.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"access_modules": {
1111
"git_urls": [
12-
"https://<user>:<github-token>@github.com/browserstack/enigma-public-access-modules.git"
12+
"https://github.com/browserstack/enigma-public-access-modules.git"
1313
]
1414
},
1515
"enigmaGroup": {

docker-entrypoint-celery.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
python manage.py createcachetable
4+
python manage.py migrate # Apply database migrations
5+
python manage.py collectstatic --clear --noinput # clearstatic files
6+
python manage.py collectstatic --noinput # collect static files
7+
8+
# directory for gunicorn logs and django app logs
9+
mkdir -p /ebs/logs
10+
touch /ebs/logs/bstack.log
11+
tail -n 0 -f /ebs/logs/bstack.log &
12+
13+
# run scripts/clone_access_modules.py to clone access modules
14+
python scripts/clone_access_modules.py
15+
pip install -r Access/access_modules/requirements.txt --no-cache-dir --ignore-installed
16+
17+
echo Starting celery
18+
python3 -m celery -A BrowserStackAutomation worker -n worker1 -l DEBUG

docker-entrypoint.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ touch /ebs/logs/bstack.log
1111
tail -n 0 -f /ebs/logs/bstack.log &
1212

1313
# run scripts/clone_access_modules.py to clone access modules
14+
1415
python scripts/clone_access_modules.py
15-
python scripts/make_config_and_readme.py
1616
pip install -r Access/access_modules/requirements.txt --no-cache-dir --ignore-installed
17-
python scripts/github_test.py
18-
python scripts/merge_config.py
17+
1918

2019
echo Starting Django runserver.
2120
python manage.py runserver 0.0.0.0:8000

docs/one-click-dev.md

+48-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
# one-click-dev-setup
1+
# Setup for Local Development
22

3+
## Pre-requisistes
34

4-
### Pre-requisistes
5+
### Install Docker
56

6-
- Install Docker
7-
```
8-
brew install docker docker-compose
9-
```
7+
- For macOS(brew)
8+
```
9+
brew install docker docker-compose
10+
```
11+
- For windows/linux/macOS refer to
12+
https://docs.docker.com/get-docker/
1013
11-
- Install Docker Container Runtime
14+
### Install Docker Container Runtime
1215
https://github.com/abiosoft/colima
1316
```bash
1417
brew install colima
@@ -22,7 +25,7 @@ git clone https://github.com/browserstack/enigma-public-central.git
2225
```
2326
1. Create .env file from .env.sample file. Edit the DOCKERIMAGE to the latest image URL.
2427
2. copy config.json.sample to config.json
25-
```pan
28+
```bash
2629
{
2730
"googleapi": {
2831
"SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "",
@@ -34,7 +37,7 @@ git clone https://github.com/browserstack/enigma-public-central.git
3437
},
3538
"access_modules": {
3639
"git_urls": [
37-
"https://<user>:<github-token>@github.com/browserstack/enigma-public-access-modules.git"
40+
"https://github.com/browserstack/enigma-public-access-modules.git"
3841
]
3942
},
4043
"enigmaGroup": {
@@ -55,12 +58,45 @@ git clone https://github.com/browserstack/enigma-public-central.git
5558
}
5659
}
5760
}
61+
```
62+
### for private repo in git_urls in `config.json`
63+
```bash
64+
"https://<git-username>:<github-token>@github.com/browserstack/enigma-public-access-modules.git"
65+
```
66+
where `github-token` is a pat token from https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
5867

59-
replace this values in config.json
60-
celery-broker-url= "redis://localhost:6379"
61-
celery-result-backend-url = "redis://localhost:6379"
6268

69+
### Add the config of broker and database in `config.json`
70+
- For self-hosted celery
71+
```bash
72+
celery-broker-url="redis://localhost:6379/0"
73+
celery-result-backend-url="redis://localhost:6379/0"
74+
```
75+
- For self-hosted databases
76+
```bash
77+
celery-broker-url="redis://localhost:6379/0"
78+
celery-result-backend-url="db+mysql://root@localhost:3306/<name_of_db>"
79+
```
80+
### Add the config of custom access-module repos `config.json`
81+
82+
```bash
83+
"access_modules": {
84+
....
85+
86+
"aws_access": {
87+
"aws_accounts": [
88+
{
89+
"account": "<your-account>",
90+
"access_key_id": "<access_key_id>",
91+
"secret_access_key": "<secret_access_key>"
92+
}
93+
]
94+
},
95+
.....
96+
},
6397
```
98+
Add configuration for all access_module as here added for aws_access.
99+
64100
3. Start the service
65101
```bash
66102
make dev
@@ -69,5 +105,3 @@ make dev
69105
```bash
70106
make logs
71107
```
72-
73-

scripts/clone_access_modules.py

+21-25
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,44 @@
1717
folder_name = url.split("/").pop()[:-4]
1818
folder_path = "./Access/access_modules/" + folder_name
1919
try:
20-
Repo.clone_from(url, folder_path)
21-
# move all folders, not files in the cloned repo to the access_modules
22-
# folder except the .git, .github and secrets folder
23-
for file in os.listdir(folder_path):
24-
if (
20+
Repo.clone_from(url, folder_path)
21+
# move all folders, not files in the cloned repo to the access_modules
22+
# folder except the .git, .github and secrets folder
23+
for file in os.listdir(folder_path):
24+
if (
2525
os.path.isdir(folder_path + "/" + file)
2626
and file != ".git"
2727
and file != ".github"
2828
and file != "secrets"
2929
) :
30-
os.rename(
31-
folder_path + "/" + file, "./Access/access_modules/" + file
32-
)
30+
os.rename(
31+
folder_path + "/" + file, "./Access/access_modules/" + file
32+
)
3333

34-
if(file == "requirements.txt"):
35-
36-
current_requirements_file = folder_path + "/" + file
37-
#Read the requirements
38-
with open(requirements_file, 'r') as f1:
34+
if(file == "requirements.txt"):
35+
current_requirements_file = folder_path + "/" + file
36+
#Read the requirements
37+
with open(requirements_file, 'r') as f1:
3938
requirements1 = f1.readlines()
4039

41-
with open(current_requirements_file, 'r') as f1:
40+
with open(current_requirements_file, 'r') as f1:
4241
requirements2 = f1.readlines()
4342

44-
# Merge the requirements
45-
merged_requirements = list(set(requirements1 + requirements2))
43+
# Merge the requirements
44+
merged_requirements = list(set(requirements1 + requirements2))
4645

47-
#update the requirements.txt
48-
with open(requirements_file, 'w') as out_file:
46+
#update the requirements.txt
47+
with open(requirements_file, 'w') as out_file:
4948
for requirement in sorted(merged_requirements):
5049
out_file.write(requirement)
5150

52-
53-
54-
print("Cloning successful!")
55-
51+
print("Cloning successful!")
5652
except Exception as e:
5753
print(e)
58-
5954
print("failed cloning " + folder_name + ".")
60-
# remove the cloned repo folder entirely with all its contents which
61-
# includes folders and files using shutil.rmtree()
55+
56+
# remove the cloned repo folder entirely with all its contents which
57+
# includes folders and files using shutil.rmtree()
6258
# shutil.rmtree() sometimes throws an error on windows,
6359
# so we use try and except to ignore the error
6460
try:

0 commit comments

Comments
 (0)