Skip to content

Commit

Permalink
fix docker config & env var at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Jan 27, 2024
1 parent 4b007ff commit d60083c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
16 changes: 16 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"
services:

# This file is supposed to be used in addition to the base docker-compose.yml
# ex:
# docker compose --file docker-compose.yml --file docker-compose.prod.yml up

#=== Frontend ===#

frontend:
build:
context: ./frontend
args:
- API_BASE_URL=http://54.36.191.123:8000
ports:
- 80:3000
24 changes: 23 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432
networks:
- backend

#=== API ===#

Expand All @@ -25,14 +29,32 @@ services:
DB_USER: postgres
DB_PASSWORD: postgres
DB_HOST: postgres
restart: always
ports:
- 8000:8000
networks:
- backend
- frontend

#=== Frontend ===#

frontend:
container_name: frontend
build: ./frontend
build:
context: ./frontend
args:
# Decided to rely on build-time env var (they will be inlined in the build output)
- API_BASE_URL=http://0.0.0.0:8000
restart: always
ports:
- 3000:3000
networks:
- frontend

#=== Networks ===#

networks:
frontend:
name: frontend_network
backend:
name: backend_network
4 changes: 3 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ARG API_BASE_URL=http://0.0.0.0
ENV API_BASE_URL=$API_BASE_URL

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

# If using npm comment out above and use below instead
Expand Down
3 changes: 3 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
env: {
API_BASE_URL: process.env['API_BASE_URL'] ?? 'http://localhost:8000'
}
}

module.exports = nextConfig
2 changes: 1 addition & 1 deletion frontend/src/app/components/SampleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function SampleDetails({ sample, onEdit, onClose, onDelete }: Sam
<td>{file_name ?
<a
// TODO: would be better to include the url in API's response
href={`http://localhost:8000/sample/${id}/download`}
href={`${process.env.API_BASE_URL}/sample/${id}/download`}
className="underline"
title="Download File"
>
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/app/utilities/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { useCallback } from "react";
import { useAppContext, useAppDispatchContext } from "../contexts/AppContext";
import { Page, Sample, SampleCreate, SampleUpdate } from "@/app/types";


/**
* Create a new AXIOS instance to query the API
* See https://www.npmjs.com/package/axios
*/
const api = axios.create({
baseURL: `${process.env.BIOSTACK_API_HOST ?? 'http://localhost'}/sample`,
timeout: 3000,
baseURL: `${process.env.API_BASE_URL}/sample`,
timeout: 5000,
headers: {
'Accept': 'application/json',
}
Expand Down

0 comments on commit d60083c

Please sign in to comment.