-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from xforman2/43-docker-image-for-bot
43 docker image for bot
- Loading branch information
Showing
8 changed files
with
255 additions
and
94 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,40 @@ | ||
# Stage 1: Build the application | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env | ||
WORKDIR /App | ||
|
||
# Copy the solution file and project files for Backend and SharedDependencies | ||
COPY HouseScout.sln ./ | ||
COPY SharedDependencies/SharedDependencies.csproj ./SharedDependencies/ | ||
COPY Backend/Backend.csproj ./Backend/ | ||
|
||
# Restore dependencies for Backend | ||
WORKDIR ./Backend | ||
RUN dotnet restore | ||
WORKDIR .. | ||
|
||
# Copy all the files for Backend and SharedDependencies | ||
COPY SharedDependencies/ ./SharedDependencies/ | ||
COPY Backend/ ./Backend/ | ||
|
||
# Build and publish the Backend project | ||
WORKDIR /App/Backend | ||
RUN dotnet publish -c Release -o out | ||
|
||
# Stage 2: Build the runtime image | ||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime | ||
|
||
# Install cron | ||
RUN apt-get update && apt-get install -y cron | ||
|
||
WORKDIR /App | ||
|
||
# Copy the build output from the previous stage | ||
COPY --from=build-env /App/Backend/out . | ||
|
||
# Copy the crontab file into the image and give exec rights | ||
COPY ./Backend/crontab /etc/cron.d/crontab | ||
RUN chmod 0644 /etc/cron.d/crontab | ||
|
||
# Apply the crontab | ||
RUN crontab /etc/cron.d/crontab | ||
CMD ["cron", "&&", "tail", "-f", "/var/log/cron.log"] |
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 @@ | ||
*/30 * * * * cd /App && ./Backend >> /var/log/cron.log 2>&1 |
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,30 @@ | ||
# Stage 1: Build the application | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env | ||
WORKDIR /App | ||
|
||
# Copy the solution file and project files for DiscordBot and SharedDependencies | ||
COPY HouseScout.sln ./ | ||
COPY SharedDependencies/SharedDependencies.csproj ./SharedDependencies/ | ||
COPY DiscordBot/DiscordBot.csproj ./DiscordBot/ | ||
|
||
# Restore dependencies for both DiscordBot and SharedDependencies | ||
WORKDIR ./DiscordBot | ||
RUN dotnet restore | ||
WORKDIR .. | ||
|
||
# Copy all the files for DiscordBot and SharedDependencies | ||
COPY SharedDependencies/ ./SharedDependencies/ | ||
COPY DiscordBot/ ./DiscordBot/ | ||
|
||
# Build and publish the DiscordBot project | ||
WORKDIR /App/DiscordBot | ||
RUN dotnet publish -c Release -o out | ||
|
||
# Stage 2: Build the runtime image | ||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime | ||
WORKDIR /App | ||
|
||
# Copy the build output from the previous stage | ||
COPY --from=build-env /App/DiscordBot/out . | ||
|
||
ENTRYPOINT ["dotnet", "DiscordBot.dll"] |
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 |
---|---|---|
@@ -1,39 +1,46 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using SharedDependencies.Model; | ||
using SharedDependencies.Services; | ||
|
||
namespace DiscordBot.Filters; | ||
|
||
public class DataFilter | ||
namespace DiscordBot.Filters | ||
{ | ||
private HouseScoutContext _context; | ||
|
||
public DataFilter(HouseScoutContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public List<Estate> SurfacePriceFilter( | ||
int priceMin, | ||
int priceMax, | ||
int surfaceMin, | ||
int surfaceMax, | ||
bool isNewUser | ||
) | ||
public class DataFilter | ||
{ | ||
var query = _context.Estates.AsQueryable(); | ||
private readonly IDbContextFactory<HouseScoutContext> _contextFactory; | ||
|
||
// we want to process only new data if user is not new, | ||
// and all data if user is new | ||
if (!isNewUser) | ||
public DataFilter(IDbContextFactory<HouseScoutContext> contextFactory) | ||
{ | ||
query = query.Where(e => e.IsNew); | ||
_contextFactory = contextFactory; | ||
} | ||
query = query.Where(e => | ||
e.Price >= priceMin | ||
&& e.Price <= priceMax | ||
&& e.Surface >= surfaceMin | ||
&& e.Surface <= surfaceMax | ||
); | ||
|
||
return query.ToList(); | ||
public List<Estate> SurfacePriceFilter( | ||
int priceMin, | ||
int priceMax, | ||
int surfaceMin, | ||
int surfaceMax, | ||
bool isNewUser | ||
) | ||
{ | ||
using (var context = _contextFactory.CreateDbContext()) | ||
{ | ||
var query = context.Estates.AsQueryable(); | ||
|
||
// Process only new data if the user is not new, | ||
// and all data if the user is new | ||
if (!isNewUser) | ||
{ | ||
query = query.Where(e => e.IsNew); | ||
} | ||
|
||
query = query.Where(e => | ||
e.Price >= priceMin | ||
&& e.Price <= priceMax | ||
&& e.Surface >= surfaceMin | ||
&& e.Surface <= surfaceMax | ||
); | ||
|
||
return query.ToList(); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.