Skip to content

Commit ef3a073

Browse files
committed
local builds & secrets
1 parent 15c4857 commit ef3a073

File tree

6 files changed

+152
-24
lines changed

6 files changed

+152
-24
lines changed

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM jc21/alpine-nginx-full:node
2+
LABEL maintainer="Jamie Curnow <jc@jc21.com>"
3+
4+
ENV SUPPRESS_NO_CONFIG_WARNING=1
5+
ENV S6_FIX_ATTRS_HIDDEN=1
6+
ENV NODE_ENV=production
7+
8+
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
9+
&& apk update \
10+
&& apk add python3 certbot jq \
11+
&& python3 -m ensurepip \
12+
&& rm -rf /var/cache/apk/*
13+
14+
# s6 overlay
15+
COPY scripts/install-s6 /tmp/install-s6
16+
RUN /tmp/install-s6 "${TARGETPLATFORM}" && rm -f /tmp/install-s6
17+
18+
EXPOSE 80
19+
EXPOSE 81
20+
EXPOSE 443
21+
22+
ADD backend /app
23+
ADD frontend/dist /app/frontend
24+
COPY global /app/global
25+
26+
WORKDIR /app
27+
RUN yarn install
28+
29+
# add late to limit cache-busting by modifications
30+
COPY docker/rootfs /
31+
32+
# Remove frontend service not required for prod, dev nginx config as well
33+
RUN rm -rf /etc/services.d/frontend
34+
RUN rm -f /etc/nginx/conf.d/dev.conf
35+
36+
VOLUME [ "/data", "/etc/letsencrypt" ]
37+
ENTRYPOINT [ "/init" ]
38+
39+
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health

docker-compose.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# docker-compose.yml
2+
version: "3.7"
3+
4+
secrets:
5+
# paths assume the .secrets folder is sibling depth to folder where docker-compose resides
6+
DB_ROOT_PWD:
7+
file: ../.secrets/db_root_pwd.txt
8+
MYSQL_PWD:
9+
file: ../.secrets/mysql_pwd.txt
10+
11+
# networks:
12+
# npm-bridge: # arbitrary name
13+
# driver: bridge
14+
15+
services:
16+
mariadb:
17+
image: ahgraber/mariadb-aria:test
18+
container_name: mariadb
19+
secrets:
20+
- DB_ROOT_PWD
21+
- MYSQL_PWD
22+
# networks:
23+
# - npm-bridge
24+
# ports:
25+
# - 3306:3306
26+
environment:
27+
# MYSQL_ROOT_PASSWORD: "npm"
28+
MYSQL_ROOT_PASSWORD__FILE: /run/secrets/DB_ROOT_PWD
29+
MYSQL_DATABASE: "npm"
30+
MYSQL_USER: "npm"
31+
# MYSQL_PASSWORD: "npm"
32+
MYSQL_PASSWORD__FILE: /run/secrets/MYSQL_PWD
33+
volumes:
34+
- ./data/mysql:/var/lib/mysql
35+
# - npm-mount:/var/lib/mysql
36+
# restart: unless-stopped
37+
38+
npm:
39+
build:
40+
context: .
41+
dockerfile: ./Dockerfile
42+
# args:
43+
# TARGETPLATFORM: arm64v8
44+
image: nginx-proxy-manager:test # provide a name and tag for the image
45+
container_name: npm
46+
secrets:
47+
- MYSQL_PWD
48+
# networks:
49+
# - npm-bridge
50+
ports:
51+
- 8080:80
52+
- 8443:443
53+
- 8888:81
54+
environment:
55+
DISABLE_IPV6: 'true'
56+
DB_MYSQL_HOST: "mariadb"
57+
DB_MYSQL_PORT: 3306
58+
DB_MYSQL_NAME: "npm"
59+
DB_MYSQL_USER: "npm"
60+
# DB_MYSQL_PASSWORD: "npm"
61+
DB_MYSQL_PASSWORD__FILE: /run/secrets/MYSQL_PWD
62+
# DB_MYSQL_PASSWORD: "sqlL3tm3in"
63+
volumes:
64+
- ./data/npm:/data
65+
- ./data/letsencrypt:/etc/letsencrypt
66+
# - npm-mount:/data
67+
# - letsencrypt-mount:/etc/letsencrypt
68+
depends_on:
69+
- mariadb
70+
# restart: unless-stopped
71+
72+
# ## https://stackoverflow.com/questions/45282608/how-to-directly-mount-nfs-share-volume-in-container-using-docker-compose-v3
73+
# volumes:
74+
# npm-mount:
75+
# driver: local
76+
# driver_opts:
77+
# type: nfs
78+
# o: nfsvers=4,addr=10.2.1.1,rw,retry=1,soft,nolock
79+
# device: ":/npm"
80+
# letsencrypt-mount:
81+
# driver: local
82+
# driver_opts:
83+
# type: nfs
84+
# o: nfsvers=4,addr=10.2.1.1,rw,retry=1,soft,nolock
85+
# device: ":/letsencrypt"
86+

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ RUN yarn install
4343
RUN rm -rf /etc/services.d/frontend RUN rm -f /etc/nginx/conf.d/dev.conf
4444

4545
VOLUME [ "/data", "/etc/letsencrypt" ]
46-
CMD [ "/init" ]
46+
ENTRYPOINT [ "/init" ]
4747

4848
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health

docker/dev/Dockerfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
FROM jc21/alpine-nginx-full:node
22
LABEL maintainer="Jamie Curnow <jc@jc21.com>"
33

4-
ENV S6_LOGGING=0
54
ENV SUPPRESS_NO_CONFIG_WARNING=1
65
ENV S6_FIX_ATTRS_HIDDEN=1
6+
ENV NODE_ENV=production
77

88
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
99
&& apk update \
1010
&& apk add python3 certbot jq \
1111
&& python3 -m ensurepip \
1212
&& rm -rf /var/cache/apk/*
1313

14-
# Task
15-
RUN cd /usr \
16-
&& curl -sL https://taskfile.dev/install.sh | sh \
17-
&& cd /root
18-
19-
COPY rootfs /
20-
RUN rm -f /etc/nginx/conf.d/production.conf
21-
2214
# s6 overlay
23-
RUN curl -L -o /tmp/s6-overlay-amd64.tar.gz "https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-amd64.tar.gz" \
24-
&& tar -xzf /tmp/s6-overlay-amd64.tar.gz -C /
15+
COPY scripts/install-s6 /tmp/install-s6
16+
RUN /tmp/install-s6 "${TARGETPLATFORM}" && rm -f /tmp/install-s6
2517

2618
EXPOSE 80
2719
EXPOSE 81
2820
EXPOSE 443
2921

30-
ENTRYPOINT [ "/init" ]
22+
COPY docker/rootfs /
23+
ADD backend /app
24+
ADD frontend/dist /app/frontend
25+
COPY global /app/global
26+
27+
WORKDIR /app
28+
RUN yarn install
29+
30+
# Remove frontend service not required for prod, dev nginx config as well
31+
RUN rm -rf /etc/services.d/frontend RUN rm -f /etc/nginx/conf.d/dev.conf
3132

32-
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health
33+
VOLUME [ "/data", "/etc/letsencrypt" ]
34+
ENTRYPOINT [ "/init" ]

docker/dev/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ services:
2828

2929
npm:
3030
build:
31-
context: ../
32-
dockerfile: ./dev/Dockerfile
31+
context: ../../
32+
dockerfile: ./docker/dev/Dockerfile
3333
# args:
3434
# TARGETPLATFORM: arm64v8
3535
image: npm:test # provide a name and tag for the image

docker/rootfs/etc/cont-init.d/01_envfile.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
# ref: https://github.com/linuxserver/docker-baseimage-alpine/blob/master/root/etc/cont-init.d/01-envfile
33

44
# in s6, environmental variables are written as text files for s6 to monitor
5-
for FILENAME in $(find /var/run/s6/container_environment/ | grep "^.*__FILE"); do
6-
echo "[secret-init] Evaluating ${FILENAME}"
5+
# seach through full-path filenames for files ending in "__FILE"
6+
for FILENAME in $(find /var/run/s6/container_environment/ | grep "__FILE$"); do
7+
echo "[secret-init] Evaluating ${FILENAME##*/}"
78

8-
# set SECRETFILE to the contents of the variable
9+
# set SECRETFILE to the contents of the full-path textfile
910
SECRETFILE=$(cat ${FILENAME})
1011
# SECRETFILE=${FILENAME}
1112
echo "[secret-init] Setting SECRETFILE to ${SECRETFILE}..." # DEBUG - rm for prod!
1213

1314
# if SECRETFILE exists / is not null
1415
if [[ -f ${SECRETFILE} ]]; then
1516
# strip the appended "__FILE" from environmental variable name ...
16-
STRIPFILE=$(echo $FILENAME | sed "s/__FILE//g")
17+
STRIPFILE=$(echo ${FILENAME} | sed "s/__FILE//g")
1718
echo "[secret-init] Set STRIPFILE to ${STRIPFILE}" # DEBUG - rm for prod!
18-
19+
1920
# ... and set value to contents of secretfile
2021
# since s6 uses text files, this is effectively "export ..."
21-
cat ${SECRETFILE} > ${STRIPFILE}
22+
cat $(${SECRETFILE} | xargs) > ${STRIPFILE}
2223
echo "[secret-init] Set ${STRIPFILE} to $(cat ${STRIPFILE})" # DEBUG - rm for prod!"
23-
echo "[secret-init] Success! ${STRIPFILE##*/} set from ${FILENAME##*/}"
24+
echo "[secret-init] Success! ${STRIPFILE} set from ${FILENAME}"
2425

2526
else
26-
echo "[secret-init] cannot find secret in ${FILENAME##*/}"
27+
echo "[secret-init] cannot find secret in ${FILENAME}"
2728
fi
2829
done

0 commit comments

Comments
 (0)