4
4
5
5
Development Tools, Tips and Tricks
6
6
7
- * Installation
8
-
9
- If you need to install frequently (for example for testing), a
10
- script like this can be useful:
11
- #+BEGIN_EXAMPLE
12
- #!/bin/bash -x
13
-
14
- source=dbox
15
- installer=chroot
16
- git_branch=master
17
- nohup_out="nohup-$source-$git_branch-$installer.out"
18
-
19
- rm -f $nohup_out
20
- nohup time nice $source/install/{$installer.sh,settings.sh} cfg.sh \
21
- --git_branch=$git_branch --reboot=true > $nohup_out &
22
- sleep 1
23
- tail -f $nohup_out
24
- #+END_EXAMPLE
25
-
26
- The file ~cfg.sh~ overrides the default config settings (for example
27
- passwords):
28
- #+BEGIN_EXAMPLE
29
- apt_mirror='http://us-east-1.ec2.archive.ubuntu.com/ubuntu/'
30
-
31
- gmail_passwd=3omRoxtho
32
- development='true'
33
- #+END_EXAMPLE
34
-
35
- You can also override configuration settings from the command line.
36
-
37
- *Note:* The order of giving the settings is important. The last one
38
- overrides the previous settings.
39
-
40
-
41
7
* How to access the shell
42
8
43
9
When things are still in development and testing we need to access
44
10
the shell of the installed system in order to check log files,
45
11
debug, play with changing configurations, etc.
46
12
47
- When the installation is done on a chroot directory, then you simply
48
- switch to it with the command =chroot=:
49
- #+BEGIN_EXAMPLE
50
- chroot /var/chroot/bcl/
51
- #+END_EXAMPLE
52
-
53
- When the installation is done in a docker container, you have to install
54
- first the commands =nsenter= and =docker-enter= like this:
13
+ For this we can install the command =docker-enter=:
55
14
#+BEGIN_EXAMPLE
56
15
docker run -v /usr/local/bin:/target jpetazzo/nsenter
57
16
#+END_EXAMPLE
58
17
59
- Then you can access the shell of a running container like this:
18
+ Then access the shell of a running container like this:
60
19
#+BEGIN_EXAMPLE
61
20
docker-enter bcl
62
21
#+END_EXAMPLE
@@ -67,19 +26,27 @@ Development Tools, Tips and Tricks
67
26
68
27
* Install sshd
69
28
70
- In order to access the server remotely through drush, ssh-client,
71
- etc. you can install *sshd* with the script ~dev/install-sshd.sh~,
72
- like this:
29
+ We want to start a sshd server on port 2201 inside the container,
30
+ but when we created the container with =docker run= we did not think
31
+ about forwarding this port. We have to destroy this container and
32
+ create a new one, with an addition =-p= option for the
33
+ port 2201. But first we should use the command =docker commit= to
34
+ save to a new image any configurations and data that we already have
35
+ in this container.
73
36
#+BEGIN_EXAMPLE
74
- chroot /var/chroot/bcl/
75
- cd /usr/local/src/btr_client/
76
- dev/install-sshd.sh
37
+ docker stop bcl
38
+ docker commit bcl btr_client:1
39
+ docker images
40
+ docker rm bcl
41
+ docker run -d --name=bcl --hostname=example.org \
42
+ -p 80:80 -p 443:443 -p 2201:2201 btr_client:1
77
43
#+END_EXAMPLE
78
44
79
- By default it will install and run a sshd that listens on the port *2201*,
80
- but you can also give it the port number as an argument:
45
+ Now we can enter the container and start the sshd server:
81
46
#+BEGIN_EXAMPLE
82
- dev/install-sshd.sh 2211
47
+ docker-enter bcl
48
+ cd /usr/local/src/btr_client/
49
+ dev/install-sshd.sh 2201
83
50
#+END_EXAMPLE
84
51
85
52
@@ -88,12 +55,10 @@ Development Tools, Tips and Tricks
88
55
There are two webservers installed, apache2 and nginx (with php5-fpm
89
56
and memcached). For development Apache2 can be more suitable, while
90
57
for production NGINX is supposed to be more responsive in high load.
91
- It also has built-in cache and its configuration is tweaked for DoS
92
- protection, short timeout, etc.
93
58
94
59
We can choose one of them like this:
95
60
#+BEGIN_EXAMPLE
96
- chroot /var/chroot/ bcl/
61
+ docker-enter bcl
97
62
cd /usr/local/src/btr_client/
98
63
dev/webserver.sh apache2
99
64
dev/webserver.sh nginx
@@ -104,9 +69,9 @@ Development Tools, Tips and Tricks
104
69
105
70
Clones of the main site can be used for development and testing.
106
71
107
- Inside the chroot you can make a clone for development like this:
72
+ Inside the container you can make a clone for development like this:
108
73
#+BEGIN_EXAMPLE
109
- chroot /var/chroot/ bcl/
74
+ docker-enter bcl
110
75
cd /usr/local/src/btr_client/
111
76
dev/clone.sh bcl bcl_dev1
112
77
dev/clone.sh bcl_dev1 bcl_test1
@@ -123,7 +88,7 @@ Development Tools, Tips and Tricks
123
88
Other clones like this can be created for testing etc. To cleanup
124
89
(remove/erase) a clone, you can use *clone_rm.sh* like this:
125
90
#+BEGIN_EXAMPLE
126
- chroot /var/chroot/ bcl/
91
+ docker-enter bcl
127
92
cd /usr/local/src/btr_client/
128
93
dev/clone_rm.sh bcl_dev1
129
94
dev/clone_rm.sh bcl_test1
@@ -134,7 +99,7 @@ Development Tools, Tips and Tricks
134
99
a development copy with a live or testing one), with the script
135
100
=dev/config.php=:
136
101
#+BEGIN_EXAMPLE
137
- chroot /var/chroot/ bcl/
102
+ docker-enter bcl
138
103
cd /usr/local/src/btr_client/
139
104
drush @bcl_dev php-script dev/config.php dev2
140
105
#+END_EXAMPLE
@@ -149,7 +114,7 @@ Development Tools, Tips and Tricks
149
114
150
115
It can be done with the script =dev/reinstall.sh=:
151
116
#+BEGIN_EXAMPLE
152
- chroot /var/chroot/ bcl/
117
+ docker-enter bcl
153
118
cd /usr/local/src/btr_client/
154
119
nohup nice dev/reinstall.sh settings.sh &
155
120
tail -f nohup.out
@@ -165,7 +130,7 @@ Development Tools, Tips and Tricks
165
130
Drupal and nothing else, can be done with the script
166
131
=dev/reinstall-db.sh=:
167
132
#+BEGIN_EXAMPLE
168
- chroot /var/chroot/ bcl/
133
+ docker-enter bcl
169
134
cd /usr/local/src/btr_client/
170
135
nohup nice dev/reinstall-db.sh @bcl_dev &
171
136
tail -f nohup.out
@@ -190,7 +155,7 @@ Development Tools, Tips and Tricks
190
155
the code (the whole Drupal directory) and the database. It can be
191
156
done like this:
192
157
#+BEGIN_EXAMPLE
193
- chroot /var/chroot/ bcl/
158
+ docker-enter bcl
194
159
cd /usr/local/src/btr_client/
195
160
dev/snapshot.sh make @bcl
196
161
dev/snapshot.sh make @bcl_dev
@@ -221,20 +186,56 @@ Development Tools, Tips and Tricks
221
186
#+END_EXAMPLE
222
187
223
188
224
- * Accessing the code of the application from outside chroot
225
-
226
- In order to access easily the code of the application from outside
227
- chroot, you can create a symbolic link like this:
228
- #+BEGIN_EXAMPLE
229
- cd /var/chroot/
230
- ln -s bcl/var/www/bcl_dev/profiles/btr_client/ \
231
- bcl_dev
232
- #+END_EXAMPLE
233
-
234
- Now you can go to */var/chroot/dev/* and start /emacs/ or any other
235
- tools. This way you don't have to install /emacs/ or any other
236
- development tools inside the /chroot/ and can use the best of
237
- development tools that your host system can offer.
189
+ * Accessing the code of the application from outside container
190
+
191
+ In general it is not possible to directly access the directories and
192
+ files of of a container from the host system. However we can use
193
+ the docker /volumes/ to share directories between the container and
194
+ the host. It can be done like this:
195
+
196
+ + First we make a backup of the directory inside the container that
197
+ we want to share:
198
+ #+BEGIN_EXAMPLE
199
+ docker-enter bcl
200
+ cd /var/www/bcl_dev/profiles/
201
+ cp -a btr_client/ btr_client-bak
202
+ exit
203
+ #+END_EXAMPLE
204
+
205
+ + Then we save the image of the container as =btr_client:dev=, in order
206
+ to start a new container based on it:
207
+ #+BEGIN_EXAMPLE
208
+ docker stop bcl
209
+ docker commit bcl btr_client:dev
210
+ docker images
211
+ #+END_EXAMPLE
212
+
213
+ + Next we create a new container that shares a directory with the
214
+ host system (using the option =-v=):
215
+ #+BEGIN_EXAMPLE
216
+ docker run -d --name=bcl_dev --hostname=dev.example.org \
217
+ -v $(pwd)/bcl_dev:/var/www/bcl_dev/profiles/btr_client/
218
+ -p 80:80 -p 443:443 btr_client:dev
219
+ #+END_EXAMPLE
220
+ *Note:* The container *bcl* must be stoped before we create and
221
+ start the new container *bcl_dev*, otherwise the ports 80 and 443
222
+ will conflict.
223
+
224
+ + Finally we enter the container and move the content of the backup
225
+ directory to the shared directory:
226
+ #+BEGIN_EXAMPLE
227
+ docker-enter bcl_dev
228
+ cd /var/www/bcl_dev/profiles/btr_client/
229
+ cp -a ../btr_client-bak/* .
230
+ cp -a ../btr_client-bak/.* .
231
+ rm -rf ../btr_client-bak/
232
+ exit
233
+ #+END_EXAMPLE
234
+
235
+ Now we can go to the directory *bcl_dev/* and start /emacs/ or any
236
+ other tools. This way we don't have to install /emacs/ or any other
237
+ development tools inside the container and we can use the best of
238
+ development tools that the host system can offer.
238
239
239
240
240
241
* Pushing commits
@@ -289,7 +290,7 @@ Development Tools, Tips and Tricks
289
290
At some point, all the modifications on the local copy of the
290
291
application (sandbox) have to be transferred to a public server,
291
292
where the application is in "production", performing "live". On that
292
- public server there is the same /chroot/ environment as in the
293
+ public server there is the same docker container as in the
293
294
development server. The synchronization of the application can be
294
295
done via git push and pull.
295
296
@@ -371,8 +372,8 @@ Development Tools, Tips and Tricks
371
372
option on the config file will make sure that it fails.
372
373
373
374
For drush commands to work remotely, *ssh* daemon has to be running
374
- on the remote server, inside the chroot environment . By default it
375
- is not installed, but it can be installed with the script
375
+ on the remote server, inside the docker container . By default it is
376
+ not installed, but it can be installed with the script
376
377
*dev/install-sshd.sh*. This script will also take care to change the
377
378
ssh port to *2201*, in order to avoid any conflicts with any
378
379
existing daemon on the host environment, and also for increased
0 commit comments