Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker v1 #7

Merged
merged 10 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand All @@ -24,8 +25,28 @@ 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
RUN mv /bot/index.php /var/www/html/
Expand Down
15 changes: 15 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 17 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@
$data = [];
$counter = 0;

#request for each json file
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://'.$_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
'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.'',
];
}

#print response to browser
echo json_encode($data);
?>
Loading