Skip to content

Commit a2d6482

Browse files
committed
use custom HTTP public port to use rootless containers by default
This commit introduces two new global constants MY_PUBLIC_URL and IMG_PUBLIC_URL which should be used now to build URLs. For alpha and production Ruby environments, they are fixed with their real values directly in the `config/environments/*.rb` files. For the development Ruby environment, they are defined by default to `http://dlfp.lo` and `http://image.dlfp.lo`. You can customize either by updating the `config/environments/development.rb` file or by setting the *process* environment variables `DOMAIN`, `DOMAIN_HTTP_PORT`, `IMAGE_DOMAIN` and `IMAGE_DOMAIN_HTTP_PORT`. For containers, you can set these variables in the `deployment/default.env` file.
1 parent a0085c9 commit a2d6482

25 files changed

+116
-69
lines changed

Container.md

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,53 @@ To simplify set up of a development environment, LinuxFr.org can be
55
run with a container engine like Docker or Podman with the [`compose.yml`](./compose.yaml)
66
file which describes how to build all needed services.
77

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/)).
8+
By default, the LinuxFr.org services will be provided under the domain names
9+
`dlfp.lo` and `image.dlfp.lo`. So you'll need to add the
10+
following line into the `/etc/hosts` file of your machine:
11+
12+
```
13+
127.0.0.1 dlfp.lo image.dlfp.lo
14+
```
15+
16+
Then, if you use the Docker engine, you can use the `docker compose up`
17+
command to start the system (you need to install the
18+
[Docker compose plugin](https://docs.docker.com/compose/) first).
1019

1120
> Note: with the Docker engine, you need to enable the Docker BuildKit builder.
1221
> Either you have a Docker version which uses it by default, or you set the
1322
> environment variable `export DOCKER_BUILDKIT=1`.
1423
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
24+
If you use the Podman engine, you can either use the same Docker compose plugin
25+
or the [podman-compose](https://github.com/containers/podman-compose/)
26+
tool. The podman cli itself provides a wrapper of one of these two tools
27+
through the
1828
[`podman compose` command](https://docs.podman.io/en/latest/markdown/podman-compose.1.html).
1929
Thus you need to use the `podman compose up` command to start the system.
2030

21-
At this point, the documentation will give you `docker compose` commands, but you should be able
22-
to use `podman compose` without any issue.
31+
At this point, this documentation will give you `docker compose` commands,
32+
but you should be able to use `podman compose` without any issue.
2333

24-
To init the SQL database schema, you need to wait up to the `database`
25-
container to be ready to listen MySQL connections.
34+
To setup the SQL database schema, you need to wait until the `database`
35+
container becomes ready to listen MySQL connections.
2636

2737
For example, you should see in the logs:
2838

29-
> database_1 | 2020-09-21 16:03:12 139820938893312 [Note] mysqld: ready for connections.
39+
> database_1 | 2020-09-21 16:03:12 139820938893312 [Note] *mysqld: ready for connections.*
3040
>
3141
> database_1 | Version: '10.1.46-MariaDB-1\~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
3242
33-
Or you can check the `database` container status to be "healthy".
43+
Or you can check the `database` container status to be *healthy* with the
44+
`docker compose ps` command.
3445

3546
Then, open a second terminal and run:
3647

3748
```
3849
docker compose exec linuxfr.org bin/rails db:setup
3950
```
4051

41-
Finally, the environment is ready and you can open [http://dlfp.lo](http://dlfp.lo)
52+
Finally, the environment is ready and you can open [http://dlfp.lo:9000](http://dlfp.lo:9000)
4253
in your favorite browser.
4354

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

@@ -68,16 +61,14 @@ If you want, you can change the domain names used by the LinuxFr.org
6861
web application. To do this, you can setup `DOMAIN` and `IMAGE_DOMAIN`
6962
variables in the `deployment/default.env` file.
7063

71-
You can also configure your own Redis service and your own MySQL
72-
service.
73-
74-
If you want to change the application port and/or other configurations, you can
75-
[override](https://docs.docker.com/compose/extends/)
76-
the docker compose configuration (in particular the `nginx` service for
77-
the port).
64+
Within the same file, you can update the HTTP listening ports by updating the
65+
`DOMAIN_HTTP_PORT` and `IMAGE_DOMAIN_HTTP_PORT` variables (both are set to
66+
`9000` by default). If you modify them, don't forget to add the new values as
67+
published ports for the `nginx` service in the `compose.yaml` file (they have
68+
to target the `8080` container port).
7869

79-
Notice, that if LinuxFr.org doesn't run on port 80, the image cache
80-
service won't work well and so you won't be able to see images in the news.
70+
You can also configure your own Redis service and your own MySQL
71+
service by updating environment variables in the same file.
8172

8273
Test modifications
8374
==================

INSTALL.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,20 @@ Additionally, you run the boards within another terminal:
131131

132132
This extra step isn't really needed to be able to use LinuxFr.org.
133133

134-
In the `config/environments/development.rb` file, there are two domains set
135-
inside variables `MY_DOMAIN` and `IMG_DOMAIN`.
136-
By default both domains are `dlfp.lo`.
134+
In the `config/environments/development.rb` file, there are these variables:
137135

138-
You'll find this domain inside some documents like emails to confirm user
136+
1. `MY_DOMAIN` and `IMG_DOMAIN` which define the domain name for the LinuxFr
137+
service and the image caching service.
138+
By default both domain names are `dlfp.lo`.
139+
140+
2. `MY_PUBLIC_URL` and `IMG_PUBLIC_PORT` which define the public HTTP port for
141+
both services.
142+
By default both ports are `80`.
143+
144+
These two set of variables are used to build the public url of the two
145+
services. By default both public urls are `http://dlfp.lo`.
146+
147+
You'll find this public url inside some documents like emails to confirm user
139148
subscription. To simplify your usage of LinuxFr.org, you should consider
140149
install a website locally using this domain name.
141150

app/controllers/admin/stylesheets_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def show
66

77
def create
88
Stylesheet.temporary(current_account, params[:url]) do
9-
redirect_to "/" + Stylesheet.capture("http://#{MY_DOMAIN}/", cookies)
9+
redirect_to "/" + Stylesheet.capture("#{MY_PUBLIC_URL}/", cookies)
1010
end
1111
end
1212

app/helpers/atom_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def atom_comments_link(content, url)
55
str = <<-EOS
66
<p>
77
<strong>Commentaires :</strong>
8-
<a href=\"//#{MY_DOMAIN}/nodes/#{content.node.id}/comments.atom\">voir le flux Atom</a>
8+
<a href=\"#{MY_PUBLIC_URL}/nodes/#{content.node.id}/comments.atom\">voir le flux Atom</a>
99
<a href=\"#{url}#comments\">ouvrir dans le navigateur</a>
1010
</p>
1111
EOS

app/models/diary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def convert
7575
@news.save!
7676
$redis.set "convert/#{@news.id}", self.id
7777
@news.node.update_column(:cc_licensed, node.cc_licensed)
78-
@news.links.create title: "Journal à l’origine de la dépêche", url: "https://#{MY_DOMAIN}/users/#{owner.to_param}/journaux/#{to_param}", lang: "fr"
78+
@news.links.create title: "Journal à l’origine de la dépêche", url: "#{MY_PUBLIC_DOMAIN}/users/#{owner.to_param}/journaux/#{to_param}", lang: "fr"
7979
@news
8080
end
8181
end

app/models/image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def src(type="img")
6767
return link if internal_link?
6868
return E403 if blacklisted?
6969
register_in_redis
70-
"//#{IMG_DOMAIN}/#{type}/#{encoded_link}/#{filename}"
70+
"#{IMG_PUBLIC_URL}/#{type}/#{encoded_link}/#{filename}"
7171
end
7272

7373
def src_attr

app/models/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def set_taglist(list, user_id)
170170
if tag.new_record?
171171
tag.save!
172172
user = User.find(user_id)
173-
Board.amr_notification("L’étiquette #{tagname} https://#{MY_DOMAIN}/tags/#{tagname}/public vient d’être créée par #{user.name} https://#{MY_DOMAIN}/users/#{user.cached_slug}")
173+
Board.amr_notification("L’étiquette #{tagname} #{MY_PUBLIC_URL}/tags/#{tagname}/public vient d’être créée par #{user.name} #{MY_PUBLIC_URL}/users/#{user.cached_slug}")
174174
end
175175
taggings.create(tag_id: tag.id, user_id: user_id)
176176
end

app/uploaders/avatar_uploader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class AvatarUploader < CarrierWave::Uploader::Base
44

55
AVATAR_SIZE = 64
6-
DEFAULT_AVATAR_URL = "//#{MY_DOMAIN}/images/default-avatar.svg"
6+
DEFAULT_AVATAR_URL = "#{MY_PUBLIC_URL}/images/default-avatar.svg"
77

88
include CarrierWave::MiniMagick
99
process resize_and_pad: [AVATAR_SIZE, AVATAR_SIZE]
@@ -13,7 +13,7 @@ def base_dir
1313
end
1414

1515
def url
16-
super.sub(base_dir.to_s, "//#{IMG_DOMAIN}")
16+
super.sub(base_dir.to_s, "#{IMG_PUBLIC_URL}")
1717
end
1818

1919
def store_dir

app/uploaders/stylesheet_uploader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def base_dir
66
end
77

88
def url
9-
super.sub(base_dir.to_s, "//#{IMG_DOMAIN}")
9+
super.sub(base_dir.to_s, "#{IMG_PUBLIC_URL}")
1010
end
1111

1212
def store_dir

app/views/bookmarks/_bookmark.atom.builder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ feed.entry(bookmark, :url => url) do |entry|
88
bookmark.node.popular_tags.each do |tag|
99
entry.category(:term => tag.name)
1010
end
11-
entry.wfw :commentRss, "https://#{MY_DOMAIN}/nodes/#{bookmark.node.id}/comments.atom"
11+
entry.wfw :commentRss, "#{MY_PUBLIC_URL}/nodes/#{bookmark.node.id}/comments.atom"
1212
end

0 commit comments

Comments
 (0)