Skip to content

Commit c0ee2ed

Browse files
committed
fix(startup): undo changes that caused regression in startup script
1 parent b343113 commit c0ee2ed

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bin
2828
.project
2929
${sys:DATA}
3030
*.log
31+
.certs
3132

3233
# User-specific stuff:
3334
.idea/workspace.xml

.scripts/convert-to-p12.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
#!/bin/sh
22

3-
certPath=${1:-"."} # if $1 is not passed, use current directory
3+
set -e
4+
5+
certPath=${1:-"."}
46
serverCrt="$certPath/server.crt"
57
serverKey="$certPath/server.key"
6-
caCrt="$certPath/ca.crt" # Path to the Certificate Authority certificate
8+
caCrt="$certPath/ca.crt"
79
pkcs12File="$certPath/signaling.p12"
8-
pkcs12Password=${2:-"changeme"} # if $2 is not passed, use "changeme"
10+
pkcs12Password=${2:-"changeme"}
911

1012
mkdir -p $certPath
1113

12-
# Check if server.crt and server.key files exist
1314
if [ ! -f "$serverCrt" ] || [ ! -f "$serverKey" ]; then
1415
echo "server.crt or server.key files not found. Generating certificates..."
15-
. "$(dirname "$0")/generate-certs.sh" $certPath
16+
. "$(dirname "$0")/generate-certs.sh" "$certPath"
1617
fi
1718

18-
# Check if ca.crt file exists to create a full chain of certificates
1919
if [ -f "$caCrt" ]; then
2020
echo "ca.crt file found. Creating a full chain of certificates..."
2121
cat $serverCrt $caCrt > "$certPath/fullchain.crt"
2222
openssl pkcs12 -export -in "$certPath/fullchain.crt" -inkey $serverKey -name "apiserver" -out $pkcs12File -password pass:$pkcs12Password
2323
else
24-
openssl pkcs12 -export -in $serverCrt -inkey $serverKey -name "apiserver" -out $pkcs12File -password pass:$pkcsPassword
24+
openssl pkcs12 -export -in $serverCrt -inkey $serverKey -name "apiserver" -out $pkcs12File -password pass:$pkcs12Password
2525
fi
2626

27+
openssl pkcs12 -info -in "$pkcs12File" -noout -passin pass:"$pkcs12Password" # Verifies the keystore
28+
2729
echo "PKCS12 keystore has been created at $pkcs12File"

.scripts/generate-certs.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
set -e
4+
35
basepath=${1:-"."} # if $1 is not passed, use current directory
46

57
mkdir -p $basepath

.scripts/init-postgres.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ set -e
55
# This scripts initializes the postgres database
66
initdb /var/lib/postgresql/data
77
pg_ctl start -D /var/lib/postgresql/data
8-
npx prisma@5.9.1 migrate deploy --schema=/service/schema.prisma
8+
npx prisma migrate deploy --schema=/service/schema.prisma
99
pg_ctl stop -D /var/lib/postgresql/data

Dockerfile

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,47 @@ RUN chmod +x heplify
2626
##
2727
FROM alpine:3.19 AS runner
2828

29-
ARG PKCS12_PASSWORD=changeme
30-
ARG POSTGRES_USER=postgres
31-
ARG POSTGRES_PASSWORD=postgres
29+
ARG PKCS12_PASSWORD="changeme"
30+
ARG POSTGRES_USER="postgres"
31+
ARG POSTGRES_PASSWORD="postgres"
3232
ARG CA_CERT_SUBJECT="/CN=Self Signed CA"
3333
ARG SERVER_CERT_SUBJECT="/CN=localhost"
34-
ARG PRISMA_VERSION=5.9.1
35-
ARG DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/routr
34+
ARG PRISMA_VERSION="5.9.1"
35+
ARG DATABASE_URL="postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/routr"
3636

3737
ENV PKCS12_PASSWORD=$PKCS12_PASSWORD \
38-
PATH_TO_CERTS=/etc/routr/certs \
39-
USER=fonoster \
38+
PATH_TO_CERTS="/etc/routr/certs" \
39+
USER="fonoster" \
4040
GID=5000 \
4141
UID=5000 \
42-
JAVA_HOME=/service/jre \
43-
EDGEPORT_RUNNER=/service/edgeport.sh \
42+
JAVA_HOME="/service/jre" \
43+
EDGEPORT_RUNNER="/service/edgeport.sh" \
4444
TLS_ON=false \
4545
VERIFY_CLIENT_CERT=false \
4646
CA_CERT_SUBJECT=$CA_CERT_SUBJECT \
4747
SERVER_CERT_SUBJECT=$SERVER_CERT_SUBJECT \
4848
DATABASE_URL=$DATABASE_URL \
4949
IGNORE_LOOPBACK_FROM_LOCALNETS=true \
5050
PRISMA_VERSION=$PRISMA_VERSION \
51-
START_INTERNAL_DB=true
51+
START_INTERNAL_DB=true \
52+
LOG4J2="/etc/routr/log4j2.yaml"
5253

5354
WORKDIR /service
5455

5556
COPY mods/edgeport/edgeport.sh .
5657
COPY mods/edgeport/libs libs
58+
COPY mods/pgdata/schema.prisma .
59+
COPY mods/pgdata/migrations migrations
60+
COPY mods/edgeport/etc/log4j2.yaml /etc/routr/log4j2.yaml
5761
COPY etc/edgeport.yaml config/edgeport.yaml
58-
COPY config/log4j2.yaml mods/edgeport/etc/log4j2.yaml
5962
COPY .scripts/convert-to-p12.sh .
6063
COPY .scripts/generate-certs.sh .
64+
COPY .scripts/init-postgres.sh .
6165
COPY --from=builder /work/dist dist
6266
COPY --from=builder /work/node_modules node_modules
6367
COPY --from=builder /work/package.json .
6468
COPY --from=builder /work/jre jre
6569
COPY --from=builder /work/heplify /usr/local/bin/
66-
COPY .scripts/init-postgres.sh .
67-
COPY mods/pgdata/schema.prisma .
68-
COPY mods/pgdata/migrations migrations
6970

7071
RUN apk add --no-cache libcap nodejs npm openssl postgresql sed sngrep su-exec tini \
7172
&& npm install -g prisma@${PRISMA_VERSION} \
@@ -74,25 +75,26 @@ RUN apk add --no-cache libcap nodejs npm openssl postgresql sed sngrep su-exec t
7475
&& adduser --disabled-password --gecos "" --ingroup ${USER} --home ${HOME} --uid ${UID} ${USER} \
7576
&& chown -R ${USER}:${USER} /service /etc/routr \
7677
&& chown -R postgres:postgres /var/lib/postgresql/data /run/postgresql /root/.npm \
77-
&& chmod +x edgeport.sh convert-to-p12.sh init-postgres.sh \
78+
&& chmod +x edgeport.sh convert-to-p12.sh init-postgres.sh generate-certs.sh \
7879
&& chmod 2777 /run/postgresql \
7980
&& setcap 'CAP_NET_RAW+eip' /usr/bin/sngrep \
8081
&& rm -rf /var/cache/apk/* /tmp/* \
81-
&& rm -rf /root/.npm /root/.config /root/.cache /root/.local \
82+
&& rm -rf /root/.npm /root/.config /root/.cache /root/.local package.json \
8283
&& apk del libcap
8384

8485
# Re-mapping the signal from 143 to 0
8586
ENTRYPOINT ["tini", "-v", "-e", "143", "--"]
8687

87-
CMD ["sh", "-c", "if [ \"$START_INTERNAL_DB\" = \"true\" ]; then \
88+
CMD ["/bin/sh", "-c", "if [ \"$START_INTERNAL_DB\" = \"true\" ]; then \
8889
su-exec postgres /service/init-postgres.sh; \
8990
su-exec postgres pg_ctl start -D /var/lib/postgresql/data --options='-h 0.0.0.0'; \
90-
fi && \
91-
DATABASE_URL=${DATABASE_URL} npx prisma@${PRISMA_VERSION} migrate deploy --schema=/service/schema.prisma && \
92-
su-exec $USER ./convert-to-p12.sh $PATH_TO_CERTS $PKCS12_PASSWORD && \
91+
fi; \
9392
if [ -n \"$HEPLIFY_OPTIONS\" ]; then \
9493
heplify $HEPLIFY_OPTIONS & \
95-
fi && \
96-
sed -i 's|keyStorePassword: .*|keyStorePassword: ${PKCS12_PASSWORD}|g' config/edgeport.yaml && \
97-
sed -i 's|trustStorePassword: .*|trustStorePassword: ${PKCS12_PASSWORD}|g' config/edgeport.yaml && \
98-
su-exec $USER node ./dist/runner"]
94+
fi; \
95+
npx prisma migrate deploy --schema=/service/schema.prisma; \
96+
sed -i \"s|keyStorePassword:.*|keyStorePassword: $PKCS12_PASSWORD|g\" config/edgeport.yaml; \
97+
sed -i \"s|trustStorePassword:.*|trustStorePassword: $PKCS12_PASSWORD|g\" config/edgeport.yaml; \
98+
su-exec $USER ./convert-to-p12.sh $PATH_TO_CERTS $PKCS12_PASSWORD; \
99+
su-exec $USER node ./dist/runner" \
100+
]

etc/certs/signaling.p12

-2.44 KB
Binary file not shown.

mods/edgeport/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ RUN apk add --no-cache --update g++ openjdk17-jdk \
1717
##
1818
FROM alpine:3.19 AS runner
1919

20-
ARG PKCS12_PASSWORD=changeme
21-
ARG PATH_TO_CERTS=/etc/routr/certs
22-
ARG PATH_TO_LOGS=/opt/routr/logs
20+
ARG PKCS12_PASSWORD="changeme"
21+
ARG PATH_TO_CERTS="/etc/routr/certs"
22+
ARG PATH_TO_LOGS="/opt/routr/logs"
2323
ARG CA_CERT_SUBJECT="/CN=Self Signed CA"
2424
ARG SERVER_CERT_SUBJECT="/CN=localhost"
2525

2626
ENV PKCS12_PASSWORD=$PKCS12_PASSWORD \
2727
PATH_TO_CERTS=$PATH_TO_CERTS \
2828
PATH_TO_LOGS=$PATH_TO_LOGS \
29-
CONFIG_PATH=/etc/routr/edgeport.yaml \
29+
CONFIG_PATH="/etc/routr/edgeport.yaml" \
3030
CA_CERT_SUBJECT=$CA_CERT_SUBJECT \
3131
SERVER_CERT_SUBJECT=$SERVER_CERT_SUBJECT \
3232
IGNORE_LOOPBACK_FROM_LOCALNETS=true \
33-
LOG4J2=/etc/routr/log4j2.yaml \
34-
JAVA_HOME=/opt/routr/jre
33+
LOG4J2="/etc/routr/log4j2.yaml" \
34+
JAVA_HOME="/opt/routr/jre"
3535

3636
WORKDIR /opt/routr
3737

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"start:deps": "docker compose -f compose.dev.yaml up rtpengine redis postgres adminer -d",
2323
"stop:deps": "docker compose -f compose.dev.yaml down rtpengine redis postgres adminer",
2424
"db:migrate": "npx prisma migrate dev --schema ./mods/pgdata/schema.prisma --name changeme",
25-
"generate:certs": "./.scripts/generate-certs.sh",
25+
"generate:certs": "SERVER_CERT_SUBJECT='/CN=localhost' CA_CERT_SUBJECT='/CN=Self Signed CA' ./.scripts/generate-certs.sh .certs",
2626
"convert:certs": "./.scripts/convert-to-p12.sh && mv signaling.p12 etc/certs/",
2727
"transpile": "tsc",
2828
"make": "npm install && npm run build && npm run setup",

0 commit comments

Comments
 (0)