Skip to content

Commit

Permalink
update to docker compose file #860
Browse files Browse the repository at this point in the history
  • Loading branch information
raprasad committed Nov 20, 2023
1 parent 09daeb2 commit 9d3838f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 96 deletions.
134 changes: 39 additions & 95 deletions README-DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,45 @@

This page lists contains rudimentary instructions for building the development environment with [Docker Compose](https://docs.docker.com/compose/).

## Building with Docker Compose
1. Clone the repo and `cd` into the directory.

`git clone https://github.com/opendp/dpcreator.git && cd dpcreator`

2. Tell Docker to turn on the webserver and database:

`docker-compose up`

If major configuration changes have been made (new dependencies, etc.) then the containers will need to be rebuilt:

`docker-compose up --build`

1. All subsequent commands should be run from the `server` directory
## Running with Docker Compose

1. **Clone the repository** and `cd` into the directory.
```
git clone https://github.com/opendp/dpcreator.git && \
cd dpcreator
```

2. **Run Docker**
- This will take a few minutes to run the first time! It includes postgres, redis, npm, etc.:
```
docker-compose up
```

`cd server`

3. The first time you run (or anytime schema changes have been made), open a separate Terminal, `cd` into the `dpcreator/` directory
and manually run this migration:

`docker-compose run server ./migrate.sh`

(In general, any command can be run by adding "docker-compose run server" to the beginning,
such as:

`docker-compose run server python manage.py shell`

which will drop you into the Django shell on the Docker container.)

## Running without Containers (not recommended)

1. Clone the repo and `cd` into the directory. `git clone https://github.com/opendifferentialprivacy/dpcreator.git && cd dpcreator`
1. Create virtual environment: `python3 -m venv venv`
1. Activate virtual environment: `. venv/bin/activate`
2. Install requirements: `pip install -r requirements.txt`
3. Ensure latest version of npm: `npm install -g npm@latest`
4. Install Vue.js project dependencies: `cd dpcreator/client && npm install`
5. Run the Vue.js dev server: `cd dpcreator/client && npm run serve`
- build for production: `npm run build`
6. `cd server/`
7. First time, run migrations: `python manage.py migrate`
8. Run Django dev server: `python manage.py runserver`
9. Open `http://127.0.0.1:8000/` in your browser.

**Note**: If major configuration changes have been made (new dependencies, etc.) then the containers will need to be rebuilt:
```
docker-compose up --build
```
3. **Initialize the database.** The first time you run (or anytime schema changes have been made):
- Open a separate Terminal
- `cd` into the `dpcreator/` directory
- Manually run this migration:
```
docker-compose run server ./migrate.sh
```
- Note: In general, any command can be run by adding "docker compose run server" to the beginning. For example:
```
# Run a Python shell on a Docker container with access to Django
docker-compose run server python manage.py shell
```
4. **Access DP Creator**
- Open http://127.0.0.1:80 in your browser
- The following credentials are available
- login/pw: `dev_admin`/`admin`

## Accessing the API

1. Follow steps 1-5 under Running, above
2. Open `http://127.0.0.1:8000/api/` in your browser.

## Accessing the API via command-line
1. Access your command-line terminal
2. Issue a HTTP command for the API area of interest. This example uses curl to issue the HTTP command. Note that the port you specify should match the port in the output of step 5 under Running, above
```
curl http://127.0.0.1:8000/api/
curl http://127.0.0.1:8000/api/users/
```

## Generating code diagrams
(not used)
1. Create a Python virtualenv to set up your environment `python3 -m venv venv`
2. Install PyDotPlus
`pip install pydotplus`
3. Install Django Extensions
`pip install django-extensions`
4. Configure your Django project to use Django Extensions in settings.py under `server/opendp-projects/`
```
INSTALLED_APPS = (
...
'django_extensions',
...
)
```
5. Invoke Django manager with graph models option, from the server/ subdirectory
`python manage.py graph_models -a -o opendpapp_models.png`
6. Use a browser or viewer to view the created png file, found in the `server/` subdirectory

(This is based on an [existing project](https://github.com/EugeneDae/django-vue-cli-webpack-demo) by EugeneDae. See his project for original documentation.)

## Generating code diagrams

1. Create a Python virtualenv to set up your environment `python3 -m venv venv`
2. Install PyDotPlus
`pip install pydotplus`
3. Install Django Extensions
`pip install django-extensions`
4. Configure your Django project to use Django Extensions in settings.py under `server/opendp-projects/`
```
INSTALLED_APPS = (
...
'django_extensions',
...
)
```
5. Invoke Django manager with graph models option, from the server/ subdirectory
`python manage.py graph_models -a -o opendpapp_models.png`
6. Use a browser or viewer to view the created png file, found in the `server/` subdirectory

(This is based on an [existing project](https://github.com/EugeneDae/django-vue-cli-webpack-demo) by EugeneDae. See his project for original documentation.)
1. Follow steps 1-4 under _Running with Docker Compose_
2. Open `http://127.0.0.1:8000/api/` in your browser.
3. The following credentials provide administrative access.
- login/pw: `dev_admin`/`admin`
4. Note, not all APIs are traditional REST APIs and they are not full documented.
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ services:
# - Built from "server/Dockerfile"
# ---------------------------------
server:
platform: linux/amd64
build: "./server"
# For production we will need to set
# these variables to point to a standalone instance
environment:
- DJANGO_SETTINGS_MODULE=opendp_project.settings.development
- VUE_APP_GOOGLE_CLIENT_ID="TEST. Set in docker-compose.yml"
- VUE_APP_ADOBE_PDF_CLIENT_ID="TEST. Set in docker-compose.yml"
- VUE_APP_ADOBE_PDF_CLIENT_ID=13c79907c6144590b17e8ef044324444
- SKIP_PDF_CREATION_FOR_TESTS=False
- SKIP_EMAIL_RELEASE_FOR_TESTS=False
- VUE_APP_WEBSOCKET_PREFIX=ws://
env_file:
- .env
command: sh -c "python manage.py show_debug_params && python manage.py runserver 0.0.0.0:8000"
Expand Down

0 comments on commit 9d3838f

Please sign in to comment.