-
Notifications
You must be signed in to change notification settings - Fork 5
Docker Compose Based Development Environment #41
Conversation
Would be cool if you took a look too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, review added! A few minor details then a suggestion to add an "assets" container to do cotech images and gulp watching.
docker-compose.yml
Outdated
ports: | ||
- 13306:3306 | ||
volumes: | ||
- ./docker/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use consistent folder mapping names, I used - ./docker/db/data:/docker-entrypoint-initdb.d
in af.
docker-compose.yml
Outdated
WP_ENV: development | ||
WP_HOME: http://localhost:18080 | ||
WP_SITEURL: http://localhost:18080/wp | ||
COMPOSER_ALLOW_SUPERUSER: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better in Dockerfile as an ENV
setting (as it's not a user/app specific configuration)
Like here https://github.com/api-platform/api-platform/blob/master/Dockerfile#L38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
export COMPOSER_NO_INTERACTION=1 | ||
|
||
# Composer does not warn when we are superuser inside the Docker container | ||
export COMPOSER_ALLOW_SUPERUSER=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, defined in another place too! I think Dockerfile is still the best place for it, set and forget.
|
||
cd /var/www/html | ||
|
||
composer update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched to using composer install
, the update command will actually change the composer.lock file to find newer versions where possible, we want it to just install what composer.lock says.
This is also why we need an image registry so we aren't copying this things around any more :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem overall. If we iterate on this docker-entrypoint.sh
, how do we make sure it is kept up to date across projects as we improve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
echo "Compiling WordPress theme" | ||
|
||
cd /var/www/html/web/app/themes/coop-tech-oowp-theme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to think a bit more about this. When we have a standard wordpress base image we will not be able to use this approach there.
In this case I would create another container for the gulp tasks for two reasons:
- keeps the wordpress image focused on doing one thing in preparation for our custom image
- we can provide a better dev experience by running
gulp watch
to recompile-on-change (as it uses this internally https://laravel.com/docs/5.0/elixir#gulp)
Having to run composer install at top-level and inside the theme seems less than ideal to me. One approach is to define the theme directory as a local composer repository and so long as it is marked as being a theme, the wordpress install would ensure it ends up in the correct place (or if it is already in the correct place I think the repository configuration has some options for that). See the "path" method on https://getcomposer.org/doc/05-repositories.md.
One of the outlandish projects uses this approach previously, but then after moving to bedrock layout it was easier to just add the plugins to the repo directly (they did not need any composer install).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... an alternative to the local directory composer repo would be to get the entrypoint script to descend the themes (and plugins/mu-plugins?) and run composer install if it finds a composer.json file...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would be nice for a separate container to run gulp watch
etc but this sort of stuff would still be needed.
However, the problem is that the WordPress image is not in a functioning state without running these commands. The two are intertwined. You need the asset compilation and you need the other bits to be present or the WordPress theme doesn't work. If you said "you need both containers running to be this site" then we have defeated the object of the exercise.
The reason for it running inside the theme was I was copying the install instructions in the repository, but looking at the composer.json
this is likely not needed.
./node_modules/gulp/bin/gulp.js | ||
|
||
cd /var/www/html | ||
curl https://www.coops.tech/cotech-images.tgz > cotech-images.tgz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about keeping wordpress image dedicated. Also these will get outdated over time, although not much we can do about that for now.
Perhaps if there was a gulp container, the command
(CMD override in docker-compose.yml) could run this before running gulp watch
? So the gulp container purpose is about "assets".
Also, don't want to run this each time we start the container, so should check if it is already there...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same response - the container isn't in a functioning state until these assets are compiled.
How can we move forward on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked on Slack - basically going to go with an assets container here.
This is great :-) There were a few small issues like I needed to do a recursive chown, but it seems to work really well! |
@chriscroome What recursive chown is needed mate? Need to add this in. |
This is the error I had:
I'm sorry I don't recall exactly which directory was |
I have installed everything from scratch on a Debian Stretch machine and documented what I did on the wiki, when I got to the tasks in the post-merge git hooks script I hit the permissions issue:
It is the
So a |
I haven't changed anything about the Git hooks stuff here, see the diff, so if you are having problems its not the result of this merge request which is only about Docker Compose and doesn't touch these files. |
The only issue I have raised is the ownership of the |
Just to add that without running the following tasks after running
These are the things that are run when the live or dev site are updated. |
@conatus so, a summary of my changes:
|
And final change:
|
@chriscroome all this should be addressed now, just to make it clear where they each happen:
This is to install composer deps from root dir, runs in wordpress docker entrypoint script each time container is started. Uses
This is also run in wordpress docker entrypoint by checking for a
This is run (although using yarn) in the
This also runs in the |
@chriscroome and to clarify - all this docker stuff only applies for development environments, perhaps production deployment using docker could be looked into in the future, but this is not addressed here at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great stuff. Nice one.
# we just check for one path that we assume will be created when we unpack | ||
TEST_PATH="$DEST/app/uploads/2017" | ||
|
||
if [ ! -e $TEST_PATH ] || [[ $* == *--force* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More shell scripts is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it runs in a controlled environment (i.e. a docker image that we choose and is always the same), and is pretty simple. I don't see an alternative, but happy if you have a suggestion.
Requirements are probably:
- downloads images automatically on first use
- does not download every time the container is started if they already exist
- can override if needed to get download even if they already exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just joking - I see no other way you could do this - you know my feelings about shell scripts, but this is cool.
@@ -0,0 +1,15 @@ | |||
#!/bin/bash | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set -e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks
@chriscroome I just read https://wiki.coops.tech/wiki/CoTech_WordPress#Debian_Stretch_dev_env - no need to install anything other than docker on your dev machine. Everything else (composer, nodejs, php, php extensions, etc) is installed inside docker (this is why it's so useful!). So, if you feel like it you can do a fresh install and skip the Install Nodejs, Install Composer and PHP modules, and Run Composer steps. |
If you could look to @nicksellen's instructions - i.e. you don't need to install anything apart from Docker - it would be really cool to get this reviewed as soon as possible. Thanks a lot mate! |
Sorry not to have had the time and energy to looks at this sooner. So, removing the
Checking with
Sorry I'm unclear how to start the docker container in order to be able to do things like running |
I seem to be getting somewhere:
Results in a WordPress web install running at http://172.17.0.2/wp-admin/setup-config.php |
Is |
Install locally. Then things should just work. Its the only command you
need, normal use of Docker isn't required.
…On Mon, 3 Jul 2017 22:13 Chris Croome, ***@***.***> wrote:
Is docker-compose installed in a container
<https://docs.docker.com/compose/install/#install-as-a-container> or so I
need to install that locally in addition to docker-ce?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#41 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AATZJgDikpuXvSvum1bdCdzb6XXg-65vks5sKVl2gaJpZM4OFhom>
.
|
This command downloads and starts the official wordpress docker image from docker hub [1]. It doesn't relate to the cotech docker-compose setup. docker-compose often comes bundled with docker setups as it's an official tool now, but you might need to install it separately. Anything version >=1.6 should be sufficient. To update an existing docker-compose installation you may need to rebuild the images, you can add the
If nothing changed it won't actually do much (you'll see lots of The README should hopefully contain enough instructions anyway :) Let me know if I can help more, feel free to ping me on cotech slack too. |
Thanks for you patience, it is up and running now and I have updated the wiki, Debian Stretch has docker-compose (1.8.0-2) and that seems to work OK. |
This allows you to run:
docker-compose up
and have a working development environment on your machine. Or follow the instructions in theREADME.md
for a bit more detail.@chriscroome have a go with this and see if it works for you.
I'll then add in the piece which updates the images programmatically.