Skip to content

Commit

Permalink
Merge pull request #7 from ifheroes/docker-v1
Browse files Browse the repository at this point in the history
Docker v1
  • Loading branch information
chrischivlog authored May 25, 2024
2 parents 53e36b7 + fbbff4a commit ad5ce70
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
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);
?>

0 comments on commit ad5ce70

Please sign in to comment.