Parcourir la source

Allow using directory bind mounts for a docker container

This helps with a situation when some applications do not allow mounting
individual files, but whole directories. In that case users could mount
`/config` directory with a single file, `config.toml`: `-v
/path/to/dir:/config`. Also, there is a backward compatibility to using
a single `/config.toml`
tags/v2.2.4^2
9seconds il y a 1 mois
Parent
révision
cfb5fe66be
1 fichiers modifiés avec 15 ajouts et 1 suppressions
  1. 15
    1
      Dockerfile

+ 15
- 1
Dockerfile Voir le fichier

@@ -5,6 +5,19 @@ FROM golang:1.26-alpine AS build
5 5
 
6 6
 ENV CGO_ENABLED=0
7 7
 
8
+# this is done for backward compatibility: before that we mounted a config
9
+# into /config.toml. Some application allow mounting directories only,
10
+# so it makes problems. So, instead we are going to do 2 steps:
11
+#  1. Create /config/config.toml as a symlink to /config.toml
12
+#  2. Force /mtg to use /config/config.toml
13
+#
14
+# it helps in both ways: users with directories could use /config directory
15
+# and overlap a symlink by their bind mount. Old users could continue using
16
+# /config.toml as a real config.
17
+RUN set -x \
18
+  && mkdir -p /config \
19
+  && ln -sv /config.toml /config/config.toml
20
+
8 21
 RUN --mount=type=cache,target=/var/cache/apk \
9 22
     set -x \
10 23
     && apk --update add \
@@ -35,8 +48,9 @@ RUN set -x \
35 48
 FROM scratch
36 49
 
37 50
 ENTRYPOINT ["/mtg"]
38
-CMD ["run", "/config.toml"]
51
+CMD ["run", "/config/config.toml"]
39 52
 
40 53
 COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
41 54
 COPY --from=build /app/mtg /mtg
42 55
 COPY --from=build /app/example.config.toml /config.toml
56
+COPY --from=build /config /config

Chargement…
Annuler
Enregistrer