mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix(docker): docker-compose for prod+development
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
**/.classpath
|
**/.classpath
|
||||||
**/.dockerignore
|
**/.dockerignore
|
||||||
**/.env
|
**/.env
|
||||||
|
!.env
|
||||||
**/.git
|
**/.git
|
||||||
**/.gitignore
|
**/.gitignore
|
||||||
**/.project
|
**/.project
|
||||||
@@ -20,4 +21,12 @@
|
|||||||
**/obj
|
**/obj
|
||||||
**/secrets.dev.yaml
|
**/secrets.dev.yaml
|
||||||
**/values.dev.yaml
|
**/values.dev.yaml
|
||||||
|
api/build
|
||||||
|
api/coverage
|
||||||
|
api/build
|
||||||
|
api/node_modules
|
||||||
|
api/public
|
||||||
|
api/web
|
||||||
|
web/build
|
||||||
|
web/node_modules
|
||||||
README.md
|
README.md
|
||||||
|
|||||||
5
.env.example
Normal file
5
.env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
PORT=<port for sasjs server (api)>
|
||||||
|
PORT_WEB=<port for sasjs web component(react)>
|
||||||
|
ACCESS_TOKEN_SECRET=<secret>
|
||||||
|
REFRESH_TOKEN_SECRET=<secret>
|
||||||
|
AUTH_CODE_SECRET=<secret>
|
||||||
10
DockerfileProd
Normal file
10
DockerfileProd
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM node:lts-alpine
|
||||||
|
WORKDIR /usr/server/
|
||||||
|
COPY . .
|
||||||
|
RUN cd web && npm ci --silent
|
||||||
|
RUN cd web && REACT_APP_CLIENT_ID=clientID1 npm run build
|
||||||
|
RUN cd api && npm ci --silent
|
||||||
|
# RUN chown -R node /usr/server/api
|
||||||
|
# USER node
|
||||||
|
WORKDIR /usr/server/api
|
||||||
|
CMD ["npm","run","start"]
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
MODE=[server]
|
MODE=[server]
|
||||||
CORS=[enable]
|
CORS=[enable]
|
||||||
|
PORT_WEB=[port for sasjs web component(react)]
|
||||||
ACCESS_TOKEN_SECRET=<secret>
|
ACCESS_TOKEN_SECRET=<secret>
|
||||||
REFRESH_TOKEN_SECRET=<secret>
|
REFRESH_TOKEN_SECRET=<secret>
|
||||||
AUTH_CODE_SECRET=<secret>
|
AUTH_CODE_SECRET=<secret>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ WORKDIR /usr/server/api
|
|||||||
COPY ["package.json","package-lock.json", "./"]
|
COPY ["package.json","package-lock.json", "./"]
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
COPY . .
|
||||||
EXPOSE 5000
|
|
||||||
# RUN chown -R node /usr/server/api
|
# RUN chown -R node /usr/server/api
|
||||||
# USER node
|
# USER node
|
||||||
CMD ["npm","start"]
|
CMD ["npm","start"]
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ dotenv.config()
|
|||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
const { MODE, CORS } = process.env
|
const { MODE, CORS, PORT_WEB } = process.env
|
||||||
if (MODE?.trim() !== 'server' || CORS?.trim() === 'enable') {
|
if (MODE?.trim() !== 'server' || CORS?.trim() === 'enable') {
|
||||||
console.log('All CORS Requests are enabled')
|
console.log('All CORS Requests are enabled')
|
||||||
app.use(cors({ credentials: true, origin: 'http://localhost:3000' }))
|
app.use(
|
||||||
|
cors({ credentials: true, origin: `http://localhost:${PORT_WEB ?? 3000}` })
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(express.json({ limit: '50mb' }))
|
app.use(express.json({ limit: '50mb' }))
|
||||||
|
|||||||
40
docker-compose.prod.yml
Normal file
40
docker-compose.prod.yml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
version: '3.4'
|
||||||
|
|
||||||
|
services:
|
||||||
|
sasjs_server_prod:
|
||||||
|
image: sasjs_server_prod
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: DockerfileProd
|
||||||
|
environment:
|
||||||
|
MODE: server
|
||||||
|
CORS: disable
|
||||||
|
PORT: ${PORT_API}
|
||||||
|
ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
|
||||||
|
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
|
||||||
|
AUTH_CODE_SECRET: ${AUTH_CODE_SECRET}
|
||||||
|
DB_CONNECT: mongodb://mongodb:27017/sasjs
|
||||||
|
expose:
|
||||||
|
- ${PORT_API}
|
||||||
|
ports:
|
||||||
|
- ${PORT_API}:${PORT_API}
|
||||||
|
links:
|
||||||
|
- mongodb
|
||||||
|
|
||||||
|
mongodb:
|
||||||
|
image: mongo:latest
|
||||||
|
ports:
|
||||||
|
- 27017:27017
|
||||||
|
volumes:
|
||||||
|
- data:/data/db
|
||||||
|
mongo-seed-users:
|
||||||
|
build: ./mongo-seed/users
|
||||||
|
links:
|
||||||
|
- mongodb
|
||||||
|
mongo-seed-clients:
|
||||||
|
build: ./mongo-seed/clients
|
||||||
|
links:
|
||||||
|
- mongodb
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
data:
|
||||||
@@ -7,10 +7,16 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
MODE: server
|
MODE: server
|
||||||
CORS: enable
|
CORS: enable
|
||||||
PORT: 5000
|
PORT: ${PORT_API}
|
||||||
|
PORT_WEB: ${PORT_WEB}
|
||||||
|
ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
|
||||||
|
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
|
||||||
|
AUTH_CODE_SECRET: ${AUTH_CODE_SECRET}
|
||||||
DB_CONNECT: mongodb://mongodb:27017/sasjs
|
DB_CONNECT: mongodb://mongodb:27017/sasjs
|
||||||
|
expose:
|
||||||
|
- ${PORT_API}
|
||||||
ports:
|
ports:
|
||||||
- 5000:5000
|
- ${PORT_API}:${PORT_API}
|
||||||
volumes:
|
volumes:
|
||||||
- ./api:/usr/server/api
|
- ./api:/usr/server/api
|
||||||
links:
|
links:
|
||||||
@@ -19,8 +25,13 @@ services:
|
|||||||
sasjs_server_web:
|
sasjs_server_web:
|
||||||
image: sasjs_server_web
|
image: sasjs_server_web
|
||||||
build: ./web
|
build: ./web
|
||||||
|
environment:
|
||||||
|
REACT_APP_PORT_API: ${PORT_API}
|
||||||
|
PORT: ${PORT_WEB}
|
||||||
|
expose:
|
||||||
|
- ${PORT_WEB}
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- ${PORT_WEB}:${PORT_WEB}
|
||||||
volumes:
|
volumes:
|
||||||
- ./web:/usr/server/web
|
- ./web:/usr/server/web
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
REACT_APP_PORT_API=[place sasjs server port]
|
||||||
REACT_APP_CLIENT_ID=<place clientId here>
|
REACT_APP_CLIENT_ID=<place clientId here>
|
||||||
@@ -3,7 +3,6 @@ WORKDIR /usr/server/web
|
|||||||
COPY ["package.json","package-lock.json", "./"]
|
COPY ["package.json","package-lock.json", "./"]
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
COPY . .
|
||||||
EXPOSE 3000
|
|
||||||
# RUN chown -R node /usr/server/api
|
# RUN chown -R node /usr/server/api
|
||||||
# USER node
|
# USER node
|
||||||
CMD ["npm","start"]
|
CMD ["npm","start"]
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ const headers = {
|
|||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
const { NODE_ENV, REACT_APP_PORT_API } = process.env
|
||||||
const baseUrl =
|
const baseUrl =
|
||||||
process.env.NODE_ENV === 'development' ? 'http://localhost:5000' : undefined
|
NODE_ENV === 'development'
|
||||||
|
? `http://localhost:${REACT_APP_PORT_API ?? 5000}`
|
||||||
|
: ''
|
||||||
|
|
||||||
const getAuthCode = async (credentials: any) => {
|
const getAuthCode = async (credentials: any) => {
|
||||||
return fetch(`${baseUrl}/SASjsApi/auth/authorize`, {
|
return fetch(`${baseUrl}/SASjsApi/auth/authorize`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -43,8 +43,11 @@ export default function useTokens() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { NODE_ENV, REACT_APP_PORT_API } = process.env
|
||||||
const baseUrl =
|
const baseUrl =
|
||||||
process.env.NODE_ENV === 'development' ? 'http://localhost:5000' : undefined
|
NODE_ENV === 'development'
|
||||||
|
? `http://localhost:${REACT_APP_PORT_API ?? 5000}`
|
||||||
|
: ''
|
||||||
|
|
||||||
const isAbsoluteURLRegex = /^(?:\w+:)\/\//
|
const isAbsoluteURLRegex = /^(?:\w+:)\/\//
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user