Skip to content

Commit d9962b5

Browse files
committed
linuxfr.org container uses Debian Bullseye and backports container definition from rails7
The linuxfr.org container wasn't anymore buildable due to `npm ci` which were stuck. So, even if the prod still use Debian Stretch, we had to upgrade the development environment to Debian Bullseye. Took the opportunity to backport container definition improvements from rails7. Especially, containers are run without root user and there are healthchecks which can help to better see the state of the containers.
1 parent 82d265e commit d9962b5

6 files changed

Lines changed: 156 additions & 72 deletions

File tree

Docker.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ For example, you should see in the logs:
1313
>
1414
> database_1 | Version: '10.1.46-MariaDB-1\~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
1515
16+
Or you can check the `database` container status to be "healthy".
17+
1618
Then, open a second terminal and run:
1719

1820
```
19-
docker-compose run linuxfr.org bin/rails db:setup
21+
docker-compose exec linuxfr.org bin/rails db:setup
2022
```
2123

2224
Finally, the environment is ready and you can open [http://dlfp.lo](http://dlfp.lo)

deployment/database/Dockerfile

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: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
FROM ruby:2-slim-buster
1+
FROM docker.io/ruby:2-slim-buster
22

3-
LABEL maintainer="adrien@adorsaz.ch"
4-
LABEL version="1.0"
5-
LABEL description="Run LinuxFr board service for LinuxFr.org Ruby on Rails website"
3+
LABEL org.opencontainers.image.title="Board for LinuxFr.org"
4+
LABEL org.opencontainers.image.description="Users of the LinuxFr.org website can chat on a space called the board (« la tribune » in french). \
5+
This Ruby daemon notifies the users when something is said with Server-Sent Event / EventSource."
6+
LABEL org.opencontainers.image.source="https://github.com/linuxfrorg/board-sse-linuxfr.org"
7+
LABEL org.opencontainers.image.url="https://github.com/linuxfrorg/board-sse-linuxfr.org"
8+
LABEL org.opencontainers.image.licenses="AGPL-3.0-only"
9+
LABEL org.opencontainers.image.version="1.1"
10+
LABEL org.opencontainers.image.authors="Adrien Dorsaz <adrien@adorsaz.ch>"
611

7-
WORKDIR /linuxfr-board
12+
ARG UID=1200
13+
14+
RUN \
15+
set -eux; \
16+
IFS=$'\n\t'; \
17+
apt-get update; \
18+
# Install dependencies \
19+
# and add curl to be used by the healthcheck defined in compose.yaml \
20+
apt-get install -y --no-install-recommends \
21+
build-essential git ruby ruby-dev \
22+
curl; \
23+
apt-get clean;
824

9-
# Install dependencies
10-
RUN apt-get update \
11-
&& apt-get install -y --no-install-recommends \
12-
build-essential ruby ruby-dev \
13-
&& apt-get clean
25+
USER ${UID}
26+
WORKDIR /linuxfr-board
27+
ENV HOME=/linuxfr-board
1428

1529
# Install board-linuxfr
1630
RUN gem install board-linuxfr -v '~> 0.1.3'
1731

18-
RUN apt purge --autoremove -y build-essential ruby-dev
32+
# Clean development dependencies
33+
USER 0
34+
RUN apt-get purge --autoremove -y build-essential ruby-dev
1935

36+
USER ${UID}
2037
EXPOSE 9000
2138

2239
CMD ["board-linuxfr"]

deployment/linuxfr-img/Dockerfile

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,50 @@
1-
FROM debian:bullseye-slim as build
2-
3-
LABEL maintainer="adrien@adorsaz.ch"
4-
LABEL version="2.0"
5-
LABEL description="Run LinuxFr image caching service for LinuxFr.org"
6-
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="2.1"
9+
LABEL org.opencontainers.image.authors="Adrien Dorsaz <adrien@adorsaz.ch>"
10+
11+
ARG UID=1200
12+
13+
RUN \
14+
set -eux; \
15+
IFS=$'\n\t'; \
16+
apt-get update; \
17+
apt-get install -y --no-install-recommends \
18+
golang git ca-certificates; \
19+
apt-get clean;
20+
21+
USER ${UID}
722
ENV GOPATH=/linuxfr-img
23+
ENV HOME=/linuxfr-img
824
WORKDIR /linuxfr-img
925

1026
# Build linuxfr-img
11-
RUN apt-get update \
12-
&& apt-get install -y --no-install-recommends \
13-
golang git ca-certificates \
14-
&& apt-get clean \
15-
&& go get -u github.com/linuxfrorg/img-LinuxFr.org
27+
RUN go get -u github.com/linuxfrorg/img-LinuxFr.org
28+
29+
FROM docker.io/debian:bullseye-slim as deploy
1630

17-
FROM debian:bullseye-slim as deploy
31+
ARG UID=1200
1832

33+
# Install curl to be used by the healthcheck defined in compose.yaml
34+
RUN \
35+
set -eux; \
36+
IFS=$'\n\t'; \
37+
apt-get update; \
38+
apt-get install -y --no-install-recommends \
39+
curl; \
40+
apt-get clean;
41+
42+
USER ${UID}
43+
ENV GOPATH=/linuxfr-img
44+
ENV HOME=/linuxfr-img
1945
WORKDIR /linuxfr-img
2046

21-
COPY --from=build /linuxfr-img/bin/img-LinuxFr.org .
47+
COPY --from=build --chown=${UID}:0 --chmod=770 /linuxfr-img/bin/img-LinuxFr.org .
2248

2349
EXPOSE 8000
2450

deployment/linuxfr.org/Dockerfile

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,58 @@
1-
FROM debian:stretch-slim
1+
FROM docker.io/debian:bullseye-slim
22

3-
LABEL maintainer="adrien@adorsaz.ch"
4-
LABEL version="1.0"
5-
LABEL description="Run LinuxFr.org Ruby on Rails website"
3+
LABEL org.opencontainers.image.title="LinuxFr.org website"
4+
LABEL org.opencontainers.image.description="Run LinuxFr.org Ruby on Rails website"
5+
LABEL org.opencontainers.image.source="https://github.com/linuxfrorg/linuxfr.org"
6+
LABEL org.opencontainers.image.url="https://github.com/linuxfrorg/linuxfr.org/blob/master/Docker.md"
7+
LABEL org.opencontainers.image.licenses="AGPL-3.0-only"
8+
LABEL org.opencontainers.image.version="2.0"
9+
LABEL org.opencontainers.image.authors="Adrien Dorsaz <adrien@adorsaz.ch>"
610

7-
WORKDIR /linuxfr.org
11+
ARG UID=1200
812

913
# Install system dependencies
10-
# Debian Stretch has been archived so we replace the sources with the archived ones
11-
RUN echo 'deb http://archive.debian.org/debian stretch main' > '/etc/apt/sources.list' \
12-
&& echo 'deb http://archive.debian.org/debian stretch-proposed-updates main' >> '/etc/apt/sources.list' \
13-
&& echo 'deb http://archive.debian.org/debian stretch-backports main' >> '/etc/apt/sources.list.d/linuxfr.list' \
14-
&& apt-get update \
15-
&& apt-get install -y --no-install-recommends --allow-downgrades \
16-
mysql-client libmysql++-dev git \
17-
build-essential openssl libreadline-dev curl libcurl4-openssl-dev zlib1g=1:1.2.8.dfsg-5 \
14+
RUN \
15+
set -eux; \
16+
IFS=$'\n\t'; \
17+
apt-get update; \
18+
apt-get install -y --no-install-recommends --allow-downgrades \
19+
mariadb-client libmariadb++-dev git \
20+
build-essential openssl libreadline-dev curl libcurl4-openssl-dev zlib1g \
1821
zlib1g-dev libssl-dev libxml2-dev libxslt-dev autoconf libgmp-dev libyaml-dev \
1922
ncurses-dev bison automake libtool imagemagick libc6-dev hunspell \
2023
hunspell-fr-comprehensive ruby ruby-dev ruby-rack \
21-
&& apt-get install -t stretch-backports -y --no-install-recommends \
22-
nodejs npm \
23-
&& gem install bundler -v 1.17.3 \
24-
&& apt-get clean
24+
nodejs npm; \
25+
gem install bundler -v 1.17.3; \
26+
apt-get clean
2527

26-
RUN mkdir /home/linuxfr.org
27-
ENV HOME /home/linuxfr.org
28+
USER ${UID}
29+
ENV HOME=/linuxfr.org
30+
WORKDIR /linuxfr.org
2831

2932
# Install node external dependencies
30-
COPY package*.json ./
33+
COPY --chown=${UID}:0 --chmod=770 package*.json ./
3134
RUN npm ci
3235

3336
# Install external dependencies
34-
COPY Gemfile* ./
37+
COPY --chown=${UID}:0 --chmod=770 Gemfile* ./
38+
39+
USER 0
40+
RUN \
41+
set -eux; \
42+
IFS=$'\n\t'; \
43+
bundle config set path 'vendor/bundle'; \
44+
bundle config set deployment 'true'; \
45+
bundle install; \
46+
chown ${UID}:0 -R .;
3547

36-
RUN bundle config set path 'vendor/bundle' \
37-
&& bundle config set deployment 'true' \
38-
&& bundle install
48+
USER ${UID}
3949

4050
# Configure the application
41-
COPY deployment/linuxfr.org/database.yml config/database.yml
42-
COPY config/secrets.yml.sample config/secrets.yml
51+
COPY --chown=${UID}:0 --chmod=770 deployment/linuxfr.org/database.yml config/database.yml
52+
COPY --chown=${UID}:0 --chmod=770 config/secrets.yml.sample config/secrets.yml
4353

4454
# Bundle source code
45-
COPY . /linuxfr.org
55+
COPY --chown=${UID}:0 --chmod=770 . /linuxfr.org
4656

4757
EXPOSE 3000
4858

docker-compose.yaml

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.1'
2-
31
services:
42
linuxfr.org:
53
build:
@@ -10,63 +8,94 @@ services:
108
volumes:
119
# Share host directories so, the developer can edit them
1210
# 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
11+
- ./app:/linuxfr.org/app:Z
12+
- ./db:/linuxfr.org/db:Z
13+
- ./lib:/linuxfr.org/lib:Z
14+
- ./public:/linuxfr.org/public:Z
15+
- ./test:/linuxfr.org/test:Z
1716
# uploads are shared with the nginx service
1817
- data-uploads:/linuxfr.org/uploads
1918
tmpfs:
2019
- /linuxfr.org/public/tmp:size=100M
20+
healthcheck:
21+
test: curl --fail http://localhost:3000
2122
depends_on:
22-
- database
23-
- redis
23+
database:
24+
condition: service_healthy
25+
restart: true
26+
redis:
27+
condition: service_healthy
28+
restart: true
2429

2530
linuxfr-board:
2631
build:
2732
context: deployment/linuxfr-board
2833
env_file:
2934
- deployment/default.env
35+
healthcheck:
36+
test: curl --fail -I http://localhost:9000
3037
depends_on:
31-
- redis
38+
redis:
39+
condition: service_healthy
40+
restart: true
3241

3342
linuxfr-img:
3443
build:
3544
context: deployment/linuxfr-img
3645
env_file:
3746
- deployment/default.env
47+
healthcheck:
48+
test: curl --fail http://localhost:8000/status
3849
depends_on:
39-
- redis
50+
redis:
51+
condition: service_healthy
52+
restart: true
4053
volumes:
4154
- cache-img:/linuxfr-img/cache
4255

4356
nginx:
44-
image: nginx:stable
57+
image: docker.io/nginx:stable
4558
env_file:
4659
- deployment/default.env
4760
volumes:
48-
- ./deployment/nginx/templates:/etc/nginx/templates
49-
- ./public/fonts:/var/linuxfr/fonts
61+
- ./deployment/nginx/templates:/etc/nginx/templates:Z
62+
- ./public/fonts:/var/linuxfr/fonts:Z
5063
- data-uploads:/var/linuxfr/uploads
5164
ports:
52-
- "80:80"
65+
- target: 80
66+
published: 127.0.0.1:80
67+
protocol: tcp
68+
healthcheck:
69+
test: curl --fail http://$$DOMAIN && curl --fail http://$$DOMAIN/img && curl --fail -I http://$$DOMAIN/b
5370
depends_on:
54-
- linuxfr.org
55-
- linuxfr-board
56-
- linuxfr-img
71+
linuxfr.org:
72+
condition: service_healthy
73+
restart: true
74+
linuxfr-board:
75+
condition: service_healthy
76+
restart: true
77+
linuxfr-img:
78+
condition: service_healthy
79+
restart: true
5780

5881
database:
5982
build:
6083
context: deployment/database
6184
env_file:
6285
- deployment/default.env
6386
ports:
64-
- "3306:3306"
87+
- target: 3306
88+
published: 127.0.0.1:3306
89+
protocol: tcp
90+
healthcheck:
91+
test: mysql -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD --execute "SHOW DATABASES;"
6592
volumes:
6693
- data-database:/var/lib/mysql
6794

6895
redis:
69-
image: redis:5
96+
image: docker.io/redis:5
97+
healthcheck:
98+
test: redis-cli --raw incr ping
7099
volumes:
71100
- data-redis:/data
72101

0 commit comments

Comments
 (0)