Skip to content

Commit 36101b6

Browse files
authored
Merge pull request #382 from Trim/ruby3-dockerfile
Ruby3 dockerfile
2 parents 0f64161 + a981437 commit 36101b6

File tree

13 files changed

+190
-128
lines changed

13 files changed

+190
-128
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
/uploads
2424
/vendor/ruby
2525
/vendor/bundle
26+
/coverage

Docker.md renamed to Container.md

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
LinuxFr on Docker
2-
-----------------
1+
LinuxFr with Containers
2+
-----------------------
33

44
To simplify set up of a developement environment, LinuxFr.org can be
5-
run on Docker with `docker-compose up`.
5+
run with a container engine like Docker or Podman with the [`compose.yml`](./compose.yaml)
6+
file which describe how to build all needed services.
7+
8+
If you use the Docker engine, you can use the `docker compose up` command to start the system (you
9+
need to install the [Docker compose plugin](https://docs.docker.com/compose/)).
10+
11+
> Note: with the Docker engine, you need to enable the Docker BuildKit builder.
12+
> Either you have a Docker version which uses it by default, or you set the
13+
> environment variable `export DOCKER_BUILDKIT=1`.
14+
15+
If you use Podman, you can either use the same Docker compose plugin or the
16+
[podman-compose](https://github.com/containers/podman-compose/)
17+
utility. The podman cli itself provide a wrapper of one of these two tools through the
18+
[`podman compose` command](https://docs.podman.io/en/latest/markdown/podman-compose.1.html).
19+
20+
At this point, the documentation will give you `docker compose` commands, but you should be able
21+
to use `podman compose` without any issue.
622

723
To init the SQL database schema, you need to wait upto the `database`
824
container to be ready to listen MySQL connections.
@@ -16,18 +32,29 @@ For example, you should see in the logs:
1632
Then, open a second terminal and run:
1733

1834
```
19-
docker-compose run linuxfr.org bin/rails db:setup
35+
docker compose run linuxfr.org bin/rails db:setup
2036
```
2137

2238
Finally, the environment is ready and you can open [http://dlfp.lo](http://dlfp.lo)
2339
in your favorite browser.
2440

25-
Note: to be able to access this URL, you'll need to add the following line
26-
into the `/etc/hosts` file of your machine:
41+
Notes:
42+
43+
1. to be able to access this URL, you'll need to add the following line
44+
into the `/etc/hosts` file of your machine:
45+
46+
```
47+
127.0.0.1 dlfp.lo image.dlfp.lo
48+
```
49+
50+
2. for [rootless containers](https://rootlesscontaine.rs/), you'll need
51+
to allow standard users to listen on ports less than 1024
52+
(this is needed because linuxfr use port 80 and 443):
53+
54+
```sh
55+
sudo sysctl net.ipv4.ip_unprivileged_port_start=80
56+
```
2757

28-
```
29-
127.0.0.1 dlfp.lo image.dlfp.lo
30-
```
3158

3259
Personalize configuration
3360
=========================
@@ -43,7 +70,7 @@ service.
4370

4471
If you want to change the application port and/or other configurations, you can
4572
[override](https://docs.docker.com/compose/extends/)
46-
the docker-compose configuration (in particular the `nginx` service for
73+
the docker compose configuration (in particular the `nginx` service for
4774
the port).
4875

4976
Notice, that if LinuxFr.org doesn't run on port 80, the image cache
@@ -52,8 +79,8 @@ service won't work well and so you won't be able to see images in the news.
5279
Test modifications
5380
==================
5481

55-
The docker-compose is currently configured to share `./app`, `./db` and
56-
`./public` directories with the docker container.
82+
The compose file currently shares `./app`, `./db` and
83+
`./public` directories with the container.
5784

5885
So you can update files with your prefered IDE on your machine. Rails
5986
will directly detect changes and apply them on next page reload.
@@ -62,7 +89,7 @@ Furthermore, if you need to access the Rails console, you need a second
6289
terminal and run:
6390

6491
```
65-
docker-compose run linuxfr.org bin/rails console
92+
docker compose run linuxfr.org bin/rails console
6693
```
6794

6895
Note: currently, we didn't configure rails to show directly the
@@ -79,10 +106,10 @@ To get help about writing tests, see the
79106
[Ruby on Rails documentation](https://guides.rubyonrails.org/testing.html#the-rails-test-runner)
80107
.
81108

82-
To run tests with Docker environment, you need to use this command:
109+
To run tests with containers, you need to use this command:
83110

84111
```
85-
docker-compose run linuxfr.org bin/rails test -v
112+
docker compose run linuxfr.org bin/rails test -v
86113
```
87114

88115
Inspect database schema
@@ -92,7 +119,7 @@ In case you need to inspect the database, you need a second terminal
92119
and run:
93120

94121
```
95-
docker-compose run database mysql -hdatabase -ulinuxfr_rails -p linuxfr_rails
122+
docker compose run database mysql -hdatabase -ulinuxfr_rails -p linuxfr_rails
96123
```
97124

98125
By default, the requested password is the same as the username.
@@ -104,20 +131,20 @@ In case you need to apply new database migrations, you need a second
104131
terminal and run:
105132

106133
```
107-
docker-compose run linuxfr.org bin/rails db:migrate
134+
docker compose run linuxfr.org bin/rails db:migrate
108135
```
109136

110137
If you had issue and want to reset all data in your database system,
111138
use:
112139

113140
```
114-
docker-compose run linuxfr.org bin/rails db:reset
141+
docker compose run linuxfr.org bin/rails db:reset
115142
```
116143

117-
Services provided by the docker-compose
144+
Services provided by the compose file
118145
=======================================
119146

120-
Currently, these services are directly enabled by docker-compose:
147+
Currently, these services are directly enabled by compose:
121148

122149
1. The [LinuxFr.org](https://github.com/linuxfrorg/linuxfr.org)
123150
ruby on rails application itself
@@ -134,7 +161,7 @@ For now, these services aren't available:
134161
because it requires to run
135162
LinuxFr.org with a TLS certificate. When the service will accept to
136163
fetch articles with simple `http://`, we'll be able to provide it
137-
directly with docker-compose.
164+
directly with docker compose.
138165
2. The [svgtex service](https://github.com/linuxfrorg/svgtex), because LinuxFr
139166
has hard-coded the `localhost`
140167
hostname in it's [HTML Pipeline tool](https://github.com/linuxfrorg/html-pipeline-linuxfr/blob/linuxfr/lib/html/pipeline/linuxfr.rb#L8)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Install
1212

1313
See [INSTALL.md](INSTALL.md) to set up LinuxFr.org on a Debian environment.
1414

15-
Alternatively, you can read [Docker.md](Docker.md) to setup easily
16-
LinuxFr.org development environment with the Docker engine and
17-
[docker-compose](https://docs.docker.com/compose/).
15+
Alternatively, you can read [Container.md](Container.md) to setup easily
16+
LinuxFr.org development environment with a container engine like Docker or
17+
Podman and use the [container composer](https://docs.docker.com/compose/).
1818

1919
See also
2020
--------

docker-compose.yaml renamed to compose.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ services:
44
linuxfr.org:
55
build:
66
context: .
7-
dockerfile: deployment/linuxfr.org/Dockerfile
7+
dockerfile: deployment/linuxfr.org/Containerfile
88
env_file:
99
- deployment/default.env
1010
volumes:
1111
# Share host directories so, the developer can edit them
1212
# and see the result without need to restart the container
13-
- ./app:/linuxfr.org/app
14-
- ./db:/linuxfr.org/db
15-
- ./public:/linuxfr.org/public
16-
- ./test:/linuxfr.org/test
13+
- ./app:/linuxfr.org/app:Z
14+
- ./db:/linuxfr.org/db:Z
15+
- ./public:/linuxfr.org/public:Z
16+
- ./test:/linuxfr.org/test:Z
1717
# uploads are shared with the nginx service
1818
- data-uploads:/linuxfr.org/uploads
1919
tmpfs:
@@ -41,12 +41,12 @@ services:
4141
- cache-img:/linuxfr-img/cache
4242

4343
nginx:
44-
image: nginx:stable
44+
image: docker.io/nginx:stable
4545
env_file:
4646
- deployment/default.env
4747
volumes:
48-
- ./deployment/nginx/templates:/etc/nginx/templates
49-
- ./public/fonts:/var/linuxfr/fonts
48+
- ./deployment/nginx/templates:/etc/nginx/templates:Z
49+
- ./public/fonts:/var/linuxfr/fonts:Z
5050
- data-uploads:/var/linuxfr/uploads
5151
ports:
5252
- "80:80"
@@ -66,7 +66,7 @@ services:
6666
- data-database:/var/lib/mysql
6767

6868
redis:
69-
image: redis:5
69+
image: docker.io/redis:5
7070
volumes:
7171
- data-redis:/data
7272

db/schema.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
t.index ["user_id"], name: "index_nodes_on_user_id"
206206
end
207207

208-
create_table "oauth_access_grants", id: :integer, charset: "utf8mb3", force: :cascade do |t|
208+
create_table "oauth_access_grants", id: :integer, charset: "utf8", force: :cascade do |t|
209209
t.integer "resource_owner_id", null: false
210210
t.integer "application_id", null: false
211211
t.string "token", null: false
@@ -219,7 +219,7 @@
219219
t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
220220
end
221221

222-
create_table "oauth_access_tokens", id: :integer, charset: "utf8mb3", force: :cascade do |t|
222+
create_table "oauth_access_tokens", id: :integer, charset: "utf8", force: :cascade do |t|
223223
t.integer "resource_owner_id"
224224
t.integer "application_id", null: false
225225
t.string "token", null: false
@@ -234,7 +234,7 @@
234234
t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true
235235
end
236236

237-
create_table "oauth_applications", id: :integer, charset: "utf8mb3", force: :cascade do |t|
237+
create_table "oauth_applications", id: :integer, charset: "utf8", force: :cascade do |t|
238238
t.string "name", null: false
239239
t.string "uid", null: false
240240
t.string "secret", null: false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM mariadb:10.1
1+
FROM docker.io/mariadb:10.1
22

33
COPY ./docker-entrypoint-initdb.d /docker-entrypoint-initdb.d
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM docker.io/ruby:3-slim-bookworm
2+
3+
LABEL org.opencontainers.image.title="LinuxFr.org boards"
4+
LABEL org.opencontainers.image.description="Push notifications for chat rooms of LinuxFr"
5+
LABEL org.opencontainers.image.source="https://github.com/linuxfrorg/board-sse-linuxfr.org"
6+
LABEL org.opencontainers.image.url="https://github.com/linuxfrorg/linuxfr.org/blob/master/Container.md"
7+
LABEL org.opencontainers.image.licenses="AGPL-3.0-only"
8+
LABEL org.opencontainers.image.version="ruby3-bookworm"
9+
LABEL org.opencontainers.image.authors="Adrien Dorsaz <[email protected]>"
10+
11+
ARG UID=1200
12+
13+
RUN apt-get update \
14+
# Install dependencies \
15+
&& apt-get install -y --no-install-recommends \
16+
build-essential git ruby ruby-dev \
17+
&& apt-get clean
18+
19+
USER ${UID}
20+
WORKDIR /linuxfr-board
21+
ENV HOME=/linuxfr-board
22+
23+
# Install board-linuxfr
24+
# RUN gem install board-linuxfr -v '~> 0.1.4'
25+
26+
# Temporary build board-linuxfr from sources
27+
RUN git clone https://github.com/linuxfrorg/board-sse-linuxfr.org.git --branch ruby3 \
28+
&& cd board-sse-linuxfr.org \
29+
&& gem build board-linuxfr.gemspec \
30+
&& gem install ./board-linuxfr-*.gem
31+
32+
# Clean development dependencies
33+
USER 0
34+
RUN apt purge --autoremove -y build-essential git ruby-dev
35+
36+
USER ${UID}
37+
EXPOSE 9000
38+
39+
CMD ["board-linuxfr"]

deployment/linuxfr-board/Dockerfile

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM docker.io/debian:bullseye-slim as build
2+
3+
LABEL org.opencontainers.image.title="LinuxFr.org image caching service"
4+
LABEL org.opencontainers.image.description="Store external images into a cache to not flood external website"
5+
LABEL org.opencontainers.image.source="https://github.com/linuxfrorg/img-LinuxFr.org"
6+
LABEL org.opencontainers.image.url="https://github.com/linuxfrorg/linuxfr.org/blob/master/Container.md"
7+
LABEL org.opencontainers.image.licenses="AGPL-3.0-only"
8+
LABEL org.opencontainers.image.version="rails7-bullseye"
9+
LABEL org.opencontainers.image.authors="Adrien Dorsaz <[email protected]>"
10+
11+
ARG UID=1200
12+
13+
RUN apt-get update \
14+
&& apt-get install -y --no-install-recommends \
15+
golang git ca-certificates \
16+
&& apt-get clean
17+
18+
USER ${UID}
19+
ENV GOPATH=/linuxfr-img
20+
ENV HOME=/linuxfr-img
21+
WORKDIR /linuxfr-img
22+
23+
# Build linuxfr-img
24+
RUN go get -u github.com/linuxfrorg/img-LinuxFr.org
25+
26+
FROM docker.io/debian:bullseye-slim as deploy
27+
28+
USER ${UID}
29+
WORKDIR /linuxfr-img
30+
31+
COPY --from=build --chown=${UID}:0 --chmod=770 /linuxfr-img/bin/img-LinuxFr.org .
32+
33+
EXPOSE 8000
34+
35+
CMD ["sh", "-c", "exec ./img-LinuxFr.org -a 0.0.0.0:8000 -r \"${REDIS_URL##redis://}\""]

deployment/linuxfr-img/Dockerfile

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

0 commit comments

Comments
 (0)