Skip to content

Commit

Permalink
feat: added staging
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Feb 26, 2024
1 parent 7ac2c94 commit f218895
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 28 deletions.
1 change: 1 addition & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug*
dist
tests
.output
.env
3 changes: 2 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ COPY . .

ENV NODE_ENV=production
RUN npx prisma generate
ENV PORT=3000

RUN useradd -m myuser
USER myuser
CMD pnpm start
CMD npx prisma db push && pnpm start
40 changes: 29 additions & 11 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3'
version: "3"

services:

database:
restart: unless-stopped
image: postgres:15
Expand Down Expand Up @@ -30,37 +29,56 @@ services:
AUTH_SIGNUP_ENABLED: "1"
JWT_SECRET: replace_in_production_with_actual_secret
JWT_EXPIRATION_PERIOD_SECONDS: 3600
API_GQL_ENDPOINT: "http://localhost:3000"
PORT: 3000
healthcheck:
test: ["CMD-SHELL", "curl --fail http://api:3000/healthz || exit 1"]
interval: 10s
timeout: 5s
retries: 5
depends_on:
database:
condition: service_healthy

frontend:
restart: unless-stopped
build:
context: .
dockerfile: ./frontend/Dockerfile
context: ./frontend
args:
NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST: "http://localhost:3000"
environment:
NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST: "http://localhost:3000"
expose:
- 3000
depends_on:
api:
condition: service_healthy

wundergraph:
platform: linux/amd64
restart: unless-stopped
expose:
- 3002
- 3000
build:
context: ./wundergraph
environment:
SWITCHBOARD_GQL_ENDPOINT: "http://api:3000/graphql"
SWITCHBOARD_GQL_ENDPOINT: "http://api:3000/drives"
depends_on:
- api
api:
condition: service_healthy

reverse-proxy:
restart: unless-stopped
image: nginx:stable
build:
context: ./nginx
ports:
- '80:80'
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- "3000:3000"
environment:
PORT: 3000
FRONTEND: "http://frontend:3000"
BACKEND: "http://api:3000"
WUNDERGRAPH: "http://wundergraph:3000"
depends_on:
- api
- frontend
- wundergraph
6 changes: 3 additions & 3 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:lts-alpine AS deps

WORKDIR /opt/app
COPY package.json pnpm-lock.yaml ./
COPY package.json pnpm-lock.yaml .
RUN npm install -g pnpm
RUN pnpm install

Expand All @@ -12,8 +12,8 @@ RUN pnpm install
FROM node:lts-alpine AS builder

ENV NODE_ENV=production
ARG SWITCHBOARD_HOST="https://ph-switchboard-nginx-prod-c84ebf8c6e3b.herokuapp.com"
ENV NEXT_PUBLIC_SWITCHBOARD_HOST=${SWITCHBOARD_HOST}
ARG NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST
ENV NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST=${NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST}
WORKDIR /opt/app
COPY . .
COPY --from=deps /opt/app/node_modules ./node_modules
Expand Down
8 changes: 5 additions & 3 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST: process.env.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST || "https://ph-switchboard-nginx-prod-c84ebf8c6e3b.herokuapp.com",
},
env: {
NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST:
process.env.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST ||
"https://ph-switchboard-nginx-prod-c84ebf8c6e3b.herokuapp.com",
},
};

export default nextConfig;
2 changes: 1 addition & 1 deletion frontend/src/app/graphql/[driveId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function GraphQLDrive() {
return (
<Suspense>
<GraphQLIframe
url={`${process.env.NEXT_PUBLIC_SWITCHBOARD_HOST}/explorer/${params?.driveId}`}
url={`${process.env.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST}/explorer/${params?.driveId}`}
/>
</Suspense>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/graphql/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function GraphQL() {
return (
<Suspense>
<GraphQLIframe
url={`${process.env.NEXT_PUBLIC_SWITCHBOARD_HOST}/explorer`}
url={`${process.env.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST}/explorer`}
/>
</Suspense>
);
Expand Down
11 changes: 3 additions & 8 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ server {

# frontend
location / {
rewrite /(.*) /$1 break;
proxy_pass ${FRONTEND};
}

# drives
# drives graphql endpoint
location /drives {
rewrite /drives/(.*) /drives/$1 break;
proxy_pass ${BACKEND};
}

# drive
# drive graphql endpoint
location /d {
rewrite /d/(.*) /d/$1 break;
proxy_pass ${BACKEND};
Expand All @@ -27,12 +28,6 @@ server {
proxy_pass ${BACKEND};
}

# api
location /graphql/ {
rewrite /graphql/(.*) /$1 break;
proxy_pass ${BACKEND};
}

# graphql API composition
location /wundergraph/graphql {
rewrite /wundergraph/graphql /graphql break;
Expand Down

0 comments on commit f218895

Please sign in to comment.