Skip to content

Commit 32c589d

Browse files
committed
fix docker config & env var at build time
1 parent 4b007ff commit 32c589d

8 files changed

+84
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ There is two ways to start the apps, the first one rely on docker and docker-com
2020

2121
Prerequisites: docker and docker-compose 3.8+
2222

23-
Run `docker-compose up`
23+
Run `docker compose --file docker-compose.base.yml --file docker-compose.dev.yml up`
2424

2525
#### Manually
2626

docker-compose.yml docker-compose.base.yml

+22-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ services:
1111
POSTGRES_USER: postgres
1212
POSTGRES_PASSWORD: postgres
1313
POSTGRES_DB: postgres
14+
networks:
15+
- backend
1416

1517
#=== API ===#
1618

@@ -25,14 +27,29 @@ services:
2527
DB_USER: postgres
2628
DB_PASSWORD: postgres
2729
DB_HOST: postgres
28-
ports:
29-
- 8000:8000
30+
restart: always
31+
depends_on:
32+
- database
33+
networks:
34+
- backend
35+
- frontend
3036

3137
#=== Frontend ===#
3238

3339
frontend:
3440
container_name: frontend
35-
build: ./frontend
41+
build:
42+
context: ./frontend
3643
restart: always
37-
ports:
38-
- 3000:3000
44+
depends_on:
45+
- api
46+
networks:
47+
- frontend
48+
49+
#=== Networks ===#
50+
51+
networks:
52+
frontend:
53+
name: frontend_network
54+
backend:
55+
name: backend_network

docker-compose.dev.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.8"
2+
services:
3+
4+
# This file is supposed to be used in addition to the base docker-compose.yml
5+
# ex:
6+
# docker compose --file docker-compose.base.yml --file docker-compose.dev.yml up
7+
8+
database:
9+
ports:
10+
- target: 5432
11+
# published: 5432 # Not required
12+
13+
api:
14+
ports:
15+
- target: 8000
16+
published: 8000
17+
18+
frontend:
19+
build:
20+
context: ./frontend
21+
args:
22+
- API_BASE_URL=http://0.0.0.0:8000
23+
ports:
24+
- target: 3000
25+
published: 3000 # Public
26+

docker-compose.prod.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.8"
2+
services:
3+
4+
# This file is supposed to be used in addition to the base docker-compose.yml
5+
# ex:
6+
# docker compose --file docker-compose.base.yml --file docker-compose.prod.yml up
7+
8+
database:
9+
ports:
10+
- target: 5432
11+
# published: # NOT publicly accessible
12+
13+
api:
14+
ports:
15+
- target: 8000
16+
published: 8000
17+
18+
frontend:
19+
build:
20+
context: ./frontend
21+
args:
22+
- API_BASE_URL=http://54.36.191.123:8000
23+
ports:
24+
- target: 3000
25+
published: 80 # Public
26+

frontend/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ WORKDIR /app
2222
COPY --from=deps /app/node_modules ./node_modules
2323
COPY . .
2424

25+
ARG API_BASE_URL=http://0.0.0.0
26+
ENV API_BASE_URL=$API_BASE_URL
27+
2528
# Next.js collects completely anonymous telemetry data about general usage.
2629
# Learn more here: https://nextjs.org/telemetry
2730
# Uncomment the following line in case you want to disable telemetry during the build.
2831
# ENV NEXT_TELEMETRY_DISABLED 1
29-
3032
RUN yarn build
3133

3234
# If using npm comment out above and use below instead

frontend/next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
output: 'standalone',
4+
env: {
5+
API_BASE_URL: process.env['API_BASE_URL'] ?? 'http://localhost:8000'
6+
}
47
}
58

69
module.exports = nextConfig

frontend/src/app/components/SampleDetails.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function SampleDetails({ sample, onEdit, onClose, onDelete }: Sam
7373
<td>{file_name ?
7474
<a
7575
// TODO: would be better to include the url in API's response
76-
href={`http://localhost:8000/sample/${id}/download`}
76+
href={`${process.env.API_BASE_URL}/sample/${id}/download`}
7777
className="underline"
7878
title="Download File"
7979
>

frontend/src/app/utilities/useApi.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { useCallback } from "react";
33
import { useAppContext, useAppDispatchContext } from "../contexts/AppContext";
44
import { Page, Sample, SampleCreate, SampleUpdate } from "@/app/types";
55

6-
76
/**
87
* Create a new AXIOS instance to query the API
98
* See https://www.npmjs.com/package/axios
109
*/
1110
const api = axios.create({
12-
baseURL: `${process.env.BIOSTACK_API_HOST ?? 'http://localhost'}/sample`,
13-
timeout: 3000,
11+
baseURL: `${process.env.API_BASE_URL}/sample`,
12+
timeout: 5000,
1413
headers: {
1514
'Accept': 'application/json',
1615
}

0 commit comments

Comments
 (0)