Skip to content

Commit 6988e80

Browse files
hyvsnervo
authored andcommitted
Generalize s6 services usage
1 parent 02b074e commit 6988e80

File tree

20 files changed

+109
-87
lines changed

20 files changed

+109
-87
lines changed

lazy.ansible/.manala.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ manala:
77
- .manala/github
88
- .manala/gitlab
99
- .manala/make
10+
- .manala/services
1011
- .manala/.dockerignore
1112
- .manala/.gitignore
1213
- .manala/Makefile.tmpl

lazy.ansible/.manala/docker/Dockerfile.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ARG DEBIAN_FRONTEND="noninteractive"
99
ARG MANALA_USER_ID="1000"
1010
ARG MANALA_GROUP_ID="1000"
1111

12+
ARG TINI_VERSION="0.19.0"
1213
ARG GOSU_VERSION="1.17"
1314
ARG GOMPLATE_VERSION="3.11.7"
1415
ARG DIRENV_VERSION="2.33.0"
@@ -45,6 +46,10 @@ RUN \
4546
&& adduser --home /home/lazy --shell /bin/bash --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \
4647
&& install --verbose --mode 0755 --group lazy --owner lazy --directory /run/user/${MANALA_USER_ID} \
4748
&& echo "lazy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/lazy \
49+
# Tini
50+
&& curl -sSL "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
51+
--output /usr/local/bin/tini \
52+
&& chmod +x /usr/local/bin/tini \
4853
# Gosu
4954
&& curl -sSL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
5055
--output /usr/local/bin/gosu \
@@ -57,13 +62,20 @@ RUN \
5762
&& curl -sSL "https://github.com/direnv/direnv/releases/download/v${DIRENV_VERSION}/direnv.linux-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
5863
--output /usr/local/bin/direnv \
5964
&& chmod +x /usr/local/bin/direnv \
65+
# Services
66+
&& install --verbose --directory /etc/services/enabled \
67+
&& install --verbose --directory /etc/services/available \
6068
# Bash completion
6169
&& install --verbose --mode 0755 --directory /etc/bash_completion.d \
6270
# Oh My Bash
6371
&& git clone https://github.com/ohmybash/oh-my-bash.git /usr/local/share/oh-my-bash \
6472
# Clean
6573
&& rm -rf /var/lib/apt/lists/*
6674

75+
# Services
76+
COPY services/docker-bridge /etc/services/available/docker-bridge
77+
COPY services/ssh-auth-bridge /etc/services/available/ssh-auth-bridge
78+
6779
##########
6880
# System #
6981
##########

lazy.ansible/.manala/docker/entrypoint.sh

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22

33
set -e
44

5-
# Ssh agent bridge
6-
if [ -n "${SSH_AUTH_SOCK}" ]; then
7-
sh -c " \
8-
while sleep 1; do \
9-
rm -f /var/run/ssh-auth-bridge.sock ;
10-
socat \
11-
UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,mode=777 \
12-
UNIX-CONNECT:/var/run/ssh-auth.sock ; \
13-
done \
14-
" &
15-
fi
16-
17-
# Docker bridge
18-
if [ -n "${DOCKER_HOST}" ]; then
19-
sh -c " \
20-
while sleep 1; do \
21-
rm -f /var/run/docker-bridge.sock ;
22-
socat -t 600 \
23-
UNIX-LISTEN:/var/run/docker-bridge.sock,fork,mode=777 \
24-
UNIX-CONNECT:/var/run/docker.sock ; \
25-
done \
26-
" &
27-
fi
28-
295
# As a consequence of running the container as root user,
306
# tty is not writable by sued user
317
if [ -t 1 ]; then
@@ -48,10 +24,18 @@ if [ -d ".manala/etc" ]; then
4824
GOMPLATE_LOG_FORMAT=simple gomplate --input-dir=.manala/etc --output-dir=/etc 2>/dev/null
4925
fi
5026

51-
# Services
52-
if [ $# -eq 0 ] && [ -d "/etc/services.d" ]; then
53-
exec s6-svscan /etc/services.d
27+
# Docker bridge
28+
if [ -n "${DOCKER_HOST}" ]; then
29+
ln --symbolic /etc/services/available/docker-bridge /etc/services/enabled/
5430
fi
5531

32+
# Ssh auth bridge
33+
if [ -n "${SSH_AUTH_SOCK}" ]; then
34+
ln --symbolic /etc/services/available/ssh-auth-bridge /etc/services/enabled/
35+
fi
36+
37+
# Services
38+
s6-svscan /etc/services/enabled &
39+
5640
# Command
57-
exec gosu lazy "$@"
41+
exec tini -- gosu lazy "$@"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
exec socat \
4+
UNIX-LISTEN:/var/run/docker-bridge.sock,fork,unlink-early,mode=777 \
5+
UNIX-CONNECT:/var/run/docker.sock
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
exec socat \
4+
UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,unlink-early,mode=777 \
5+
UNIX-CONNECT:/var/run/ssh-auth.sock

lazy.kubernetes/.manala.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ manala:
77
- .manala/github
88
- .manala/gitlab
99
- .manala/make
10+
- .manala/services
1011
- .manala/.dockerignore
1112
- .manala/.gitignore
1213
- .manala/Makefile.tmpl

lazy.kubernetes/.manala/docker/Dockerfile.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ARG DEBIAN_FRONTEND="noninteractive"
99
ARG MANALA_USER_ID="1000"
1010
ARG MANALA_GROUP_ID="1000"
1111

12+
ARG TINI_VERSION="0.19.0"
1213
ARG GOSU_VERSION="1.17"
1314
ARG GOMPLATE_VERSION="3.11.7"
1415
ARG DIRENV_VERSION="2.33.0"
@@ -45,6 +46,10 @@ RUN \
4546
&& adduser --home /home/lazy --shell /bin/bash --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \
4647
&& install --verbose --mode 0755 --group lazy --owner lazy --directory /run/user/${MANALA_USER_ID} \
4748
&& echo "lazy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/lazy \
49+
# Tini
50+
&& curl -sSL "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
51+
--output /usr/local/bin/tini \
52+
&& chmod +x /usr/local/bin/tini \
4853
# Gosu
4954
&& curl -sSL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
5055
--output /usr/local/bin/gosu \
@@ -57,13 +62,20 @@ RUN \
5762
&& curl -sSL "https://github.com/direnv/direnv/releases/download/v${DIRENV_VERSION}/direnv.linux-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
5863
--output /usr/local/bin/direnv \
5964
&& chmod +x /usr/local/bin/direnv \
65+
# Services
66+
&& install --verbose --directory /etc/services/enabled \
67+
&& install --verbose --directory /etc/services/available \
6068
# Bash completion
6169
&& install --verbose --mode 0755 --directory /etc/bash_completion.d \
6270
# Oh My Bash
6371
&& git clone https://github.com/ohmybash/oh-my-bash.git /usr/local/share/oh-my-bash \
6472
# Clean
6573
&& rm -rf /var/lib/apt/lists/*
6674

75+
# Services
76+
COPY services/docker-bridge /etc/services/available/docker-bridge
77+
COPY services/ssh-auth-bridge /etc/services/available/ssh-auth-bridge
78+
6779
##########
6880
# System #
6981
##########

lazy.kubernetes/.manala/docker/entrypoint.sh

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22

33
set -e
44

5-
# Ssh agent bridge
6-
if [ -n "${SSH_AUTH_SOCK}" ]; then
7-
sh -c " \
8-
while sleep 1; do \
9-
rm -f /var/run/ssh-auth-bridge.sock ;
10-
socat \
11-
UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,mode=777 \
12-
UNIX-CONNECT:/var/run/ssh-auth.sock ; \
13-
done \
14-
" &
15-
fi
16-
17-
# Docker bridge
18-
if [ -n "${DOCKER_HOST}" ]; then
19-
sh -c " \
20-
while sleep 1; do \
21-
rm -f /var/run/docker-bridge.sock ;
22-
socat -t 600 \
23-
UNIX-LISTEN:/var/run/docker-bridge.sock,fork,mode=777 \
24-
UNIX-CONNECT:/var/run/docker.sock ; \
25-
done \
26-
" &
27-
fi
28-
295
# As a consequence of running the container as root user,
306
# tty is not writable by sued user
317
if [ -t 1 ]; then
@@ -48,10 +24,18 @@ if [ -d ".manala/etc" ]; then
4824
GOMPLATE_LOG_FORMAT=simple gomplate --input-dir=.manala/etc --output-dir=/etc 2>/dev/null
4925
fi
5026

51-
# Services
52-
if [ $# -eq 0 ] && [ -d "/etc/services.d" ]; then
53-
exec s6-svscan /etc/services.d
27+
# Docker bridge
28+
if [ -n "${DOCKER_HOST}" ]; then
29+
ln --symbolic /etc/services/available/docker-bridge /etc/services/enabled/
5430
fi
5531

32+
# Ssh auth bridge
33+
if [ -n "${SSH_AUTH_SOCK}" ]; then
34+
ln --symbolic /etc/services/available/ssh-auth-bridge /etc/services/enabled/
35+
fi
36+
37+
# Services
38+
s6-svscan /etc/services/enabled &
39+
5640
# Command
57-
exec gosu lazy "$@"
41+
exec tini -- gosu lazy "$@"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
exec socat \
4+
UNIX-LISTEN:/var/run/docker-bridge.sock,fork,unlink-early,mode=777 \
5+
UNIX-CONNECT:/var/run/docker.sock
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
exec socat \
4+
UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,unlink-early,mode=777 \
5+
UNIX-CONNECT:/var/run/ssh-auth.sock

lazy.symfony/.manala.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ manala:
88
- .manala/github
99
- .manala/gitlab
1010
- .manala/make
11+
- .manala/services
1112
- .manala/.dockerignore
1213
- .manala/.gitignore
1314
- .manala/Makefile.tmpl

lazy.symfony/.manala/docker/Dockerfile.tmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ARG DEBIAN_FRONTEND="noninteractive"
99
ARG MANALA_USER_ID="1000"
1010
ARG MANALA_GROUP_ID="1000"
1111

12+
ARG TINI_VERSION="0.19.0"
1213
ARG GOSU_VERSION="1.17"
1314
ARG GOMPLATE_VERSION="3.11.7"
1415
ARG DIRENV_VERSION="2.33.0"
@@ -45,6 +46,10 @@ RUN \
4546
&& adduser --home /home/lazy --shell /bin/bash --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \
4647
&& install --verbose --mode 0755 --group lazy --owner lazy --directory /run/user/${MANALA_USER_ID} \
4748
&& echo "lazy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/lazy \
49+
# Tini
50+
&& curl -sSL "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
51+
--output /usr/local/bin/tini \
52+
&& chmod +x /usr/local/bin/tini \
4853
# Gosu
4954
&& curl -sSL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
5055
--output /usr/local/bin/gosu \
@@ -57,13 +62,20 @@ RUN \
5762
&& curl -sSL "https://github.com/direnv/direnv/releases/download/v${DIRENV_VERSION}/direnv.linux-{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
5863
--output /usr/local/bin/direnv \
5964
&& chmod +x /usr/local/bin/direnv \
65+
# Services
66+
&& install --verbose --directory /etc/services/enabled \
67+
&& install --verbose --directory /etc/services/available \
6068
# Bash completion
6169
&& install --verbose --mode 0755 --directory /etc/bash_completion.d \
6270
# Oh My Bash
6371
&& git clone https://github.com/ohmybash/oh-my-bash.git /usr/local/share/oh-my-bash \
6472
# Clean
6573
&& rm -rf /var/lib/apt/lists/*
6674

75+
# Services
76+
COPY services/docker-bridge /etc/services/available/docker-bridge
77+
COPY services/ssh-auth-bridge /etc/services/available/ssh-auth-bridge
78+
6779
##########
6880
# System #
6981
##########
@@ -133,6 +145,8 @@ Pin-Priority: 1000\n\
133145
# Clean
134146
&& rm -rf /var/lib/apt/lists/*
135147

148+
COPY services/nginx /etc/services/enabled/nginx
149+
136150
# Php
137151
{{ $php := .Vars.system.php -}}
138152
RUN \
@@ -174,6 +188,8 @@ Signed-By: /etc/apt/keyrings/sury_php.gpg\n\
174188
# Clean
175189
&& rm -rf /var/lib/apt/lists/*
176190

191+
COPY services/php /etc/services/enabled/php
192+
177193
{{ $nodejs := .Vars.system.nodejs -}}
178194
{{ if $nodejs.version -}}
179195
# Nodejs

lazy.symfony/.manala/docker/entrypoint.sh

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22

33
set -e
44

5-
# Ssh agent bridge
6-
if [ -n "${SSH_AUTH_SOCK}" ]; then
7-
sh -c " \
8-
while sleep 1; do \
9-
rm -f /var/run/ssh-auth-bridge.sock ;
10-
socat \
11-
UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,mode=777 \
12-
UNIX-CONNECT:/var/run/ssh-auth.sock ; \
13-
done \
14-
" &
15-
fi
16-
17-
# Docker bridge
18-
if [ -n "${DOCKER_HOST}" ]; then
19-
sh -c " \
20-
while sleep 1; do \
21-
rm -f /var/run/docker-bridge.sock ;
22-
socat -t 600 \
23-
UNIX-LISTEN:/var/run/docker-bridge.sock,fork,mode=777 \
24-
UNIX-CONNECT:/var/run/docker.sock ; \
25-
done \
26-
" &
27-
fi
28-
295
# As a consequence of running the container as root user,
306
# tty is not writable by sued user
317
if [ -t 1 ]; then
@@ -48,10 +24,15 @@ if [ -d ".manala/etc" ]; then
4824
GOMPLATE_LOG_FORMAT=simple gomplate --input-dir=.manala/etc --output-dir=/etc 2>/dev/null
4925
fi
5026

51-
# Services
52-
if [ $# -eq 0 ] && [ -d "/etc/services.d" ]; then
53-
exec s6-svscan /etc/services.d
27+
# Docker bridge
28+
if [ -n "${DOCKER_HOST}" ]; then
29+
ln --symbolic /etc/services/available/docker-bridge /etc/services/enabled/
5430
fi
5531

56-
# Command
57-
exec gosu lazy "$@"
32+
# Ssh auth bridge
33+
if [ -n "${SSH_AUTH_SOCK}" ]; then
34+
ln --symbolic /etc/services/available/ssh-auth-bridge /etc/services/enabled/
35+
fi
36+
37+
# Services
38+
exec s6-svscan /etc/services/enabled

lazy.symfony/.manala/etc/services.d/.s6-svscan/finish

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
exec socat \
4+
UNIX-LISTEN:/var/run/docker-bridge.sock,fork,unlink-early,mode=777 \
5+
UNIX-CONNECT:/var/run/docker.sock
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/sh
2+
23
exec nginx -c /etc/nginx/project.conf
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/sh
2+
23
exec php-fpm --fpm-config /etc/php/default/fpm/project.conf
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
exec socat \
4+
UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,unlink-early,mode=777 \
5+
UNIX-CONNECT:/var/run/ssh-auth.sock

0 commit comments

Comments
 (0)