Skip to content

Commit

Permalink
chore(back): Adjust the folder structure for backend container, etc.
Browse files Browse the repository at this point in the history
We did:

* Add Dockerfile in `back/` folder for docker container `backend`. Now it will
  build the node_modules in image. It will be helpful for those who do not have
  tool yarn and reduce the difficulty of running.
* Move source files from `back/` to `back/src`. Because Dockerfile's `COPY`
  cannot just copy directory. [More info][github-moby-dockerfile-stupid-copy].
  And that's why we also change some files with new path to those source files.
* Add `depends_on` keys in `docker-compose.yml`

[github-moby-dockerfile-stupid-copy]: moby/moby#15858
  • Loading branch information
PeterlitsZo committed Mar 10, 2022
1 parent 434c24d commit dc40a05
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 12 deletions.
12 changes: 12 additions & 0 deletions back/Dockerfile
@@ -0,0 +1,12 @@
FROM node

WORKDIR /home/node/app/

COPY package.json yarn.lock ./
RUN yarn && mkdir src
COPY ./src/ ./src/

USER node
EXPOSE 4000

CMD ["yarn", "start"]
2 changes: 1 addition & 1 deletion back/make.mjs
Expand Up @@ -13,7 +13,7 @@ const [_node_path, _zs_path, _this_file_path, ...argv] = process.argv;
*****************************************************************************/
const DB_NAME = 'acm-homepage.maria-db';
const DB_PORT = 3306;
const DB_DOCKERFILE_DIR = `${__dirname}/db`;
const DB_DOCKERFILE_DIR = `${__dirname}/src/db`;

/******************************************************************************
* Main part
Expand Down
5 changes: 3 additions & 2 deletions back/package.json
Expand Up @@ -10,8 +10,9 @@
"prettier": "^2.2.1"
},
"scripts": {
"dev": "NODE_ENV=development node main.js",
"format": "prettier --config ../.prettierrc -w \"?({graphql,db}/**/)*.{js,jsx,ts,tsx,json}\""
"dev": "NODE_ENV=development node ./src/main.js",
"start": "NODE_ENV=production node ./src/main.js",
"format": "prettier --config ../.prettierrc -w \"?(src/**/)*.{js,jsx,ts,tsx,json}\""
},
"type": "module"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions back/main.js → back/src/main.js
Expand Up @@ -34,3 +34,4 @@ GraphQLServer.use(
GraphQLServer.listen(4000, () => {
console.log('Listening on localhost:4000...');
});

16 changes: 7 additions & 9 deletions docker-compose.yml
@@ -1,19 +1,17 @@
version: "3"
services:
db:
build: ./back/db/
build: ./back/src/db/
backend:
image: node
user: node
working_dir: /home/node/app/
environment:
- NODE_ENV=production
volumes:
- ./back/:/home/node/app/
command: "node main.js"
build: ./back/
depends_on:
- db
nginx:
build: ./server/
ports:
- 80:80
volumes:
- ./front/dist/:/usr/share/nginx/html/
depends_on:
- db
- backend

0 comments on commit dc40a05

Please sign in to comment.