Skip to content

Commit d049422

Browse files
FF-134 reverse proxy (#6)
* rp is basiclly working * proxy working, rest is weird * cleanup is neccesarry * fixed weird behavouir of rest * refactoring * changed ngix config till i turn insane * made the docker running check consistent. * fixed small typo * made install.sh output consistent. * FF-138 Created nginx workflow Co-authored-by: open-schnick <jonathan.burst@gmx.de>
1 parent a36ffcb commit d049422

12 files changed

Lines changed: 108 additions & 46 deletions

File tree

.github/workflows/nginx_image.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build Nginx Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag for new Image'
8+
required: true
9+
default: 'v1.0.0'
10+
11+
jobs:
12+
Build_Image:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
name: Checkout Repo.
17+
uses: actions/checkout@v1
18+
-
19+
name: Login to DockerHub
20+
uses: docker/login-action@v1
21+
with:
22+
username: ${{ secrets.DOCKER_USER }}
23+
password: ${{ secrets.DOCKER_PW }}
24+
-
25+
name: Build and push Image
26+
run: |
27+
VERSION=${{ github.event.inputs.tag }}
28+
docker build -t filefighter/reverseproxy:$VERSION ReverseProxy/
29+
docker push filefighter/reverseproxy:$VERSION

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ You should see a login page. For the first setup you can use the credentials.
112112
To be sure everything is setup correctly click [here](http://localhost:80/health). If everything is green you are good to go.
113113
114114
### Configuration
115-
The script uses a [config.cfg](./config.cfg) file that stores information in `key=value` format.
115+
The script uses a [config.cfg](config.cfg) file that stores information in `key=value` format.
116116
Valid keys to configure how FileFighter behaves are listed here:
117117
118118
| Key | Possible Values | Default | Description |
@@ -125,7 +125,7 @@ Valid keys to configure how FileFighter behaves are listed here:
125125
| use_stable_versions | true / false | true | When set to true the latest stable versions will be used. When set to false always the latest (possible unstable) versions will be used. |
126126
127127
All of these keys use the [default values](./lib/config.cfg.defaults) if you don't overwrite those values.
128-
It is also possible to have an empty [config.cfg](./config.cfg) file as the default values will be used.
128+
It is also possible to have an empty [config.cfg](config.cfg) file as the default values will be used.
129129
If the `db_password` key is empty, a random password will be generated.
130130
131131
Be carefully as the developers of FileFighter won't take responsibility when you are using the application or configuration options wrong or in a not intended way.

ReverseProxy/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# dockerfile
2+
FROM nginx
3+
RUN rm /etc/nginx/conf.d/default.conf
4+
COPY nginx.conf /etc/nginx/nginx.conf
5+
EXPOSE 80
6+
CMD ["nginx", "-g", "daemon off;"]

ReverseProxy/nginx.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
worker_processes 1;
2+
3+
events { worker_connections 1024; }
4+
5+
http {
6+
7+
sendfile on;
8+
9+
server {
10+
listen 80;
11+
12+
proxy_set_header Host $host;
13+
proxy_set_header X-Real-IP $remote_addr;
14+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15+
proxy_set_header X-Forwarded-Host $server_name;
16+
17+
location /api {
18+
proxy_pass http://FileFighterREST:8080/;
19+
proxy_redirect off;
20+
}
21+
22+
location / {
23+
proxy_pass http://FileFighterFrontend:5000/;
24+
proxy_redirect off;
25+
}
26+
}
27+
}

config.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
rest_port=8080
2-
frontend_port=80
1+
app_port=80
32
db_user=root
43
db_name=filefighter
54
use_stable_versions=true

ffighter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ source lib/status.sh
1515
version="v1.3"
1616
date="08.11.20"
1717

18+
# Check if docker is running
19+
if ! docker info >/dev/null 2>&1; then
20+
echo "Docker is not running, install it first or retry."
21+
exit 1
22+
fi
23+
1824
if [ -z "$1" ]; then
1925
echoLogo $version $date "Show Usage"
2026
printUsage

lib/config.cfg.defaults

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# DO NOT CHANGE OR REMOVE THIS FILE!
22

33
# Services
4-
rest_port=8080
5-
frontend_port=80
4+
app_port=80
5+
66

77
# DB Settings
88
db_user=root

lib/install.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,33 @@ ffinstall() {
33
source lib/config.sh # load the config library functions
44
source lib/dockertags.sh # load docker functions.
55

6-
# Check if docker is running
7-
if ! docker info >/dev/null 2>&1; then
8-
echo "Docker is not running, install it first or retry."
9-
exit 1
10-
fi
11-
126
# setup variables
137
configFilePath=$(pwd)/config.cfg
148
restname="FileFighterREST"
159
frontendname="FileFighterFrontend"
1610
dbname="FileFighterDB"
1711
networkname="FileFighterNetwork"
12+
reverseproxyname="FileFighterReverseProxy"
1813

1914
# latest stable versions.
2015
frontendVersion="latest"
2116
restVersion="latest"
17+
proxyVersion="$(getTagsByName filefighter/reverseproxy | tail -1)"
18+
2219

2320
echo "Docker prerequisites matched. Docker instance running."
2421
echo "Reading in config file from: $configFilePath."
2522

2623
# Read in default keys.
27-
frontend_port="$(read $configFilePath frontend_port)"
28-
rest_port="$(read $configFilePath rest_port)"
24+
app_port="$(read $configFilePath app_port)"
2925
db_name="$(read $configFilePath db_name)"
3026
db_user="$(read $configFilePath db_user)"
3127
db_password="$(read $configFilePath db_password)"
3228
use_stable_versions="$(read $configFilePath use_stable_versions)"
3329

34-
if ! [[ $frontend_port ]]; then
35-
echo "Config for frontend_port not found, using defaults."
36-
frontend_port="$(read ./lib/config.cfg.defaults frontend_port)"
37-
fi
38-
39-
if ! [[ $rest_port ]]; then
40-
echo "Config for rest_port not found, using defaults."
41-
rest_port="$(read config.cfg.defaults rest_port)"
30+
if ! [[ $app_port ]]; then
31+
echo "Config for app_port not found, using defaults."
32+
app_port="$(read ./lib/config.cfg.defaults app_port)"
4233
fi
4334

4435
if ! [[ $db_name ]]; then
@@ -65,7 +56,7 @@ ffinstall() {
6556
if ! [[ $db_password ]]; then
6657
# Create new Password
6758
echo "Creating new random password for the database."
68-
db_password=$(wget -qO- "https://www.passwordrandom.com/query?command=password&scheme=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
59+
db_password=$(wget -qO- "https://www.passwordrandom.com/query?command=password&scheme=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
6960
write $configFilePath db_password $db_password
7061
fi
7162

@@ -85,7 +76,7 @@ ffinstall() {
8576
echo "Finished reading config. Building containers..."
8677

8778
# Check for already existing CONTAINERS.
88-
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]]; then
79+
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $reverseproxyname) ]]; then
8980
echo ""
9081
echo "A container with already exists with the name $restname or $frontendname or $dbname."
9182
echo "Maybe its the second time that you run this script. If not please remove these containers."
@@ -121,7 +112,7 @@ ffinstall() {
121112
-e DB_NAME=$db_name \
122113
-e DB_CONTAINER_NAME=$dbname \
123114
-e SPRING_PROFILES_ACTIVE="prod" \
124-
-p $rest_port:8080 \
115+
--expose 8080 \
125116
--network $networkname \
126117
--name $restname filefighter/rest:$restVersion >/dev/null 2>&1
127118

@@ -133,10 +124,20 @@ ffinstall() {
133124
echo "Downloading filefighter/frontend image."
134125
docker create \
135126
-e REST_PORT=$rest_port \
136-
-p $frontend_port:5000 \
127+
--network $networkname \
137128
--name $frontendname filefighter/frontend:$frontendVersion >/dev/null 2>&1
138129

139130
echo "Finished downloading."
131+
echo ""
132+
133+
# ReverseProxy
134+
echo "Creating ReverseProxy Container with tag: $proxyVersion"
135+
echo "Downloading filefighter/reverseproxy image."
136+
docker create \
137+
--network $networkname \
138+
-p $app_port:80 \
139+
--name=$reverseproxyname \
140+
filefighter/reverseproxy:$proxyVersion >/dev/null 2>&1
140141

141142
# DataHandler
142143

lib/remove.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ ffremove() {
33
restname="FileFighterREST"
44
frontendname="FileFighterFrontend"
55
dbname="FileFighterDB"
6+
reverseproxyname="FileFighterReverseProxy"
67

7-
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]]; then
8+
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $reverseproxyname) ]]; then
89
docker container stop $restname && docker container rm $restname
910
docker container stop $frontendname && docker container rm $frontendname
1011
docker container stop $dbname && docker container rm $dbname
12+
docker container stop $reverseproxyname && docker container rm $reverseproxyname
1113

1214
echo "Removed FileFighter Application. Install it again with 'ffighter install'."
1315
exit 0

lib/start.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
#!/usr/bin/env bash
22

33
ffstart() {
4-
# Check if docker is running
5-
if ! docker info >/dev/null 2>&1; then
6-
echo "Docker is not running, install it first or retry."
7-
exit 1
8-
fi
9-
104
source ./lib/config.sh # load the config library functions
11-
frontendport=$(read config.cfg frontend_port)
5+
appport=$(read config.cfg app_port)
126

137
# setup variables
148
restname="FileFighterREST"
159
frontendname="FileFighterFrontend"
1610
dbname="FileFighterDB"
11+
reverseproxyname="FileFighterReverseProxy"
1712

18-
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]]; then
13+
if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $reverseproxyname) ]]; then
1914
echo "Docker prerequisites matched. Docker instance running."
2015
echo "Starting services..."
2116

2217
docker start $restname
2318
docker start $frontendname
2419
docker start $dbname
20+
docker start $reverseproxyname
2521

2622
echo ""
2723
echo "Finished starting FileFighter services."
28-
echo "Frontend is running here: http://localhost:$frontendport."
24+
echo "Frontend is running here: http://localhost:$appport."
2925
echo "You can stop them again with 'ffighter stop'."
3026
echo ""
3127
exit 0

0 commit comments

Comments
 (0)