Add Dockerfiles for server and client, update package.json scripts
This commit is contained in:
parent
469204a30f
commit
c099f016f9
11 changed files with 167 additions and 117 deletions
10
.github/workflows/build-deploy.yml
vendored
10
.github/workflows/build-deploy.yml
vendored
|
|
@ -4,6 +4,8 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
test:
|
||||
|
|
@ -32,7 +34,9 @@ jobs:
|
|||
with:
|
||||
image: c4thebomb/know-it-all-client
|
||||
registry: docker.io
|
||||
tags: latest
|
||||
addLatest: true
|
||||
multiPlatform: true
|
||||
platform: linux/amd64,linux/arm64/v8
|
||||
directory: ./client
|
||||
dockerfile: ./client/Dockerfile
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
|
|
@ -42,7 +46,9 @@ jobs:
|
|||
with:
|
||||
image: c4thebomb/know-it-all-server
|
||||
registry: docker.io
|
||||
tags: latest
|
||||
addLatest: true
|
||||
multiPlatform: true
|
||||
platform: linux/amd64,linux/arm64/v8
|
||||
directory: ./server
|
||||
dockerfile: ./server/Dockerfile
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM node:16-alpine
|
||||
|
||||
FROM node:16-alpine as build
|
||||
WORKDIR /app
|
||||
|
||||
COPY ["./package.json", "./package-lock.json*", "./"]
|
||||
COPY ["package.json", "./"]
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY ["./public", "./public"]
|
||||
COPY ["./src", "./src"]
|
||||
COPY . .
|
||||
|
||||
RUN npm run build
|
||||
|
||||
|
||||
FROM node:16-alpine
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=build /app/build ./build
|
||||
COPY --from=build /app/node_modules/serve ./node_modules/serve
|
||||
|
||||
EXPOSE 3000/tcp
|
||||
|
||||
CMD ["npm", "run", "serve"]
|
||||
CMD ["npx", "serve", "-s", "build"]
|
||||
|
|
|
|||
14
client/Dockerfile.dev
Normal file
14
client/Dockerfile.dev
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM node:16-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ["package.json", "./"]
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000/tcp
|
||||
|
||||
CMD ["npm" "run" "start"]
|
||||
|
|
@ -17,16 +17,13 @@
|
|||
"react-helmet": "^6.1.0",
|
||||
"react-router-dom": "^6.2.2",
|
||||
"react-scripts": "5.0.0",
|
||||
"serve": "^14.2.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
"serve": "^14.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"serve": "serve -s build",
|
||||
"preserve": "npm run build"
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
|
|
|
|||
|
|
@ -1,34 +1,43 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
client:
|
||||
restart: unless-stopped
|
||||
image: c4thebomb/know-it-all-client
|
||||
build: ./client
|
||||
ports:
|
||||
- 3000:3000
|
||||
networks:
|
||||
- local-network
|
||||
env_file:
|
||||
- path: ./.env
|
||||
required: true
|
||||
environment:
|
||||
WATCHPACK_POLLING: true
|
||||
depends_on:
|
||||
- server
|
||||
server:
|
||||
restart: unless-stopped
|
||||
image: c4thebomb/know-it-all-server
|
||||
build: ./server
|
||||
ports:
|
||||
- 3000:3001
|
||||
networks:
|
||||
- local-network
|
||||
env_file:
|
||||
- path: ./.env
|
||||
required: true
|
||||
environment:
|
||||
DB_CONN_STRING: 'mongodb://mongodb:27017'
|
||||
CHOKIDAR_USEPOLLING: true
|
||||
client:
|
||||
restart: unless-stopped
|
||||
build:
|
||||
context: ./client
|
||||
dockerfile: Dockerfile
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64/v8
|
||||
image: c4thebomb/know-it-all-client
|
||||
env_file:
|
||||
- path: .env
|
||||
required: true
|
||||
ports:
|
||||
- 127.0.0.1:3000:3000
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
WATCHPACK_POLLING: true
|
||||
depends_on:
|
||||
- server
|
||||
server:
|
||||
restart: unless-stopped
|
||||
image: c4thebomb/know-it-all-server
|
||||
build: ./server
|
||||
ports:
|
||||
- 127.0.0.1:3000:3001
|
||||
networks:
|
||||
- know-it-all
|
||||
- common-network
|
||||
env_file:
|
||||
- path: .env
|
||||
required: true
|
||||
environment:
|
||||
DB_CONN_STRING: 'mongodb://mongodb:27017'
|
||||
CHOKIDAR_USEPOLLING: true
|
||||
|
||||
networks:
|
||||
local-network: {}
|
||||
common-network:
|
||||
external: true
|
||||
know-it-all: {}
|
||||
|
|
|
|||
|
|
@ -1,62 +1,64 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
client:
|
||||
restart: unless-stopped
|
||||
build: ./client
|
||||
image: c4thebomb/know-it-all-client
|
||||
ports:
|
||||
- 3000:3000
|
||||
volumes:
|
||||
- ./client:/app
|
||||
- /app/node_modules
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
REACT_APP_API_ROOT: 'http://localhost:3001/api'
|
||||
REACT_APP_DOMAIN_ROOT: 'http://localhost:3000'
|
||||
WATCHPACK_POLLING: true
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
command: npm start
|
||||
server:
|
||||
restart: unless-stopped
|
||||
build: ./server
|
||||
image: c4thebomb/know-it-all-server
|
||||
ports:
|
||||
- 3001:3000
|
||||
volumes:
|
||||
- ./server:/app
|
||||
- /app/node_modules
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
NODE_ENV: development
|
||||
MYSQL_HOST: mysqldb
|
||||
MYSQL_USER: root
|
||||
MYSQL_PASSWORD: passw0rd
|
||||
MYSQL_DATABASE: dev
|
||||
depends_on:
|
||||
- mysqldb
|
||||
mysqldb:
|
||||
restart: unless-stopped
|
||||
image: mysql:8.3
|
||||
ports:
|
||||
- 3306:3306
|
||||
volumes:
|
||||
- know-it-all-mysql:/var/lib/mysql
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 'passw0rd'
|
||||
MYSQL_DATABASE: dev
|
||||
healthcheck:
|
||||
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
client:
|
||||
restart: unless-stopped
|
||||
build:
|
||||
context: ./client
|
||||
dockerfile: Dockerfile.dev
|
||||
ports:
|
||||
- 3000:3000
|
||||
volumes:
|
||||
- ./client:/app
|
||||
- /app/node_modules
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
REACT_APP_API_ROOT: 'http://localhost:3001/api'
|
||||
REACT_APP_DOMAIN_ROOT: 'http://localhost:3000'
|
||||
WATCHPACK_POLLING: true
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
command: npm start
|
||||
server:
|
||||
restart: unless-stopped
|
||||
build:
|
||||
context: ./server
|
||||
dockerfile: Dockerfile.dev
|
||||
ports:
|
||||
- 3001:3000
|
||||
volumes:
|
||||
- ./server:/app
|
||||
- /app/node_modules
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
NODE_ENV: development
|
||||
MYSQL_HOST: mysqldb
|
||||
MYSQL_USER: root
|
||||
MYSQL_PASSWORD: passw0rd
|
||||
MYSQL_DATABASE: dev
|
||||
depends_on:
|
||||
- mysqldb
|
||||
mysqldb:
|
||||
restart: unless-stopped
|
||||
image: mysql:8.3
|
||||
ports:
|
||||
- 3306:3306
|
||||
volumes:
|
||||
- know-it-all-mysql:/var/lib/mysql
|
||||
networks:
|
||||
- know-it-all
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 'passw0rd'
|
||||
MYSQL_DATABASE: dev
|
||||
healthcheck:
|
||||
test: [ 'CMD', 'mysqladmin', 'ping', '-h', 'localhost' ]
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
volumes:
|
||||
know-it-all-mysql:
|
||||
know-it-all-mysql:
|
||||
networks:
|
||||
know-it-all: {}
|
||||
know-it-all: {}
|
||||
|
|
|
|||
22
package-lock.json
generated
22
package-lock.json
generated
|
|
@ -42,8 +42,7 @@
|
|||
"react-helmet": "^6.1.0",
|
||||
"react-router-dom": "^6.2.2",
|
||||
"react-scripts": "5.0.0",
|
||||
"serve": "^14.2.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
"serve": "^14.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@aashutoshrathi/word-wrap": {
|
||||
|
|
@ -15317,9 +15316,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/postcss-load-config/node_modules/lilconfig": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.0.tgz",
|
||||
"integrity": "sha512-p3cz0JV5vw/XeouBU3Ldnp+ZkBjE+n8ydJ4mcwBrOiXXPqNlrzGBqWs9X4MWF7f+iKUBu794Y8Hh8yawiJbCjw==",
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.1.tgz",
|
||||
"integrity": "sha512-O18pf7nyvHTckunPWCV1XUNXU1piu01y2b7ATJ0ppkUkk8ocqVWBrYjJBCwHDjD/ZWcfyrA0P4gKhzWGi5EINQ==",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
|
|
@ -19938,16 +19937,16 @@
|
|||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "4.9.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz",
|
||||
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
|
||||
"version": "5.3.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
|
||||
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.2.0"
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/uid-number": {
|
||||
|
|
@ -20295,11 +20294,6 @@
|
|||
"minimalistic-assert": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/web-vitals": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-2.1.4.tgz",
|
||||
"integrity": "sha512-sVWcwhU5mX6crfI5Vd2dC4qchyTqxV8URinzt25XqVh+bHEPGH4C3NPrNionCP7Obx59wrYEbNlw4Z8sjALzZg=="
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"scripts": {
|
||||
"start": "concurrently \"npm run start -w client\" \"npm run start -w server\"",
|
||||
"start:server": "npm start server",
|
||||
"start:client": "npm start client",
|
||||
"build": "npm run build -w client",
|
||||
"test": "npm run test -w server",
|
||||
"migrate": "npm run migrate -w server",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM node:16-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ["package.json", "./"]
|
||||
RUN npm install
|
||||
|
||||
RUN npm install --production
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000/tcp
|
||||
CMD npm run start
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
CMD ["node", "bin/www"]
|
||||
|
|
|
|||
13
server/Dockerfile.dev
Normal file
13
server/Dockerfile.dev
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
FROM node:16-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ["package.json", "./"]
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000/tcp
|
||||
|
||||
CMD ["npm", "run", "start"]
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
"private": true,
|
||||
"scripts": {
|
||||
"start": "nodemon ./bin/www",
|
||||
"start:prod": "node ./bin/www",
|
||||
"test": "jest -i",
|
||||
"migrate": "sequelize db:migrate --env",
|
||||
"migrate:undo": "sequelize db:migrate:undo:all --env"
|
||||
|
|
|
|||
Reference in a new issue