Skip to content

Commit 7ccf4ea

Browse files
committed
Few docker improvements
1 parent 1ebf239 commit 7ccf4ea

9 files changed

+128
-151
lines changed

.secrets/mongo_admin_password.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mongoadminpassword

.secrets/mongo_shieldy_password.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shieldyDBpass

.secrets/shieldy_token.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1111111111:XXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXX

Dockerfile

+33-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
FROM node:lts
2-
3-
WORKDIR /usr/src/app
4-
5-
COPY . .
6-
7-
#Required by wait-for
8-
RUN apt-get -y update
9-
RUN apt-get install -y netcat
10-
#Required by pupetteer / chrome headless for image captcha generation
11-
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
12-
#Required to seed the user and database for initial setup
13-
RUN wget https://repo.mongodb.org/apt/debian/dists/stretch/mongodb-org/4.2/main/binary-amd64/mongodb-org-shell_4.2.2_amd64.deb --quiet
14-
RUN dpkg -i mongodb-org-shell_4.2.2_amd64.deb
15-
#Install shieldy dependencies
16-
RUN yarn install
17-
18-
#Wait for mongo to be up, seed the user and db if needed and run shieldy
19-
ENTRYPOINT ./wait-for mongo:27017 -t 1 -- mongo mongodb://$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongo:27017/ --eval "let dbname='$MONGO_SHIELDY_DB';let username='$MONGO_SHIELDY_USERNAME';let userpassword='$MONGO_SHIELDY_PASSWORD'" init-mongo.js && yarn distribute
1+
FROM node:12-alpine
2+
3+
RUN mkdir -p /usr/src/app
4+
WORKDIR /usr/src/app
5+
6+
COPY ./package.json .
7+
COPY ./src ./src
8+
COPY ./scripts ./scripts
9+
COPY ./tsconfig.json .
10+
COPY ./yarn.lock .
11+
COPY ./entrypoint.sh .
12+
13+
RUN apk add --no-cache \
14+
chromium \
15+
nss \
16+
freetype \
17+
freetype-dev \
18+
harfbuzz \
19+
ca-certificates \
20+
ttf-freefont \
21+
nodejs \
22+
yarn
23+
24+
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
25+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
26+
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
27+
28+
# Install shieldy dependencies
29+
RUN yarn install
30+
31+
RUN rm -rf /usr/local/lib/node_modules/npm/ /usr/local/bin/npm
32+
33+
CMD ["./entrypoint.sh"]

docker-compose.yml

+60-38
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,60 @@
1-
version: "3"
2-
3-
services:
4-
shieldy:
5-
build: .
6-
restart: always
7-
environment:
8-
MONGO_INITDB_ROOT_USERNAME: mongoadmin
9-
MONGO_INITDB_ROOT_PASSWORD: example
10-
MONGO_SHIELDY_DB: shieldyDB
11-
MONGO_SHIELDY_USERNAME: shieldyDBuser
12-
MONGO_SHIELDY_PASSWORD: shieldyDBpassword
13-
TOKEN: 111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
14-
MONGO: mongodb://shieldyDBuser:shieldyDBpassword@mongo:27017/shieldyDB
15-
ADMIN: 111111111
16-
depends_on:
17-
- mongo
18-
mongo:
19-
image: mongo
20-
restart: always
21-
environment:
22-
MONGO_INITDB_ROOT_USERNAME: mongoadmin
23-
MONGO_INITDB_ROOT_PASSWORD: example
24-
volumes:
25-
- dbdata:/data/db
26-
# If database debugging is needed
27-
# mongo-express:
28-
# image: mongo-express
29-
# restart: always
30-
# ports:
31-
# - 8081:8081
32-
# environment:
33-
# ME_CONFIG_MONGODB_ADMINUSERNAME: mongoadmin
34-
# ME_CONFIG_MONGODB_ADMINPASSWORD: example
35-
# depends_on:
36-
# - mongo
37-
volumes:
38-
dbdata:
1+
version: "3"
2+
3+
services:
4+
shieldy:
5+
build: .
6+
restart: always
7+
environment:
8+
MONGO_SHIELDY_DB: shieldyDB
9+
MONGO_SHIELDY_USERNAME: shieldyDBuser
10+
MONGO_SHIELDY_PASSWORD_FILE: /run/secrets/mongo_shieldy_password
11+
MONGO_INITDB_DATABASE: shieldyDB
12+
TOKEN_FILE: /run/secrets/shieldy_token
13+
ADMIN: 658158536
14+
secrets:
15+
- shieldy_token
16+
- mongo_shieldy_password
17+
depends_on:
18+
- wait-dependencies
19+
mongo:
20+
image: mongo
21+
restart: always
22+
environment:
23+
MONGO_INITDB_ROOT_USERNAME: mongoadmin
24+
MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/mongo_admin_password
25+
MONGO_SHIELDY_USERNAME: shieldyDBuser
26+
MONGO_SHIELDY_PASSWORD_FILE: /run/secrets/mongo_shieldy_password
27+
MONGO_INITDB_DATABASE: shieldyDB
28+
secrets:
29+
- mongo_admin_password
30+
- mongo_shieldy_password
31+
volumes:
32+
- dbdata:/data/db
33+
- ./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro
34+
wait-dependencies:
35+
image: willwill/wait-for-it:latest
36+
depends_on:
37+
- mongo
38+
entrypoint: /bin/sh
39+
command: >
40+
-c "./wait-for-it.sh mongo:27017 --strict --timeout=1"
41+
# If database debugging is needed
42+
# mongo-express:
43+
# image: mongo-express
44+
# restart: always
45+
# ports:
46+
# - 8081:8081
47+
# environment:
48+
# ME_CONFIG_MONGODB_ADMINUSERNAME: mongoadmin
49+
# ME_CONFIG_MONGODB_ADMINPASSWORD: example
50+
# depends_on:
51+
# - mongo
52+
secrets:
53+
mongo_admin_password:
54+
file: .secrets/mongo_admin_password.txt
55+
mongo_shieldy_password:
56+
file: .secrets/mongo_shieldy_password.txt
57+
shieldy_token:
58+
file: .secrets/shieldy_token.txt
59+
volumes:
60+
dbdata:

entrypoint.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
if [ ! -z ${MONGO_SHIELDY_PASSWORD_FILE+x} ]; then
4+
MONGO_SHIELDY_PASSWORD=$(cat ${MONGO_SHIELDY_PASSWORD_FILE})
5+
fi
6+
7+
if [ ! -z ${TOKEN_FILE+x} ]; then
8+
TOKEN=$(cat ${TOKEN_FILE})
9+
export TOKEN
10+
fi
11+
12+
export MONGO=mongodb://${MONGO_SHIELDY_USERNAME}:${MONGO_SHIELDY_PASSWORD}@mongo:27017/${MONGO_INITDB_DATABASE}
13+
14+
yarn distribute
15+

init-mongo.js

-15
This file was deleted.

init-mongo.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -Eeuo pipefail
3+
4+
if [ ! -z ${MONGO_SHIELDY_PASSWORD_FILE+x} ]; then
5+
MONGO_SHIELDY_PASSWORD=$(cat ${MONGO_SHIELDY_PASSWORD_FILE})
6+
fi
7+
8+
if [ "$MONGO_SHIELDY_USERNAME" ] && [ "$MONGO_SHIELDY_PASSWORD" ]; then
9+
"${mongo[@]}" -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase "$rootAuthDatabase" "$MONGO_INITDB_DATABASE" <<-EOJS
10+
db.createUser({
11+
user: $(_js_escape "$MONGO_SHIELDY_USERNAME"),
12+
pwd: $(_js_escape "$MONGO_SHIELDY_PASSWORD"),
13+
roles: [{ role: "readWrite", db: $(_js_escape "$MONGO_INITDB_DATABASE")}]
14+
});
15+
EOJS
16+
fi
17+

wait-for

-79
This file was deleted.

0 commit comments

Comments
 (0)