docker-wagtail-develop/README.md

133 wiersze
4.3 KiB
Markdown
Czysty Zwykły widok Historia

2020-01-24 15:26:51 +00:00
docker-wagtail-develop
======================
A script to painlessly set up a Docker environment for development of Wagtail - inspired by [vagrant-wagtail-develop](https://github.com/wagtail/vagrant-wagtail-develop)
Initial work in Bristol sprint January 2020 by [esperk](https://github.com/esperk) and [saevarom](https://github.com/saevarom).
Setup
-----
**Requirements:** [Docker](https://www.docker.com/) and Docker Compose (Docker Compose is included with Docker Desktop for Mac and Windows).
Open a terminal and follow those instructions:
```sh
# 1. Decide where to put the project. We use "~/Development" in our examples.
cd ~/Development
# 2. Clone the docker-wagtail-develop repository in a new "wagtail-dev" folder.
git clone https://github.com/wagtail/docker-wagtail-develop.git wagtail-dev
2020-01-24 15:26:51 +00:00
# 3. Move inside the new folder.
cd wagtail-dev/
# 4. Run the setup script. This will check out the bakerydemo project and local copies of wagtail and its dependencies.
2020-01-24 15:26:51 +00:00
./setup.sh
# 5. Build the containers
docker-compose build
```
It can take a while (typically 15-20 minutes) to fetch and build all dependencies and containers.
Here is the resulting folder structure:
```sh
.
├── libs # Supporting libraries to develop Wagtail against.
├── wagtail # Wagtail repository / codebase.
└── bakerydemo # Wagtail Bakery project used for development.
```
Reworked the database and Wagtail installation setup (#18) * Broke out the initial database stuff into a separate one-time script. Also enhanced the .dockerignore file to make image builds a lot faster, and added .idea to the .gitignire, so that PyCharm projects won't get added to the repo. * Reworked the database and Wagtail installation setup In order to improve the development experience while using docker-wagtail-develop, I reorganized how the database setup is done, and how and when Wagtail gets installed into the python environment inside the docker container. Plus a few other changes. 1. Database. The migration and initial data load steps are now done once, by the user, during initial setup (setup-sb.sh), rather than happening at the start of every `docker-compose up`. This is possible because the postgres data is already being stored in a Docker Volume, so it persists across container executions. 2. Wagtail is now installed into the 'web' docker container by the Dockerfile, rather than docker-compose. This lets Docker skip that step if nothing has changed in Wagtail since the last build (admittedly, not super common, given that this project is for developing Wagtail), and generally makes the whole process a lot cleaner. 3. I added a bunch of stuff to .dockerignore, which significantly cuts down on the 'web' and 'frontend' images filesizes and build times. 4. I gave each of the three containers specific names, so that they can be more easily executed into for things like running manage.py commands or other OS stuff. This resulted in the connect string for the postgres DB needing to be tweaked. 5. I changed the 'frontend' container's copy command for the node_modules folder to use the -u flag, which allows cp to skip any files that haven't changed since the last time the copy was run. This *dramatically* speeds up the startup of the 'frontend' container on all but the very first execution (which does the initial copy into the host's wagtail folder). I really wanted to find a way to put node_modules into a Docker Volume, but since you can't write to Volumes during the image build process, that unfortunately negates any value-add that we might have gotten from their use in this case.
2020-10-09 16:58:58 +00:00
Once the build is complete:
2020-01-24 15:26:51 +00:00
```sh
# 6. Start your containers and wait for them to finish their startup scripts.
2020-01-24 15:26:51 +00:00
docker-compose up
2022-01-18 15:12:14 +00:00
```
You might see a message like this the first time you run your containers. This is normal because the frontend container has not finished building the assets for the Wagtail admin. Just wait a few seconds for the frontend container to finish building and then stop and start your containers again (Ctrl+C + `docker-compose up`).
```
WARNINGS:
?: (wagtailadmin.W001) CSS for the Wagtail admin is missing
HINT:
Most likely you are running a development (non-packaged) copy of
Wagtail and have not built the static assets -
see https://docs.wagtail.org/en/latest/contributing/developing.html
File not found: /code/wagtail/wagtail/admin/static/wagtailadmin/css/normalize.css```
```
```sh
# 7. Now in a new shell, run the databse setup script. The database will be persisted across container executions by Docker's Volumes system so you will only need to run this commmand the first time you start the database.
2021-03-04 21:58:52 +00:00
./setup-db.sh
2020-01-24 15:26:51 +00:00
# Success!
```
2020-05-14 20:11:22 +00:00
If you're running this on Linux you might get into some privilege issues that can be solved using this command (tested on Ubuntu):
```sh
CURRENT_UID=$(id -u):$(id -g) docker-compose -f docker-compose.yml -f docker-compose.linux.yml up
```
2020-01-24 15:26:51 +00:00
- Visit your site at http://localhost:8000
- The admin interface is at http://localhost:8000/admin/ - log in with `admin` / `changeme`.
What you can do
---------------
### See a list of running containers
2020-01-24 15:26:51 +00:00
```sh
$ docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------
db docker-entrypoint.sh postgres Up 5432/tcp
frontend docker-entrypoint.sh /bin/ ... Up
web ./manage.py runserver 0.0. ... Up 0.0.0.0:8000->8000/tcp
2020-01-24 15:26:51 +00:00
```
### Run tests
```sh
docker-compose exec -w /code/wagtail web python runtests.py
```
### You can open a django shell session
2020-01-24 15:26:51 +00:00
```sh
docker-compose exec web python manage.py shell
2020-01-24 15:26:51 +00:00
```
### You can open a shell on the web server
2020-01-24 15:26:51 +00:00
```sh
docker-compose exec web bash
2020-01-24 15:26:51 +00:00
```
### You can open a shell to work with the frontend code (Node/NPM)
```sh
docker-compose exec frontend bash
```
2020-01-24 15:26:51 +00:00
Getting ready to contribute
---------------------------
2020-01-24 15:44:38 +00:00
Here are other actions you will likely need to do to make your first contribution to Wagtail.
2020-01-24 15:26:51 +00:00
2020-01-24 15:44:38 +00:00
Set up git remotes to Wagtail forks (run these lines outside of the Docker instances, on your machine):
2020-01-24 15:26:51 +00:00
```sh
cd ~/Development/wagtail-dev/wagtail
# Change the default origin remote to point to your fork.
git remote set-url origin git@github.com:<USERNAME>/wagtail.git
# Add wagtail/wagtail as the "upstream" remote.
git remote add upstream git@github.com:wagtail/wagtail.git
# Pull latest changes from all remotes / forks.
git pull --all
```
2020-01-24 10:41:58 +00:00
2020-01-24 15:43:25 +00:00
TODO
----
* Set up an elasticsearch service container
2020-02-15 11:23:01 +00:00
* Test on Windows and Linux