Skip to content

Commit

Permalink
Added dockerfile, fixed firebase depndencies
Browse files Browse the repository at this point in the history
  • Loading branch information
srgtuszy committed Oct 22, 2024
1 parent 94b5464 commit e57ea3a
Show file tree
Hide file tree
Showing 8 changed files with 537 additions and 665 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ app.*.map.json

# Firebase
public/

# Env files
.env.electricity-assistant-fb2f7
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM --platform=linux/amd64 dart:stable AS build

WORKDIR /app

# Install necessary dependencies
RUN apt-get update && apt-get install -y curl git unzip xz-utils zip libglu1-mesa

# Download and install Flutter SDK
RUN curl -L https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.24.3-stable.tar.xz | tar xJ
ENV PATH="/app/flutter/bin:${PATH}"

# Copy the Flutter project files to the container
COPY . .

# Enable Flutter web
RUN git config --global --add safe.directory /app/flutter
RUN flutter upgrade
RUN flutter config --enable-web

# Get Flutter packages
RUN flutter pub get

# Build the web release version
RUN flutter build web --release

# Stage 2: Serve the app with Nginx
FROM nginx:alpine

# Copy the built app from the previous stage
COPY --from=build /app/build/web /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Start Nginx server
CMD ["nginx", "-g", "daemon off;"]
17 changes: 11 additions & 6 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const { onCall } = require("firebase-functions/v2/https");
admin.initializeApp();
const { defineSecret } = require('firebase-functions/params');
const { onInit } = require('firebase-functions/v2/core');
const { GoogleGenerativeAI } = require("@google/generative-ai");
const geminiKey = defineSecret('GEMINI_API_KEY');

admin.initializeApp();
const db = admin.firestore();
const { GoogleGenerativeAI } = require("@google/generative-ai");
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

let genAI, model;
onInit(() => {
genAI = new GoogleGenerativeAI(geminiKey.value());
model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
});

exports.triggerGenerateTips = onCall({cors: true}, async (req, res) => {
console.log("Generating tips");
console.log(await db.collection("electricity").get());
const measurements = await fetchMeasurements();
console.log(`Fetched ${measurements.length} measurements`);
const tips = await generateTips(measurements);
Expand Down
Loading

0 comments on commit e57ea3a

Please sign in to comment.