aboutsummaryrefslogtreecommitdiffstats
path: root/docker
diff options
context:
space:
mode:
authorLibravatar Michal Kostewicz <m.kostewicz84@gmail.com>2021-02-05 19:18:05 +0100
committerLibravatar Michal Kostewicz <m.kostewicz84@gmail.com>2021-02-07 10:20:38 +0100
commit8337e2632686cf8d0dcf39474019370f7d3dc752 (patch)
tree7adac5b63d03aff8d81ab1250fa54d3007e51b41 /docker
parentMerge pull request #47 from cromefire/db-path (diff)
downloadferdium-server-8337e2632686cf8d0dcf39474019370f7d3dc752.tar.gz
ferdium-server-8337e2632686cf8d0dcf39474019370f7d3dc752.tar.zst
ferdium-server-8337e2632686cf8d0dcf39474019370f7d3dc752.zip
Moved getferdi/server-docker into getferdi/server repository.
Add sample docker-compose file and update README.md files in root and docker directories.
Diffstat (limited to 'docker')
-rw-r--r--docker/.dockerignore13
-rw-r--r--docker/.gitignore16
-rw-r--r--docker/Dockerfile97
-rw-r--r--docker/LICENSE21
-rw-r--r--docker/README.md224
-rw-r--r--docker/docker-compose.yml37
-rw-r--r--docker/logo.pngbin0 -> 340668 bytes
-rwxr-xr-xdocker/root/defaults/.env.example35
-rwxr-xr-xdocker/root/etc/cont-init.d/10-adduser32
-rwxr-xr-xdocker/root/etc/cont-init.d/50-config184
-rwxr-xr-xdocker/root/etc/services.d/ferdi-server/run10
11 files changed, 669 insertions, 0 deletions
diff --git a/docker/.dockerignore b/docker/.dockerignore
new file mode 100644
index 0000000..92207ac
--- /dev/null
+++ b/docker/.dockerignore
@@ -0,0 +1,13 @@
1.DS_Store
2
3# ignore .git and .cache folders
4.git
5.gitignore
6.github
7.gitattributes
8.cache
9
10# ignore all markdown files (md) beside all README*.md other than README-secret.md
11*.md
12!README*.md
13README-secret.md
diff --git a/docker/.gitignore b/docker/.gitignore
new file mode 100644
index 0000000..b726524
--- /dev/null
+++ b/docker/.gitignore
@@ -0,0 +1,16 @@
1# Node modules
2node_modules
3
4# Adonis directory for storing tmp files
5tmp
6
7# The development sqlite file
8database/development.sqlite
9database/adonis.sqlite
10
11# Uploaded recipes
12recipes/
13
14.DS_Store
15public/terms.html
16public/privacy.html
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644
index 0000000..2b165f5
--- /dev/null
+++ b/docker/Dockerfile
@@ -0,0 +1,97 @@
1FROM lsiobase/alpine:3.11
2
3# version labels
4ARG BUILD_DATE
5LABEL build_version="Ferdi-server-docker Build-date:- ${BUILD_DATE}"
6LABEL maintainer="xthursdayx"
7
8ARG FERDI_RELEASE
9ENV NODE_VERSION=10.16.3
10ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
11
12# install packages
13RUN \
14 echo "**** installing build packages ****" && \
15 apk add --no-cache \
16 libcap \
17 libstdc++ \
18 nano && \
19 apk add --no-cache --virtual .build-deps \
20 binutils-gold \
21 curl \
22 gnupg \
23 gcc \
24 g++ \
25 linux-headers \
26 make \
27 memcached \
28 python && \
29 echo "**** downloading keys ****" && \
30 # gpg keys listed at https://github.com/nodejs/node#release-keys
31 for key in \
32 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
33 FD3A5288F042B6850C66B31F09FE44734EB7990E \
34 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
35 DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
36 C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
37 B9AE9905FFD7803F25714661B63B535A4C206CA9 \
38 77984A986EBC2AA786BC0F66B01FBB92821C587A \
39 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
40 4ED778F539E3634C779C87C6D7062848A1AB005C \
41 A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
42 B9E2F5981AA6E0CD28160D9FF13993A75599653C \
43 ; do \
44 gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
45 gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
46 gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
47 done && \
48 echo "**** installing node ****" && \
49 curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.xz" && \
50 curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" && \
51 gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc && \
52 grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - && \
53 tar -xf "node-v$NODE_VERSION.tar.xz" && \
54 cd "node-v$NODE_VERSION" && \
55 ./configure --prefix=/usr && \
56 make -j$(getconf _NPROCESSORS_ONLN) V= && \
57 make install && \
58 apk del .build-deps && \
59 cd / && \
60 rm -Rf "node-v$NODE_VERSION" && \
61 rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
62
63RUN \
64 apk add --no-cache --virtual .build-deps-ferdi \
65 curl \
66 gnupg \
67 tar && \
68 echo "**** installing npm ****" && \
69 npm config set unsafe-perm true && \
70 npm install -g npm@latest && \
71 find /usr/lib/node_modules/npm -name test -o -name .bin -type d | xargs rm -rf && \
72 echo "**** install ferdi server ****" && \
73 mkdir -p /ferdi && \
74 curl -o /ferdi/ferdi.tar.gz -L "https://github.com/getferdi/server/archive/master.tar.gz" && \
75 echo "**** cleanup ****" && \
76 apk del .build-deps-ferdi && \
77 rm -rf \
78 ${RM_DIRS} \
79 /SHASUMS256.txt \
80 /tmp/* \
81 /var/cache/apk/* \
82 /usr/share/man/* \
83 /usr/share/doc \
84 /root/.node-gyp \
85 /root/.config \
86 /usr/lib/node_modules/npm/man \
87 /usr/lib/node_modules/npm/doc \
88 /usr/lib/node_modules/npm/html \
89 /usr/lib/node_modules/npm/scripts
90
91COPY root/ /
92
93USER root
94
95# ports and volumes
96EXPOSE 80 443
97VOLUME /app/database /app/recipes /config
diff --git a/docker/LICENSE b/docker/LICENSE
new file mode 100644
index 0000000..a91c1fe
--- /dev/null
+++ b/docker/LICENSE
@@ -0,0 +1,21 @@
1MIT License
2
3Copyright (c) 2019 xthursdayx
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21SOFTWARE.
diff --git a/docker/README.md b/docker/README.md
new file mode 100644
index 0000000..8e0da08
--- /dev/null
+++ b/docker/README.md
@@ -0,0 +1,224 @@
1<p align="center">
2 <img src="./logo.png" alt="" width="300"/>
3</p>
4
5# Ferdi-server-docker
6[Ferdi](https://github.com/getferdi/ferdi) is a hard-fork of [Franz](https://github.com/meetfranz/franz), adding awesome features and removing unwanted ones. Ferdi-server is an unofficial replacement of the Franz server for use with the Ferdi Client.
7
8This is a dockerized version of [Ferdi-server](https://github.com/getferdi/server) running on Alpine Linux and Node.js (v10.16.3).
9
10## Why use a custom Ferdi-server?
11A custom ferdi-server allows you to experience the full potential of the Ferdi client. It allows you to use all Premium features (e.g. Workspaces and custom URL recipes) and [adding your own recipes](#creating-and-using-custom-recipes).
12
13## Features
14- [x] User registration and login
15- [x] Service creation, download, listing and removing
16- [x] Workspace support
17- [x] Functioning service store
18- [x] User dashboard
19- [x] Password recovery
20- [x] Export/import data to other ferdi-servers
21- [ ] Recipe update
22
23## Installation & Setup
24
25Here are some example snippets to help you get started creating a container.
26
27The docker can be run as is, with the default sqlite database, or you can modifying your ENV variables to use an external database (e.g. MYSql, MariaDB, Postgres, etc). After setting up the docker container you will need to create a NGINX reverse proxy to access Ferdi-server outside of your home network.
28
29### docker
30
31Pull the docker image:
32
33 docker pull getferdi/ferdi-server
34
35To create the docker container with the proper parameters:
36
37 docker create \
38 --name=ferdi-server \
39 -e NODE_ENV=development \
40 -e EXTERNAL_DOMAIN=<ferdi-serverdomain> \
41 -e DB_CONNECTION=<database> \
42 -e DB_HOST=<yourdbhost> \
43 -e DB_PORT=<yourdbport> \
44 -e DB_USER=<yourdbuser> \
45 -e DB_PASSWORD=<yourdbpass> \
46 -e DB_DATABASE=<yourdbdatabase> \
47 -e DB_SSL=false \
48 -e MAIL_CONNECTION=smtp \
49 -e SMPT_HOST=<smtpmailserver> \
50 -e SMTP_PORT=<smtpport> \
51 -e MAIL_SSL=true/false \
52 -e MAIL_USERNAME=<yourmailusername> \
53 -e MAIL_PASSWORD=<yourmailpassword> \
54 -e MAIL_SENDER=<sendemailaddress> \
55 -e IS_CREATION_ENABLED=true \
56 -e IS_DASHBOARD_ENABLED=true \
57 -e IS_REGISTRATION_ENABLED=true \
58 -e CONNECT_WITH_FRANZ=true \
59 -p <port>:80 \
60 -v <path to data>:/config \
61 -v <path to database>:/app/database \
62 -v <path to recipes>:/app/recipes \
63 --restart unless-stopped \
64 getferdi/ferdi-server
65
66### docker-compose
67
68 You can use sample [./docker/docker-compose.yml](https://github.com/getferdi/server/tree/master/docker/docker-compose.yml).
69 This will pull latest image from Docker Hub or use local image which you can build using instructions in [Building locally section](#Building-locally).
70
71 To start the application, use
72
73 docker-compose up
74The server will be launched at [http://localhost:3333/](http://localhost:3333/) address.
75
76## Configuration
77
78Container images are configured using parameters passed at runtime (such as those above). These parameters are separated by a colon and indicate `<external>:<internal>` respectively. For example, `-p 3333:80` would expose port `80` from inside the container to be accessible from the host's IP on port `3333` outside the container.
79After the first run, Ferdi-server's configuration is saved inside the `config.txt` file inside your persistent data directory (`/config` in the container).
80
81| Parameter | Function |
82| :----: | --- |
83| `-p <port>:80` | will map the container's port 80 to a port on the host, default is 3333 |
84| `-e NODE_ENV=development` | for specifying Node environment, production or development, default is development |
85| `-e EXTERNAL_DOMAIN=<ferdi-serverdomain>` | for specifying external domain address of the ferdi server |
86| `-e DB_CONNECTION=sqlite` | for specifying the database being used, default is sqlite |
87| `-e DB_HOST=<yourdbhost>` | for specifying the database host, default is 127.0.0.1 |
88| `-e DB_PORT=<yourdbport>` | for specifying the database port, default is 3306 |
89| `-e DB_USER=<yourdbuser>` | for specifying the database user, default is root |
90| `-e DB_PASSWORD=<yourdbpass>` | for specifying the database password, default is password |
91| `-e DB_DATABASE=adonis` | for specifying the database to be used, adonis |
92| `-e DB_SSL=false` | true only if your database is postgres and it is hosted online on platforms like GCP, AWS, etc |
93| `-e MAIL_CONNECTION=<mailsender>` | for specifying the mail sender to be used, default is smtp |
94| `-e SMPT_HOST=<smtpmailserver>` | for specifying the mail host to be used, default is 127.0.0.1 |
95| `-e SMTP_PORT=<smtpport>` | for specifying the mail port to be used, default is 2525 |
96| `-e MAIL_SSL=true/false` | for specifying SMTP mail secuirty, default is false |
97| `-e MAIL_USERNAME=<yourmailusername>` | for specifying your mail username to be used, default is username |
98| `-e MAIL_PASSWORD=<yourmailpassword>` | for specifying your mail password to be used, default is password |
99| `-e MAIL_SENDER=<sendemailaddress` | for specifying the mail sender address to be used, default is noreply@getferdi.com |
100| `-e IS_CREATION_ENABLED=true` | for specifying whether to enable the [creation of custom recipes](#creating-and-using-custom-recipes), default is true |
101| `-e IS_DASHBOARD_ENABLED=true` | for specifying whether to enable the Ferdi-server dashboard, default is true |
102| `-e IS_REGISTRATION_ENABLED=true` | for specifying whether to allow user registration, default is true |
103| `-e CONNECT_WITH_FRANZ=true` | for specifying whether to enable connections to the Franz server, default is true |
104| `-v <path to data>:/config` | this will store persistent ENV data on the docker host |
105| `-v <path to database>:/app/database` | this will strore Ferdi-server's database on the docker host for persistence |
106| `-v <path to recipes>:/app/recipes` | this will strore Ferdi-server's recipes on the docker host for persistence |
107
108By enabling the `CONNECT_WITH_FRANZ` option, Ferdi-server can:
109 - Show the full Franz recipe library instead of only custom recipes
110 - Import Franz accounts
111
112## Supported databases and drivers
113
114To use a different database than the default, SQLite, enter the driver code below in your ENV configuration.
115
116| Database | Driver |
117| :----: | --- |
118| MariaDB | mysql |
119| MySQL | mysql |
120| PostgreSQL | pg |
121| SQLite3 | sqlite |
122
123## Supported mail connections (advanced)
124
125To use a different email sender than the default, SMTP, enter the correct information in your ENV configuration and adapt your docker run, create, or compose commands accordingly.
126
127| Mail Connection | ENV variables |
128| :----: | --- |
129| SMTP | SMTP_PORT, SMTP_HOST, MAIL_USERNAME, MAIL_PASSWORD, MAIL_SSL |
130| SparkPost | SPARKPOST_API_KEY |
131| Mailgun | MAILGUN_DOMAIN, MAILGUN_API_REGION, MAILGUN_API_KEY |
132| Ethereal | A disposable account is created automatically if you choose this option. |
133
134## NGINX config block
135To access Ferdi-server from outside of your home network on a subdomain use this server block:
136
137```
138# Ferdi-server
139server {
140 listen 443 ssl http2;
141 server_name ferdi.my.website;
142
143 # all ssl related config moved to ssl.conf
144 include /config/nginx/ssl.conf;
145
146 location / {
147 proxy_pass http://<Ferdi-IP>:3333;
148 proxy_set_header X-Real-IP $remote_addr;
149 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
150 proxy_set_header Host $host;
151 proxy_set_header X-Forwarded-Proto $scheme;
152 }
153}
154```
155
156## Importing your Franz account
157Ferdi-server allows you to import your full Franz account, including all its settings.
158
159To import your Franz account, open `http://[YOUR FERDI-SERVER]/import` in your browser and login using your Franz account details. Ferdi-server will create a new user with the same credentials and copy your Franz settings, services and workspaces.
160
161## Transferring user data
162Please refer to <https://github.com/getferdi/ferdi/wiki/Transferring-data-between-servers>
163
164## Creating and using custom recipes
165Ferdi-server allows to extends the Franz recipe catalogue with custom Ferdi recipes.
166
167For documentation on how to create a recipe, please visit [the official guide by Franz](https://github.com/meetfranz/plugins/blob/master/docs/integration.md).
168
169To add your recipe to Ferdi-server, open `http://[YOUR FERDI-SERVER]/new` in your browser. You can now define the following settings:
170- `Author`: Author who created the recipe
171- `Name`: Name for your new service. Can contain spaces and unicode characters
172- `Service ID`: Unique ID for this recipe. Does not contain spaces or special characters (e.g. `google-drive`)
173- `Link to PNG/SVG image`: Direct link to a 1024x1024 PNG image and SVG that is used as a logo inside the store. Please use jsDelivr when using a file uploaded to GitHub as raw.githubusercontent files won't load
174- `Recipe files`: Recipe files that you created using the [Franz recipe creation guide](https://github.com/meetfranz/plugins/blob/master/docs/integration.md). Please do *not* package your files beforehand - upload the raw files (you can drag and drop multiple files). ferdi-server will automatically package and store the recipe in the right format. Please also do not drag and drop or select the whole folder, select the individual files.
175
176### Listing custom recipes
177Inside Ferdi, searching for `ferdi:custom` will list all your custom recipes.
178
179## Support Info
180
181* Shell access while the container is running: `docker exec -it ferdi-server /bin/bash`
182* To monitor the logs of the container in realtime: `docker logs -f ferdi-server`
183
184## Updating Info
185
186Below are the instructions for updating the container to get the most recent version of Ferdi-server:
187
188### Via Docker Run/Create
189* Update the image: `docker pull getferdi/ferdi-server`
190* Stop the running container: `docker stop ferdi-server`
191* Delete the container: `docker rm ferdi-server`
192* Recreate a new container with the same docker create parameters as instructed above (if mapped correctly to a host folder, your `/config` folder and your ENV settings will be preserved)
193* Start the new container: `docker start ferdi-server`
194* You can also remove the old dangling images: `docker image prune`
195
196### Via Docker Compose
197* Update all images: `docker-compose pull`
198 * or update a single image: `docker-compose pull ferdi-server`
199* Let compose update all containers as necessary: `docker-compose up -d`
200 * or update a single container: `docker-compose up -d ferdi-server`
201* You can also remove the old dangling images: `docker image prune`
202
203## Building locally
204
205If you want to make local modifications to this image for development purposes or just to customize the logic:
206```
207git clone https://github.com/getferdi/server-docker.git
208cd server-docker
209docker build \
210 --no-cache \
211 --pull \
212 -t getferdi/ferdi-server:latest .
213```
214
215## Versions
216
217* **05.02.21:** - Repository moved to ferdi-server repository
218* **19.01.21:** - Updated Mail SSL and DB SLL settings
219* **20.09.20:** - Updated SMTP Mailer settings for password reset.
220* **21.06.20:** - Rebase to Alpine 3.11 and added Mailer settings.
221* **25.09.19:** - Initial Release.
222
223## License
224Ferdi-server-docker and ferdi-server are licensed under the MIT License.
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
new file mode 100644
index 0000000..7bf1b8c
--- /dev/null
+++ b/docker/docker-compose.yml
@@ -0,0 +1,37 @@
1version: "2"
2services:
3 ferdi-server:
4 image: getferdi/ferdi-server
5 container_name: ferdi-server
6 environment:
7 - NODE_ENV=development
8 - EXTERNAL_DOMAIN=localhost
9 - DB_CONNECTION=sqlite
10 - DB_HOST=127.0.0.1
11 - DB_PORT=3306
12 - DB_USER=root
13 - DB_PASSWORD=password
14 - DB_DATABASE=adonis
15 - DB_SSL=false
16 - MAIL_CONNECTION=smtp
17 - SMPT_HOST=127.0.0.1
18 - SMTP_PORT=2525
19 - MAIL_SSL=false
20 - MAIL_USERNAME=username
21 - MAIL_PASSWORD=password
22 - MAIL_SENDER=noreply@getferdi.com
23 - IS_CREATION_ENABLED=true
24 - IS_DASHBOARD_ENABLED=true
25 - IS_REGISTRATION_ENABLED=true
26 - CONNECT_WITH_FRANZ=false
27 volumes:
28 - ferdi-config-vol:/config
29 - ferdi-database-vol:/app/database
30 - ferdi-recipes-vol:/app/recipes
31 ports:
32 - 3333:80
33 restart: unless-stopped
34volumes:
35 ferdi-config-vol:
36 ferdi-database-vol:
37 ferdi-recipes-vol: \ No newline at end of file
diff --git a/docker/logo.png b/docker/logo.png
new file mode 100644
index 0000000..587e0b8
--- /dev/null
+++ b/docker/logo.png
Binary files differ
diff --git a/docker/root/defaults/.env.example b/docker/root/defaults/.env.example
new file mode 100755
index 0000000..2ed73dc
--- /dev/null
+++ b/docker/root/defaults/.env.example
@@ -0,0 +1,35 @@
1HOST=0.0.0.0
2PORT=80
3NODE_ENV=development
4
5APP_NAME=AdonisJs
6APP_URL=http://${EXTERNAL_DOMAIN}
7EXTERNAL_DOMAIN=ferdi.domain.tld
8
9CACHE_VIEWS=false
10
11APP_KEY=appkey
12
13DB_CONNECTION=sqlite
14DB_HOST=127.0.0.1
15DB_PORT=3306
16DB_USER=root
17DB_PASSWORD=password
18DB_DATABASE=adonis
19
20DB_SSL=false
21
22HASH_DRIVER=bcrypt
23
24IS_CREATION_ENABLED=true
25IS_DASHBOARD_ENABLED=true
26IS_REGISTRATION_ENABLED=true
27CONNECT_WITH_FRANZ=true
28
29MAIL_CONNECTION=smtp
30SMTP_PORT=2525
31SMTP_HOST=127.0.0.1
32MAIL_USERNAME=username
33MAIL_PASSWORD=password
34MAIL_SENDER=noreply@getferdi.com
35MAIL_SSL=false
diff --git a/docker/root/etc/cont-init.d/10-adduser b/docker/root/etc/cont-init.d/10-adduser
new file mode 100755
index 0000000..8ba1aea
--- /dev/null
+++ b/docker/root/etc/cont-init.d/10-adduser
@@ -0,0 +1,32 @@
1#!/usr/bin/with-contenv bash
2
3PUID=${PUID:-911}
4PGID=${PGID:-911}
5
6groupmod -o -g "$PGID" abc
7usermod -o -u "$PUID" abc
8
9echo '
10-------------------------------------
11 ____ ___
12 / __/__ _______/ (_)
13 / _// -_) __/ _ / /
14 _/_/ \__/_/ \_,_/_/
15 / __/__ _____ _____ ____
16 _\ \/ -_) __/ |/ / -_) __/
17 /___/\__/_/ |___/\__/_/
18
19Brought to you by getferdi.com
20Support our Open Collective at:
21https://opencollective.com/getferdi/
22-------------------------------------
23GID/UID
24-------------------------------------'
25echo "
26User uid: $(id -u abc)
27User gid: $(id -g abc)
28-------------------------------------
29"
30chown abc:abc /app
31chown abc:abc /config
32chown abc:abc /defaults \ No newline at end of file
diff --git a/docker/root/etc/cont-init.d/50-config b/docker/root/etc/cont-init.d/50-config
new file mode 100755
index 0000000..1c0caed
--- /dev/null
+++ b/docker/root/etc/cont-init.d/50-config
@@ -0,0 +1,184 @@
1#!/usr/bin/with-contenv bash
2
3# Display variables for troubleshooting
4echo " "
5echo "-------------------------------------"
6echo " "
7echo -e "Variables set:\\n\
8NODE_ENV=${NODE_ENV}\\n\
9EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}\\n\
10DB_CONNECTION=${DB_CONNECTION}\\n\
11DB_HOST=${DB_HOST}\\n\
12DB_PORT=${DB_PORT}\\n\
13DB_USER=${DB_USER}\\n\
14DB_PASSWORD=${DB_PASSWORD}\\n\
15DB_DATABASE=${DB_DATABASE}\\n\
16DB_SSL=${DB_SSL}\\n\
17IS_CREATION_ENABLED=${IS_CREATION_ENABLED}\\n\
18IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}\\n\
19IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}\\n\
20CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}\\n\
21MAIL_CONNECTION=${MAIL_CONNECTION}\\n\
22SMTP_PORT=${SMTP_PORT}\\n\
23SMTP_HOST=${SMTP_HOST}\\n\
24MAIL_SSL=${MAIL_SSL}\\n\
25MAIL_USERNAME=${MAIL_USERNAME}\\n\
26MAIL_PASSWORD=${MAIL_PASSWORD}\\n\
27MAIL_SENDER=${MAIL_SENDER}\\n"
28
29# Echo init finish for test runs
30if [ -n "${TEST_RUN}" ]; then
31 echo " "
32 echo '**** [services.d] done ****'
33fi
34
35# install ferdi-server if necessary
36[[ -f /ferdi/ferdi.tar.gz ]] && \
37 echo "**** Installing Ferdi-server ****" && \
38 tar xf \
39 /ferdi/ferdi.tar.gz -C \
40 /app --strip-components=1 && \
41 rm -rf \
42 /ferdi && \
43 chown -R abc:abc /app
44
45# set ferdi-server status
46echo " "
47echo "**** Checking Ferdi-server settings ****"
48if [ -f /config/config.txt ]; then
49 [[ "${NODE_ENV}" ]] && sed -i "s/NODE_ENV=.*/NODE_ENV=${NODE_ENV}/g" /config/config.txt
50 [[ "${EXTERNAL_DOMAIN}" ]] && sed -i "s/EXTERNAL_DOMAIN=.*/EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}/g" /config/config.txt
51 [[ "${IS_CREATION_ENABLED}" ]] && sed -i "s/IS_CREATION_ENABLED=.*/IS_CREATION_ENABLED=${IS_CREATION_ENABLED}/g" /config/config.txt
52 [[ "${IS_DASHBOARD_ENABLED}" ]] && sed -i "s/IS_DASHBOARD_ENABLED=.*/IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}/g" /config/config.txt
53 [[ "${IS_REGISTRATION_ENABLED}" ]] && sed -i "s/IS_REGISTRATION_ENABLED=.*/IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}/g" /config/config.txt
54 [[ "${CONNECT_WITH_FRANZ}" ]] && sed -i "s/CONNECT_WITH_FRANZ=.*/CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}/g" /config/config.txt
55 [[ "${DB_CONNECTION}" ]] && sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=${DB_CONNECTION}/g" /config/config.txt
56 [[ "${DB_HOST}" ]] && sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/config.txt
57 [[ "${DB_PORT}" ]] && sed -i "s/DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/config.txt
58 [[ "${DB_DATABASE}" ]] && sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/config.txt
59 [[ "${DB_USER}" ]] && sed -i "s/DB_USER=.*/DB_USER=${DB_USER}/g" /config/config.txt
60 [[ "${DB_PASSWORD}" ]] && sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD}/g" /config/config.txt
61 [[ "${DB_SSL}" ]] && sed -i "s/DB_SSL=.*/DB_SSL=${DB_SSL}/g" /config/config.txt
62 [[ "${MAIL_CONNECTION}" ]] && sed -i "s/MAIL_CONNECTION=.*/MAIL_CONNECTION=${MAIL_CONNECTION}/g" /config/config.txt
63 [[ "${SMTP_HOST}" ]] && sed -i "s/SMTP_HOST=.*/SMTP_HOST=${SMTP_HOST}/g" /config/config.txt
64 [[ "${SMTP_PORT}" ]] && sed -i "s/SMTP_PORT=.*/SMTP_PORT=${SMTP_PORT}/g" /config/config.txt
65 [[ "${MAIL_SSL}" ]] && sed -i "s/MAIL_SSL=.*/MAIL_SSL=${MAIL_SSL}/g" /config/config.txt
66 [[ "${MAIL_USERNAME}" ]] && sed -i "s/MAIL_USERNAME=.*/MAIL_USERNAME=${MAIL_USERNAME}/g" /config/config.txt
67 [[ "${MAIL_PASSWORD}" ]] && sed -i "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=${MAIL_PASSWORD}/g" /config/config.txt
68 [[ "${MMAIL_SENDER}" ]] && sed -i "s/MAIL_SENDER=.*/MAIL_SENDER=${MAIL_SENDER}/g" /config/config.txt
69 rm /config/.env
70 cp /config/config.txt /config/.env
71elif [ ! -f /config/config.txt ]; then
72 echo " "
73 echo "**** Generating .env file ****"
74 cp /defaults/.env.example /config/.env
75 [[ "${NODE_ENV}" ]] && sed -i "s/NODE_ENV=.*/NODE_ENV=${NODE_ENV}/g" /config/.env
76 [[ "${EXTERNAL_DOMAIN}" ]] && sed -i "s/EXTERNAL_DOMAIN=.*/EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}/g" /config/.env
77 [[ "${IS_CREATION_ENABLED}" ]] && sed -i "s/IS_CREATION_ENABLED=.*/IS_CREATION_ENABLED=${IS_CREATION_ENABLED}/g" /config/.env
78 [[ "${IS_DASHBOARD_ENABLED}" ]] && sed -i "s/IS_DASHBOARD_ENABLED=.*/IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}/g" /config/.env
79 [[ "${IS_REGISTRATION_ENABLED}" ]] && sed -i "s/IS_REGISTRATION_ENABLED=.*/IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}/g" /config/.env
80 [[ "${CONNECT_WITH_FRANZ}" ]] && sed -i "s/CONNECT_WITH_FRANZ=.*/CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}/g" /config/.env
81 [[ "${DB_CONNECTION}" ]] && sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=${DB_CONNECTION}/g" /config/.env
82 [[ "${DB_HOST}" ]] && sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/.env
83 [[ "${DB_PORT}" ]] && sed -i "s/DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/.env
84 [[ "${DB_DATABASE}" ]] && sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/.env
85 [[ "${DB_USER}" ]] && sed -i "s/DB_USER=.*/DB_USER=${DB_USER}/g" /config/.env
86 [[ "${DB_PASSWORD}" ]] && sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD}/g" /config/.env
87 [[ "${DB_SSL}" ]] && sed -i "s/DB_SSL=.*/DB_SSL=${DB_SSL}/g" /config/.env
88 [[ "${MAIL_CONNECTION}" ]] && sed -i "s/MAIL_CONNECTION=.*/MAIL_CONNECTION=${MAIL_CONNECTION}/g" /config/.env
89 [[ "${SMTP_HOST}" ]] && sed -i "s/SMTP_HOST=.*/SMTP_HOST=${SMTP_HOST}/g" /config/.env
90 [[ "${SMTP_PORT}" ]] && sed -i "s/SMTP_PORT=.*/SMTP_PORT=${SMTP_PORT}/g" /config/.env
91 [[ "${MAIL_SSL}" ]] && sed -i "s/MAIL_SSL=.*/MAIL_SSL=${MAIL_SSL}/g" /config/.env
92 [[ "${MAIL_USERNAME}" ]] && sed -i "s/MAIL_USERNAME=.*/MAIL_USERNAME=${MAIL_USERNAME}/g" /config/.env
93 [[ "${MAIL_PASSWORD}" ]] && sed -i "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=${MAIL_PASSWORD}/g" /config/.env
94 [[ "${MMAIL_SENDER}" ]] && sed -i "s/MAIL_SENDER=.*/MAIL_SENDER=${MAIL_SENDER}/g" /config/.env
95 cp /config/.env /config/config.txt
96fi
97
98# update .env
99if [ -f /app/.env ]; then
100 rm /app/.env
101 ln -s /config/.env /app/.env
102elif [ ! -f /app/.env ]; then
103 ln -s /config/.env /app/.env
104fi
105
106# install adonisjs cli
107echo " "
108echo "**** Installing AdonisJS and deps ****"
109cd /app
110echo " "
111npm config set unsafe-perm true
112npm i -g @adonisjs/cli
113
114# install adonisjs dependencies
115npm install
116
117# make custom recipe dir
118if [ ! -f /app/recipes/dev ]; then
119mkdir -p /app/recipes/dev
120fi
121
122# setting the database helper
123if [ "${DB_CONNECTION}" = "sqlite" ]; then
124 echo " "
125 echo "**** DB helper loaded ****"
126 else npm i ${DB_CONNECTION}
127 echo " "
128 echo "**** DB Helper loaded ****"
129fi
130
131# check for the database endpoint for 30 seconds
132echo " "
133echo "**** Checking DB endpoint ****"
134source .env
135END=$((SECONDS+30))
136while [ ${SECONDS} -lt ${END} ] && [ "${DB_HOST} ${DB_PORT}" ];
137 do
138 /usr/bin/nc -z ${DB_HOST} ${DB_PORT} && \
139 if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} ${DB_PORT})" ];
140 then
141 [ ! -z "${RUN}" ] && break
142 RUN="RAN"
143 # we sleep here again due to first run init on DB containers
144 [ ! -f /dbwait.lock ] && sleep 5
145 else
146 sleep 1
147 fi
148 sleep 1
149done
150
151# source the .env file
152source .env
153
154# database migration
155echo " "
156echo "**** Run DB migration ****"
157adonis migration:run --force
158
159# Create APP key if needed
160if [ ! -f "/config/FERDI_APP_KEY.txt" ];
161 then
162 echo " "
163 echo "**** Generating Ferdi-server app key for first run ****"
164 adonis key:generate
165 source .env
166 echo $APP_KEY > /config/FERDI_APP_KEY.txt
167 echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****"
168 sed -i "s/APP_KEY=/APP_KEY=$APP_KEY/g" /config/config.txt
169elif [ -f "/config/FERDI_APP_KEY.txt" ];
170 then
171 echo " "
172 echo "**** App Key found ****"
173 APP_KEY=$(cat /config/FERDI_APP_KEY.txt)
174 sed -i "s/APP_KEY=.*/APP_KEY=$APP_KEY/g" /config/config.txt
175 echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****"
176fi
177
178# set permissions
179chown -R abc:abc \
180 /config \
181 /app
182
183# set lockfile to avoid DB waits for this specific container
184touch /dbwait.lock
diff --git a/docker/root/etc/services.d/ferdi-server/run b/docker/root/etc/services.d/ferdi-server/run
new file mode 100755
index 0000000..cf1568c
--- /dev/null
+++ b/docker/root/etc/services.d/ferdi-server/run
@@ -0,0 +1,10 @@
1#!/usr/bin/with-contenv bash
2
3cd /app
4
5setcap 'cap_net_bind_service=+ep' `which node`
6
7# start server
8echo " "
9echo "**** Starting Ferdi-server ****"
10exec s6-setuidgid abc adonis serve --dev \ No newline at end of file