created Dockerfile and entrypoint with default http port

This commit is contained in:
Andrew Karp
2020-12-28 12:02:26 +02:00
parent d36a291543
commit 3ede7d5077
3 changed files with 25 additions and 2 deletions

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM node:alpine as builder
RUN apk update && apk add --no-cache python make g++
WORKDIR /opt/app/
COPY package.json ./
RUN npm install
RUN npm prune
FROM node:alpine as webapp
RUN apk add curl
WORKDIR /opt/app
COPY . /opt/app
COPY --from=builder /opt/app/node_modules ./node_modules
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

8
entrypoint.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
PUBLIC_IPV4="$(curl --fail -qs whatismyip.akamai.com)"
API_PORT="${API_PORT:-3000}"
API_VERSION="${API_VERSION:-v1}"
echo "REACT_APP_API_BASE_URL=${REACT_APP_API_BASE_URL:-http://$PUBLIC_IPV4}:$API_PORT/$API_VERSION" > /opt/app/.env
cd /opt/app/
npm run build
npm run serve

View File

@@ -15,11 +15,11 @@
"styled-components": "^5.0.1"
},
"scripts": {
"start": "PORT=3001 react-scripts start",
"start": "PORT=${HTTP_PORT:-3001} react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"serve": "serve -s build -l 3001",
"serve": "serve -s build -l ${HTTP_PORT:-3001}",
"pm2": "pm2 start npm --name \"jambonz-webapp\" -- run serve",
"deploy": "npm i && npm run build && npm run pm2"
},