Skip to content

Commit 41071ec

Browse files
committed
Fix up Docker
Installs chromium into Docker image to run js tests in the container Removes deprecated version key from docker-compose.yml Reworks the docker commands Updates the Docker installation instructions in the README
1 parent a30a07c commit 41071ec

File tree

16 files changed

+69
-97
lines changed

16 files changed

+69
-97
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ FROM ruby:3.2.2
33
# Default node version on apt is old. This makes sure a recent version is installed
44
# This step also runs apt-get update
55
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
6-
RUN apt-get install -y --force-yes build-essential libpq-dev nodejs
6+
RUN apt-get update
7+
RUN apt-get install -y --force-yes build-essential libpq-dev nodejs chromium chromium-driver
78

89
WORKDIR /planner
910

10-
COPY Gemfile Gemfile.lock ./
11-
RUN bundle install --jobs 4
12-
1311
COPY . ./
12+
13+
RUN bundle install --jobs 4

README.md

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,39 @@ from a command prompt in your project folder:
6161

6262
**Note:** If when starting the application with Docker you get the error `UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte` this may be because you created the `.env`-file using PowerShell. This can be solved by deleting that file and creating a new one using a bash shell (for example Git Bash).
6363

64-
### 3. Install and set up the environment
64+
### 3. Install and set up the environment using docker
6565

66-
We recommend using Docker to install and run the application. However alternatively if you prefer, [you can install directly to your system environment instead](https://github.com/codebar/planner/blob/master/native-installation-instructions.md).
66+
We recommend using Docker to install and run the application. However alternatively if you prefer, [you can install directly to your system environment instead](./native-installation-instructions.md).
6767

68-
#### Install using Docker
68+
Before you start, you will need to have Docker installed and running. You can [download it from the Docker website](https://docker.com/). Once downloaded, install and start the Docker application.
6969

70-
Before you start, you will need to have Docker installed and running. You can [download it from the Docker website](https://docker.com/).
70+
Run `bin/dup` to build and create the docker container. This will also set up the Rails application within the container and start the container. You will only have to run this command once. After initial setup, use `bin/dstart` to start an existing container - using `bin/dup` will recreate an existing container and reset the database.
7171

72-
The current Dockerfile and docker-compose were closely copied from [the Docker guide](https://docs.docker.com/compose/rails/).
72+
### 4. Start the app
7373

74-
1. Run `bin/dbuild` to build and setup the docker environment.
75-
2. Run `bin/drake` to run all the tests and make sure everything works.
74+
Run `bin/dserver` to start the Rails server.
7675

77-
**Note:** If you are using Windows, you can run `bin/dbuild` using Git Bash.
76+
*If you have previously stopped the container, you will have to first start the container using `bin/dstart`.
7877

79-
### 4. Run the tests
78+
This should run a process which starts a server in a Docker container on your computer. This process won't finish - you'll know the server is ready when it stops doing anything and displays a message like this:
79+
```
80+
Rails 4.2.11 application starting in development on http://localhost:3000
81+
```
8082

81-
Run `bin/drake` to run all the tests and make sure everything works.
82-
You can also use `bin/drails` and `bin/dspec` to run specific rails and rspec commands via docker.
83+
(Optional) Note that to be able to use the page as an admin, you must first give yourself admin privileges. Make sure you have started your app and signed up as an user on your locally running app. Then run the script `bin/dadmin <your email>`.
8384

84-
#### Running single tests/test files
85+
**You can now view the app at http://localhost:3000**
8586

86-
If you just want to run a single test file you can pass the path to the file, either using `rspec` or via the `SPEC` variable with `rake`:
87-
```bash
88-
bundle exec rspec <path to test>
89-
bundle exec rake SPEC=<path to test>
90-
```
87+
You can stop the server when you're finished by typing `Ctrl + C`.
9188

92-
This can also be used with specific line number (running only that one test), for example:
93-
```bash
94-
bundle exec rspec spec/features/admin/manage_workshop_attendances_spec.rb:42
95-
bundle exec rake SPEC=spec/features/admin/manage_workshop_attendances_spec.rb:42
96-
```
89+
### 5. Run the tests
90+
91+
Run `bin/drspec` to run all the tests.
9792

98-
These also work with the corresponding `bin/dspec` and `bin/drake` commands.
93+
This command passes any additional arguments into `rspec` in the docker container, so you can run individual tests with `bin/drspec PATH_TO_TEST` and run a single test case in a file with `bin/drspec PATH_TO_TEST:LINE_NUMBER`
9994

10095
#### Running JavaScript enabled feature tests with a visible browser
96+
10197
There are a small number of feature tests marked with `js: true` which use
10298
headless Chrome. These can be hard to work with without being able to see what is
10399
actually happening in the browser. To spin up a visible browser, pass
@@ -109,20 +105,18 @@ CHROME_HEADLESS=false bundle exec rspec
109105

110106
Running JavaScript enabled tests with a visible browser currently doesn't work with Docker.
111107

112-
### 5. Start the app
113-
114-
Run `bin/dstart` to start the app.
115-
116-
This should run a process which starts a server in a Docker container on your computer. This process won't finish - you'll know the server is ready when it stops doing anything and displays a message like this:
117-
```
118-
Rails 4.2.11 application starting in development on http://localhost:3000
119-
```
120-
121-
(Optional) Note that to be able to use the page as an admin, you must first give yourself admin privileges. Make sure you have started your app and signed up as an user on your locally running app. Then run a script `bin/dadmin <your email>`.
122-
123-
**You can now view the app at http://localhost:3000**
124-
125-
You can stop the server when you're finished by typing `Ctrl + C`.
108+
### Available Docker commands
109+
110+
- `bin/dup`: `docker-compose up --build -d --wait && rake db:drop db:create db:migrate db:seed db:test:prepare`. Rebuilds and boots up a new container, and then initialize the Rails database.
111+
- `bin/dstart`: `docker-compose start`. Starts the existing container.
112+
- `bin/dserver`: `docker-compose exec web make serve`. Runs the Rails server. Use this instead of `bin/drails server` to make it bind to the correct IP addresses to allow the server to be viewable outside the container.
113+
- `drails`: `docker-compose exec web rails $@`. Runs rails within the container.
114+
- `drspec`: `docker-compose exec web rspec $@`. Runs rspec within the container.
115+
- `drake`: `docker-compose exec web rake $@`. Runs rake inside the container.
116+
- `dexec`: `docker-compose exec web bash`. Runs a bash shell inside the container.
117+
- `dadmin`: Gives the the last user (or the one with a given email) the admin role
118+
- `bin/dstop`: `docker-compose stop`. Stops container but does not remove it
119+
- `bin/ddown`: `docker-compose down`. Stops and destroy a container.
126120

127121
## Front-end framework
128122

bin/dadmin

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
docker-compose up -d web
5-
64
if [ $# -gt 0 ]
75
then
8-
docker-compose exec web rails runner "Member.find_by(email: '$@').add_role(:admin)"
6+
docker compose exec web rails runner "Member.find_by(email: '$@').add_role(:admin)"
97
else
10-
docker-compose exec web rails runner "Member.last.add_role(:admin)"
8+
docker compose exec web rails runner "Member.last.add_role(:admin)"
119
fi

bin/dbuild

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/ddown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
docker compose down

bin/dexec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
set -e
44

5-
docker-compose up -d web
6-
docker-compose exec web bash
5+
docker compose exec web bash

bin/drails

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -e
44

5-
docker-compose run --rm web rails "$@"
5+
docker compose exec web rails $@

bin/drake

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@
22

33
set -e
44

5-
function cleanup {
6-
# capture exit code
7-
code=$?
8-
echo "cleaning up"
9-
10-
# ignore errors
11-
set +e
12-
docker-compose down
13-
14-
exit $code
15-
}
16-
17-
trap cleanup EXIT
18-
19-
docker-compose run --rm web rake $@
5+
docker compose exec web rake $@

bin/drspec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
docker compose exec web rspec $@

bin/drun

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)