diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 8226681..3506cb6 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,4 +1,4 @@ -name: Hello World Workflow +name: Build and Push Docker images on: workflow_dispatch: @@ -10,8 +10,57 @@ on: - master jobs: - say-hello: + build: runs-on: ubuntu-latest + steps: - - name: Say Hello World - run: echo "Hello, World!" + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build frontend Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: app.dockerfile + push: false + tags: ${{ secrets.DOCKER_USERNAME }}/perplexica-frontend:latest + + - name: Build backend Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: backend.dockerfile + push: false + tags: ${{ secrets.DOCKER_USERNAME }}/perplexica-backend:latest + + - name: Push frontend Docker image + if: github.event_name != 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + file: app.dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/perplexica-frontend:latest + + - name: Push backend Docker image + if: github.event_name != 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + file: backend.dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/perplexica-backend:latest + + - name: Log out from Docker Hub + if: github.event_name != 'pull_request' + run: docker logout diff --git a/app.dockerfile b/app.dockerfile index 105cf86..c3d3594 100644 --- a/app.dockerfile +++ b/app.dockerfile @@ -1,7 +1,7 @@ FROM node:alpine -ARG NEXT_PUBLIC_WS_URL -ARG NEXT_PUBLIC_API_URL +ARG NEXT_PUBLIC_WS_URL='ws://127.0.0.1:3001' +ARG NEXT_PUBLIC_API_URL='http://127.0.0.1:3001/api' ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL} ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} diff --git a/backend.dockerfile b/backend.dockerfile index 4886573..8297263 100644 --- a/backend.dockerfile +++ b/backend.dockerfile @@ -6,13 +6,10 @@ WORKDIR /home/perplexica COPY src /home/perplexica/src COPY tsconfig.json /home/perplexica/ -COPY config.toml /home/perplexica/ COPY drizzle.config.ts /home/perplexica/ COPY package.json /home/perplexica/ COPY yarn.lock /home/perplexica/ -RUN sed -i "s|SEARXNG = \".*\"|SEARXNG = \"${SEARXNG_API_URL}\"|g" /home/perplexica/config.toml - RUN mkdir /home/perplexica/data RUN yarn install diff --git a/docker-compose.yaml b/docker-compose.yaml index d6f9203..436e39e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -31,9 +31,6 @@ services: build: context: . dockerfile: app.dockerfile - args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 depends_on: - perplexica-backend ports: diff --git a/src/config.ts b/src/config.ts index 9ebc182..4c4a2b9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import path from 'path'; import toml from '@iarna/toml'; +import process from 'process'; const configFileName = 'config.toml'; @@ -29,20 +30,25 @@ const loadConfig = () => fs.readFileSync(path.join(__dirname, `../${configFileName}`), 'utf-8'), ) as any as Config; -export const getPort = () => loadConfig().GENERAL.PORT; +export const getPort = () => process.env.PORT ?? loadConfig().GENERAL.PORT; export const getSimilarityMeasure = () => - loadConfig().GENERAL.SIMILARITY_MEASURE; + process.env.SIMILARITY_MEASURE ?? loadConfig().GENERAL.SIMILARITY_MEASURE; -export const getOpenaiApiKey = () => loadConfig().API_KEYS.OPENAI; +export const getOpenaiApiKey = () => + process.env.OPENAI_API_KEY ?? loadConfig().API_KEYS.OPENAI; -export const getGroqApiKey = () => loadConfig().API_KEYS.GROQ; +export const getGroqApiKey = () => + process.env.GROQ_API_KEY ?? loadConfig().API_KEYS.GROQ; -export const getAnthropicApiKey = () => loadConfig().API_KEYS.ANTHROPIC; +export const getAnthropicApiKey = () => + process.env.ANTHROPIC_API_KEY ?? loadConfig().API_KEYS.ANTHROPIC; -export const getSearxngApiEndpoint = () => loadConfig().API_ENDPOINTS.SEARXNG; +export const getSearxngApiEndpoint = () => + process.env.SEARXNG_API_ENDPOINT ?? loadConfig().API_ENDPOINTS.SEARXNG; -export const getOllamaApiEndpoint = () => loadConfig().API_ENDPOINTS.OLLAMA; +export const getOllamaApiEndpoint = () => + process.env.OLLAMA_API_ENDPOINT ?? loadConfig().API_ENDPOINTS.OLLAMA; export const updateConfig = (config: RecursivePartial) => { const currentConfig = loadConfig();