8000 Add `Docker` to build and run all `mruby` tests · mruby/mruby@00d43ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 00d43ad

Browse files
committed
Add Docker to build and run all mruby tests
Run `pre-commit` and generate `YARD` docs with Docker Update CONTRIBUTING
1 parent 8d014e9 commit 00d43ad

File tree

9 files changed

+161
-0
lines changed

9 files changed

+161
-0
lines changed

.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
.idea
3+
.vscode
4+
*.bak
5+
*.iml
6+
*.ipr
7+
*.swp
8+
*.tmp
9+
10+
/.yardoc
11+
/bin
12+
/build
13+
/doc/api
14+
/doc/capi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ compile_flags.txt
3232
cscope.files
3333
cscope.out
3434
tags
35+
!Gemfile.lock

CONTRIBUTING.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,69 @@ We use [GitHub Actions](.github/workflows/lint.yml) to run `pre-commit` on every
5454
- [pre-commit autoupdate](https://pre-commit.com/#pre-commit-autoupdate)
5555
- [Temporarily disabling hooks](https://pre-commit.com/#temporarily-disabling-hooks)
5656

57+
## Docker
58+
59+
We have both a `Dockerfile` and `docker-compose.yml` files in the repository root.
60+
You can run these with the command line or use
61+
[Docker Desktop](https://www.docker.com/products/docker-desktop/).
62+
63+
The Docker image is running Debian bullseye with Ruby and Python installed.
64+
You can build the Docker image with:
65+
66+
`$ docker-compose build test`
67+
68+
So far we just have one service: `test`. Running the default `docker-compose`
69+
command will create the Docker image, spin up a container and then build and
70+
run all mruby tests.
71+
72+
The default `docker-compose` command is:
73+
74+
`$ docker-compose -p mruby run test`
75+
76+
You can also use Make or Rake to run the default `docker-compose`
77+
command from above:
78+
79+
- `make composetest`
80+
- `rake composetest`
81+
82+
List your Docker images with:
83+
84+
```console
85+
$ docker images
86+
REPOSITORY TAG IMAGE ID CREATED SIZE
87+
mruby-test latest ec60f9536948 29 seconds ago 1.29GB
88+
```
89+
90+
You can also run any custom `docker-compose` command which will override
91+
the default. For example to run `pre-commit run --all-files` type:
92+
93+
`$ docker-compose -p mruby run test pre-commit run --all-files`
94+
95+
For convenience, you can also run `pre-commit` with:
96+
97+
- `make composecheck`
98+
- `rake composecheck`
99+
100+
The bonus of running `pre-commit` with `docker-compose` is that you won't need
101+
to install `pre-commit` and the hooks on your local machine. And that also
102+
means you won't need to install `brew`, `conda` or `pip`.
103+
104+
Note limitation: currently running `pre-commit` with `docker-compose` we
105+
skip the `check-executables-have-shebangs` hook.
106+
107+
Two more examples of custom `docker-compose` commands are:
108+
109+
- `$ docker-compose -p mruby run test ls`
110+
- `$ docker-compose -p mruby run test rake doc:api`
111+
112+
If you want to test using a different `docker-compose` YAML config file you
113+
can use the `-f` flag:
114+
115+
`$ docker-compose -p mruby -f docker-compose.test.yml run test`
116+
117+
- <https://docs.docker.com/compose/>
118+
- <https://docs.docker.com/engine/reference/commandline/cli/>
119+
57120
## Spell Checking
58121

59122
We are using `pre-commit` to run [codespell](https://github.com/codespell-project/codespell)

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ruby:3.2.2-bullseye
2+
3+
RUN apt-get update && apt-get install --no-install-recommends -y python3-pip shellcheck \
4+
&& apt-get clean \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
WORKDIR /app
8+
9+
COPY Gemfile .
10+
11+
COPY Gemfile.lock .
12+
13+
COPY .pre-commit-config.yaml .
14+
15+
RUN bundle install && pip3 install pre-commit && git init . && pre-commit install-hooks
16+
17+
COPY . .

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'rake'
6+
gem 'yard'
7+
gem 'yard-coderay'
8+
gem 'yard-mruby'

Gemfile.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
coderay (1.1.3)
5+
rake (13.0.6)
6+
webrick (1.7.0)
7+
yard (0.9.28)
8+
webrick (~> 1.7.0)
9+
yard-coderay (0.1.0)
10+
coderay
11+
yard
12+
yard-mruby (0.3.0)
13+
yard (~> 0.9.0)
14+
15+
PLATFORMS
16+
ruby
17+
x86_64-darwin-21
18+
x86_64-linux
19+
20+
DEPENDENCIES
21+
rake
22+
yard
23+
yard-coderay
24+
yard-mruby
25+
26+
BUNDLED WITH
27+
2.4.10

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ checkinstall :
2525
checkupdate :
2626
pre-commit autoupdate
2727
.PHONY : checkupdate
28+
29+
composecheck :
30+
docker-compose -p mruby run test pre-commit run --all-files
31+
.PHONY : composecheck
32+
33+
composetest :
34+
docker-compose -p mruby run test
35+
.PHONY : composetest

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ desc "check the pre-commit hooks for updates"
8282
task :checkupdate do
8383
sh "pre-commit autoupdate"
8484
end
85+
86+
desc "run all pre-commit hooks against all files with docker-compose"
87+
task :composecheck do
88+
sh "docker-compose -p mruby run test pre-commit run --all-files"
89+
end
90+
91+
desc "build and run all mruby tests with docker-compose"
92+
task :composetest do
93+
sh "docker-compose -p mruby run test"
94+
end

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3'
2+
services:
3+
test:
4+
build:
5+
context: .
6+
command: sh -c 'rake deep_clean && rake -m test:build && rake test:run'
7+
environment:
8+
- MRUBY_CONFIG=ci/gcc-clang
9+
- CC=gcc
10+
- CXX=g++
11+
- LD=gcc
12+
- SKIP=check-executables-have-shebangs
13+
working_dir: /app

0 commit comments

Comments
 (0)
0