-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] update docker compose ๐ (#496)
* [fix] update docker compose ๐ * [doc] update README.md --------- Co-authored-by: John Zhou <john@realchar.ai>
- Loading branch information
1 parent
4f546ae
commit 24fb970
Showing
4 changed files
with
80 additions
and
31 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
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,67 @@ | ||
# We are using a Node.js base image | ||
FROM node:lts-alpine as build | ||
|
||
# Working directory be app | ||
WORKDIR /app | ||
|
||
ARG NEXT_PUBLIC_RC_BUILD_NUMBER | ||
ARG NEXT_PUBLIC_FIREBASE_API_KEY | ||
ARG NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN | ||
ARG NEXT_PUBLIC_FIREBASE_PROJECT_ID | ||
ARG NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET | ||
ARG NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID | ||
ARG NEXT_PUBLIC_FIREBASE_APP_ID | ||
ARG NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID | ||
ARG NEXT_PUBLIC_API_HOST | ||
ARG API_HOST | ||
ARG NEXT_PUBLIC_TURN_SERVER_API_ENDPOINT | ||
|
||
ENV NEXT_PUBLIC_RC_BUILD_NUMBER $NEXT_PUBLIC_RC_BUILD_NUMBER | ||
ENV NEXT_PUBLIC_FIREBASE_API_KEY $NEXT_PUBLIC_FIREBASE_API_KEY | ||
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN $NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN | ||
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID $NEXT_PUBLIC_FIREBASE_PROJECT_ID | ||
ENV NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET $NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET | ||
ENV NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID $NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID | ||
ENV NEXT_PUBLIC_FIREBASE_APP_ID $NEXT_PUBLIC_FIREBASE_APP_ID | ||
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID $NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID | ||
ENV NEXT_PUBLIC_API_HOST $NEXT_PUBLIC_API_HOST | ||
ENV API_HOST $API_HOST | ||
ENV NEXT_PUBLIC_TURN_SERVER_API_ENDPOINT $NEXT_PUBLIC_TURN_SERVER_API_ENDPOINT | ||
|
||
|
||
# Copy package.json and package-lock.json before other files | ||
# Utilise Docker cache to save re-installing dependencies if unchanged | ||
COPY package.json ./ | ||
COPY package-lock.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Copy all files | ||
COPY ./ ./ | ||
|
||
# Build app | ||
RUN env | ||
RUN npm run build | ||
|
||
# Run phase | ||
FROM node:lts-alpine | ||
|
||
# Install Nginx | ||
RUN apk add --no-cache curl nginx procps | ||
|
||
WORKDIR /app | ||
|
||
# Copy over the built app files | ||
COPY --from=build /app ./ | ||
|
||
# Install production dependencies | ||
RUN npm ci --only=production | ||
|
||
# Expose port 3000 to the Docker host, so we can access it | ||
# from the outside | ||
EXPOSE 3000 | ||
|
||
# Start command will start the Next.js app | ||
CMD ["sh", "-c", "npm start"] | ||
|
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,16 +1,12 @@ | ||
const host = process.env.API_HOST; | ||
|
||
export async function getCharacters() { | ||
if (!host) { | ||
// skip fetching during build | ||
try { | ||
const res = await fetch(`${host}/characters`, { next: { revalidate: 5 } }); | ||
return await res.json(); | ||
} catch (err) { | ||
console.log(err); | ||
return []; | ||
} | ||
|
||
const res = await fetch(`${host}/characters`, { next: { revalidate: 5 } }); | ||
|
||
if (!res.ok) { | ||
// This will activate the closest `error.js` Error Boundary | ||
throw new Error('Failed to fetch data'); | ||
} | ||
return res.json(); | ||
} |
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