From 2f8a2deef62b44816adfb66fe212330252ca93bd Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 26 Jan 2024 21:20:05 +0100 Subject: [PATCH 1/9] Create Dockerfile Kleinere Tests mit Docker --- Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2702e04 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:16.20.2 + +WORKDIR /bot +COPY /bot ./ + +RUN npm install +RUN mkdir /bot/exports + +WORKDIR /bot +COPY /bot ./ + +RUN npm run deploy +CMD npm run start \ No newline at end of file From 988479027838d1663fbfe6c7afd8405536cc347f Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 11 Feb 2024 19:53:12 +0100 Subject: [PATCH 2/9] Update Dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docker file wurde angepasst und lädt nun direkt aus dem GitHub Repo alle notwendigen Daten herunter. --- Dockerfile | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2702e04..5ec7daa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,25 @@ +# First stage: Clone the repository +FROM bitnami/git as clone_stage +RUN git clone https://github.com/ifheroes/infinityheroes-bot.git /bot + +# Second stage: Build and run the Node application FROM node:16.20.2 +# Create the working directory WORKDIR /bot -COPY /bot ./ +# Copy the cloned repository from the first stage +COPY --from=clone_stage /bot ./ + +COPY config.json /bot/src/data + +# Install dependencies RUN npm install -RUN mkdir /bot/exports -WORKDIR /bot -COPY /bot ./ +RUN mkdir /bot/exports +# Deploy the application (if this step is needed) RUN npm run deploy -CMD npm run start \ No newline at end of file + +# Command to run the application +CMD npm run start From 7d2c6f006a97ff6acb7f7a6fc9eb5c792f5beca6 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 19 Feb 2024 19:17:32 +0100 Subject: [PATCH 3/9] Enhanced API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zu dem Image wurde ein Webinterface hinzugefügt welches über /exports/ erreicht wird kann als GET API genutzt werden. --- Dockerfile | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5ec7daa..a20452a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,17 @@ RUN git clone https://github.com/ifheroes/infinityheroes-bot.git /bot # Second stage: Build and run the Node application FROM node:16.20.2 +RUN apt-get update && apt-get install -y apache2 && \ + # Apache Konfiguration anpassen + a2enmod rewrite && \ + sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf && \ + service apache2 restart && \ + # Aufräumen + apt-get clean && rm -rf /var/lib/apt/lists/* + + + + # Create the working directory WORKDIR /bot @@ -16,10 +27,13 @@ COPY config.json /bot/src/data # Install dependencies RUN npm install -RUN mkdir /bot/exports +RUN mkdir /bot/exports && \ + ln -s /bot/exports /var/www/html/exports # Deploy the application (if this step is needed) RUN npm run deploy -# Command to run the application -CMD npm run start +# Apache im Hintergrund starten und Node.js-Anwendung als primären Prozess ausführen +CMD service apache2 start && npm run start + + From 6638779fb54d691c5700ef1c724aeb939a6ac8db Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 22 May 2024 21:08:05 +0200 Subject: [PATCH 4/9] Added API Webservice in Docker + Developers can now access the API inside the Docker container + Docker container now expoesed to 8080 --- Dockerfile | 35 +++++++++++++++++++++++------------ index.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 index.php diff --git a/Dockerfile b/Dockerfile index a20452a..458d3be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,19 +2,21 @@ FROM bitnami/git as clone_stage RUN git clone https://github.com/ifheroes/infinityheroes-bot.git /bot -# Second stage: Build and run the Node application +# Second stage: Build and run the Node application with Apache and PHP FROM node:16.20.2 -RUN apt-get update && apt-get install -y apache2 && \ - # Apache Konfiguration anpassen +# Install Apache, PHP, and other dependencies +RUN apt-get update && apt-get install -y \ + apache2 \ + php \ + libapache2-mod-php && \ a2enmod rewrite && \ - sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf && \ - service apache2 restart && \ - # Aufräumen apt-get clean && rm -rf /var/lib/apt/lists/* - - +# Configure Apache +RUN sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf && \ + sed -i 's/Listen 80/Listen 8080/' /etc/apache2/ports.conf && \ + sed -i 's///' /etc/apache2/sites-available/000-default.conf # Create the working directory WORKDIR /bot @@ -22,18 +24,27 @@ WORKDIR /bot # Copy the cloned repository from the first stage COPY --from=clone_stage /bot ./ +# Copy the configuration file COPY config.json /bot/src/data -# Install dependencies +# Copy the index.php for the API to the webserver directory +COPY index.php /var/www/html/ + +# Remove the default index.html file if it exists +RUN rm -f /var/www/html/index.html + +# Install Node.js dependencies RUN npm install +# Create the exports directory and link it to the webserver RUN mkdir /bot/exports && \ ln -s /bot/exports /var/www/html/exports # Deploy the application (if this step is needed) RUN npm run deploy -# Apache im Hintergrund starten und Node.js-Anwendung als primären Prozess ausführen -CMD service apache2 start && npm run start - +# Expose port 8080 for Apache +EXPOSE 8080 +# Start Apache in the background and run the Node.js application as the primary process +CMD service apache2 start && npm run start diff --git a/index.php b/index.php new file mode 100644 index 0000000..89caa4e --- /dev/null +++ b/index.php @@ -0,0 +1,32 @@ +''.$counter.'', # print out counted number + 'path'=>'https://'.$_SERVER['HTTP_HOST'].'/exports/' . $file, # path to file with current url + 'date'=>date("d-m-Y", filectime($directory . '/' . $file)), # get creation date from json file + 'file_id'=>date("dmYhis", filectime($directory . '/' . $file)), # create an file id out of the date and time + ]; +} + +echo json_encode($data); +?> \ No newline at end of file From aebe2a8289ce775217ff7068008111a4d2d64114 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 22 May 2024 21:17:37 +0200 Subject: [PATCH 5/9] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 425bc36..2e67ef7 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,16 @@ Dieser Bot erlaubt die Synchronisation zwischen der Webseite von ifheroes.de und Jede JSON-Datei existiert nur einmal, es kann keinen Dateinamen zwei mal geben, denn: Der Dateiname besteht aus `Monat-Tag-Jahr_Stunde-Minute-Sekunde.json` (`MM-DD-YYYY_HH-mm-ss`), Bsp. `02.18.3912_11:27:27.json` + +## Informationen zur Verwendung mit Docker + +1.Zunächst muss das Repo von github heruntergeladen werden +2. Im gleichen file die dem Dockerfile muss nun die config.json abgelegt werden. +3. Aktuell muss noch ein Image erstellt werden mit dem Befehl: +```` +docker build --pull --rm -f "Dockerfile" -t infinityheroesbot:latest "." +```` +4. Nun kann das image mit ausgeführt werden mit +```` +docker run -d -p 8080:8080 infinityheroesbot:latest +```` From 4a3b01aaba684ff7cd2e022607bb1c91d21feb15 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 22 May 2024 21:18:19 +0200 Subject: [PATCH 6/9] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e67ef7..5fad18a 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,10 @@ Der Dateiname besteht aus `Monat-Tag-Jahr_Stunde-Minute-Sekunde.json` (`MM-DD-YY ## Informationen zur Verwendung mit Docker -1.Zunächst muss das Repo von github heruntergeladen werden +1. Zunächst muss das Repo von github heruntergeladen werden + 2. Im gleichen file die dem Dockerfile muss nun die config.json abgelegt werden. + 3. Aktuell muss noch ein Image erstellt werden mit dem Befehl: ```` docker build --pull --rm -f "Dockerfile" -t infinityheroesbot:latest "." From 89e0cd5e0fbdba6f10cc4470df963b2a37b7b732 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 24 May 2024 12:57:40 +0200 Subject: [PATCH 7/9] Added docker compose --- Dockerfile | 31 ++++++++++++++++++++++++++----- compose.yml | 15 +++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 compose.yml diff --git a/Dockerfile b/Dockerfile index 458d3be..cc884fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,11 +5,12 @@ RUN git clone https://github.com/ifheroes/infinityheroes-bot.git /bot # Second stage: Build and run the Node application with Apache and PHP FROM node:16.20.2 -# Install Apache, PHP, and other dependencies +# Install Apache, PHP, jq, and other dependencies RUN apt-get update && apt-get install -y \ apache2 \ php \ - libapache2-mod-php && \ + libapache2-mod-php \ + jq && \ a2enmod rewrite && \ apt-get clean && rm -rf /var/lib/apt/lists/* @@ -24,11 +25,31 @@ WORKDIR /bot # Copy the cloned repository from the first stage COPY --from=clone_stage /bot ./ -# Copy the configuration file -COPY config.json /bot/src/data +# Copy the configuration file template +RUN cp /bot/src/data/config.json.pub /bot/src/data/config.json + +# Add environment variables from compose file +ARG token +ARG clientId +ARG guildId +ARG roleId +ARG color + +RUN echo "Token: ${token}" + + +# Update the configuration file with environment variables +RUN jq --arg token "$token" \ + --arg clientId "$clientId" \ + --arg guildId "$guildId" \ + --arg roleId "$roleId" \ + --arg color "$color" \ + '.token=$token | .clientId=$clientId | .guildId=$guildId | .roleId=$roleId | .color=$color' \ + /bot/src/data/config.json > /bot/src/data/config.json.tmp && \ + mv /bot/src/data/config.json.tmp /bot/src/data/config.json # Copy the index.php for the API to the webserver directory -COPY index.php /var/www/html/ +RUN mv /bot/index.php /var/www/html/ # Remove the default index.html file if it exists RUN rm -f /var/www/html/index.html diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..6e2d31a --- /dev/null +++ b/compose.yml @@ -0,0 +1,15 @@ +services: + ifheroesbot: + build: + args: + - token= + - clientId= + - guildId= + - roleId= + - color= + - api_url=https://api.ifheroes.de/v1/news + ports: + - "8080:8080" + + volumes: + - ./exports:/bot/exports From 726a961e1041259c3a7e0b95289d8b6c0fec91cd Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 24 May 2024 13:14:25 +0200 Subject: [PATCH 8/9] Update index.php --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 89caa4e..7d33202 100644 --- a/index.php +++ b/index.php @@ -22,7 +22,7 @@ $counter++; $data[] = [ 'number'=>''.$counter.'', # print out counted number - 'path'=>'https://'.$_SERVER['HTTP_HOST'].'/exports/' . $file, # path to file with current url + 'path'=>'https://api.ifheroes.de/v1/news/exports/' . $file, # path to file with current url 'date'=>date("d-m-Y", filectime($directory . '/' . $file)), # get creation date from json file 'file_id'=>date("dmYhis", filectime($directory . '/' . $file)), # create an file id out of the date and time ]; From 9bac7f4e8eacc67d14a2ded76ad4ffbc33162bd5 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 25 May 2024 09:49:01 +0200 Subject: [PATCH 9/9] Update index.php --- index.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 7d33202..91b7ec9 100644 --- a/index.php +++ b/index.php @@ -19,12 +19,26 @@ $counter = 0; foreach ($jsonFiles as $file) { + + # structure as api + + # decode the json file + $fileData = file_get_contents($directory . $file); + $obj = json_decode($fileData); + + $title = $obj->title; + $text = $obj->text; + $image = $obj->image; + $counter++; $data[] = [ 'number'=>''.$counter.'', # print out counted number - 'path'=>'https://api.ifheroes.de/v1/news/exports/' . $file, # path to file with current url - 'date'=>date("d-m-Y", filectime($directory . '/' . $file)), # get creation date from json file - 'file_id'=>date("dmYhis", filectime($directory . '/' . $file)), # create an file id out of the date and time + 'path'=> 'https://api.ifheroes.de/v1/news/exports/' . $file, # path to file with current url + 'date'=> date("d-m-Y", filectime($directory . '/' . $file)), # get creation date from json file + 'file_id'=> date("dmYhis", filectime($directory . '/' . $file)), # create an file id out of the date and time + 'title'=>''.$title.'', + 'text'=>''.$text.'', + 'image'=>''.$image.'', ]; }