@@ -3,8 +3,19 @@ Docker image
3
3
4
4
We provide a docker image (defined in :gh_blob: `Dockerfile `) that can be used to
5
5
easily get an instance of CMS running locally with all the necessary
6
- dependencies. We also provide a :gh_blob: `docker-compose.test.yml ` files that
7
- uses said docker image to run the tests.
6
+ dependencies. We also provide:
7
+
8
+ * :gh_blob: `cms-test.sh `: This file uses :gh_blob: `docker-compose.test.yml ` to
9
+ spawn a volatile database (not persisted on disk) as well as a CMS instance
10
+ that automatically runs all tests.
11
+
12
+ * :gh_blob: `cms-dev.sh `: This file uses :gh_blob: `docker-compose.dev.yml ` to
13
+ spawn a database (persisted in the local ``.dev/postgres-data `` folder
14
+ within the repository) as well as a CMS instance that only runs `bash `,
15
+ leaving you with a shell from where you can start cms services and servers.
16
+ The DB port and CMS server ports are also automatically forwarded on the
17
+ host machine (respectively to ``15432 `` for the database, and ``8888-8890 ``
18
+ for CMS).
8
19
9
20
Make sure that you have a recent version of Docker installed, as well as Docker
10
21
Compose.
@@ -14,45 +25,109 @@ Compose.
14
25
Running tests
15
26
=============
16
27
17
- First you need to build the docker image, then you use it to run the tests.
28
+ You can simply run:
29
+
30
+ .. sourcecode :: bash
31
+
32
+ ./cms-test.sh
33
+
34
+ Or, you can issue the full command (that is defined in ``cms-test.sh ``) which
35
+ is similar to:
36
+
37
+ .. sourcecode :: bash
38
+
39
+ docker compose -p someprojectname -f docker-compose.test.yml run --build --rm testcms
18
40
19
41
.. note ::
20
42
43
+ Some versions of docker require to specify ``-p ``, some version will fill it
44
+ for you based on the current folder's name (which for us would be equivalent
45
+ to passing ``-p cms ``).
46
+
21
47
The ``-p `` flag is used as a namespace for the containers that will be
22
48
created. When you're running tests on a separate branch, it can be useful to
23
- include the branch name there, to avoid any conflict. (You can also omit the
24
- flag and specify the name via the ``COMPOSE_PROJECT_NAME `` environment
25
- variable.)
49
+ include the branch name there, to avoid any conflict. The ``cms-test.sh ``
50
+ script uses the **name of the current git branch ** and passes it to ``-p ``.
51
+
52
+ Note also that if you are not part of the ``docker `` group then you'll need
53
+ to run every docker command with ``sudo ``, including ``sudo ./cms-test.sh ``.
54
+ We recommend adding yourself to the ``docker `` group.
55
+
56
+ What the ``cms-test.sh `` command does is: first build a fresh CMS image when
57
+ necessary, and then create (assuming you didn't specify the ``-p `` flag) a
58
+ ``cms-testdb-1 `` container for the database, and a
59
+ ``cms-testcms-run-<random_string> `` container for CMS.
60
+
61
+ The database container **will not ** be automatically deleted, while the CMS
62
+ container will be automatically deleted upon exiting (because of the ``--rm ``
63
+ flag).
64
+
65
+ To delete the ``cms-testdb-1 `` container after testing you can run:
66
+
67
+ .. sourcecode :: bash
26
68
27
- If you are not part of the ``docker `` group, then you need to run every
28
- docker command with ``sudo ``.
69
+ docker rm -f cms-testdb-1
29
70
30
- To build the image:
71
+ Developing CMS
72
+ ==============
73
+
74
+ To run a local development instance of CMS, you can simply run:
31
75
32
76
.. sourcecode :: bash
33
77
34
- docker compose -p cms -f docker-compose.test.yml build testcms
78
+ ./ cms-dev.sh
35
79
36
- To run the tests:
80
+ Or, you can issue the full command (that is defined in ``cms-dev.sh ``) which is
81
+ similar to:
37
82
38
83
.. sourcecode :: bash
39
84
40
- docker compose -p cms -f docker-compose.test.yml run --rm testcms
85
+ docker compose -p someprojectname -f docker-compose.dev.yml run --build --rm --service-ports devcms
86
+
87
+ The command will build a fresh CMS image when necessary, and drop you into a
88
+ bash prompt where the repository is mounted on ``~/cms `` for ease of
89
+ development. You can edit the code from the host (i.e. outside the container)
90
+ and then reinstall CMS (``python3 setup.py install ``) directly from inside the
91
+ container, without having to rebuild the image every time.
41
92
42
- Another option is to add the ``--build `` flag to the ``run `` command, to perform
43
- a new build before running the tests:
93
+ Upon running ``cms-dev.sh `` for the first time, the database will initially be
94
+ empty. You need to initialize it (notice that the following commands are
95
+ indicated with a ``>>> `` prompt because they are meant to be executed **inside **
96
+ the container, from the prompt that you get to after running ``cms-dev.sh ``)
97
+ like so:
44
98
45
99
.. sourcecode :: bash
46
100
47
- docker compose -p cms -f docker-compose.test.yml run --build --rm testcms
101
+ >>> createdb - h devdb - U postgres cmsdb
102
+ >>> cmsInitDB
48
103
49
- This command will create (assuming you used ``-p cms ``) a ``cms-testdb-1 ``
50
- container for the database which **will not ** be automatically deleted, and a
51
- ``cms-testcms-run-<random_string> `` container for CMS which will be
52
- automatically deleted (because of the ``--rm `` flag) upon exiting.
104
+ Then you probably want to download a test contest and import it, for example
105
+ like this:
53
106
54
- To delete the ``cms-testdb-1 `` container after testing you can run:
107
+ .. sourcecode :: bash
108
+
109
+ >>> git clone https:// github.com/ cms- dev/ con_test.git
110
+ >>> cd con_test
111
+ >>> cmsImportUser -- all
112
+ >>> cmsImportContest - i .
113
+
114
+ If this succeeds, you can then run one of the servers, for example the
115
+ ContestWebServer, like so:
55
116
56
117
.. sourcecode :: bash
57
118
58
- docker rm -f cms-testdb-1
119
+ >>> cmsContestWebServer
120
+
121
+ When it prompts you to choose a contest ID, you can simply hit Enter.
122
+
123
+ When the server is finally running, you can check (from the host machine) that
124
+ the server is reachable at http://localhost:8888/
125
+
126
+ You can also verify that upon exiting the container's bash shell and reentering
127
+ it (by running ``cms-dev.sh `` again) you won't need to re-import the contest, as
128
+ the database is persisted on disk on the host machine. Even manually destroying
129
+ and recreating the database container will retain the same data. If for some
130
+ reason you need to reset the database, we recommend using the ``dropdb -h devdb
131
+ -U postgres cmsdb `` command inside the container. To remove any trace of the
132
+ database data, you can delete the ``.dev/postgres-data `` folder within the git
133
+ repository.
0 commit comments