-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Dockerfile Kleinere Tests mit Docker * Update Dockerfile Docker file wurde angepasst und lädt nun direkt aus dem GitHub Repo alle notwendigen Daten herunter. * Enhanced API Zu dem Image wurde ein Webinterface hinzugefügt welches über <url>/exports/ erreicht wird kann als GET API genutzt werden. * Added API Webservice in Docker + Developers can now access the API inside the Docker container + Docker container now expoesed to 8080 * Update README.md * Update README.md
- Loading branch information
1 parent
1c4fbbb
commit 0ce97f8
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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 with Apache and PHP | ||
FROM node:16.20.2 | ||
|
||
# Install Apache, PHP, and other dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
apache2 \ | ||
php \ | ||
libapache2-mod-php && \ | ||
a2enmod rewrite && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
||
# Configure Apache | ||
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf && \ | ||
sed -i 's/Listen 80/Listen 8080/' /etc/apache2/ports.conf && \ | ||
sed -i 's/<VirtualHost \*:80>/<VirtualHost \*:8080>/' /etc/apache2/sites-available/000-default.conf | ||
|
||
# Create the working directory | ||
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 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 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
#set the header for json response | ||
header('Content-Type: application/json'); | ||
|
||
#scan the /exports folder | ||
$directory = "exports/"; | ||
$files = scandir($directory, SCANDIR_SORT_DESCENDING); | ||
|
||
# exclude subdirs from the scan | ||
$jsonFiles = array_filter($files, function($file) use ($directory) { | ||
return is_file($directory . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) === 'json'; | ||
}); | ||
|
||
# print out the json files found in export folder | ||
header('Content-Type: application/json'); | ||
|
||
$data = []; | ||
$counter = 0; | ||
|
||
foreach ($jsonFiles as $file) { | ||
$counter++; | ||
$data[] = [ | ||
'number'=>''.$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); | ||
?> |