Skip to content

Commit 3d65909

Browse files
committed
Changed order of operations, docker container builds the react app during composition
1 parent 5b99937 commit 3d65909

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ npm run build
3535
The following commands will build the docker via compose which builds the multi-docker system.
3636
You will also need to move the docker related `.env` into the docker folder (dir of Dockerfile) before running the following:
3737
```bash
38-
cd docker
3938
docker network create traefik
40-
docker-compose -p khi up --build
39+
docker-compose --env-file .env -p khi -f docker/docker-compose.yml up --build
4140
```
4241
The following commands will build ONLY the khi website docker image that you later start via `docker run -d ...`.
4342
```bash

docker/Dockerfile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@ WORKDIR /
55
# docker run -d --name khi_db -e MONGO_INITDB_ROOT_USERNAME=env.user -e MONGO_INITDB_ROOT_PASSWORD=env.password -e MONGO_INITDB_DATABASE=env.db -v mongodb_data:/data/db -p 27017:27017 mongo:latest
66
RUN apt-get update && apt-get install -y supervisor sudo nodejs npm net-tools
77

8+
# ensure directories exist
9+
RUN mkdir /var/www
10+
RUN mkdir /var/www/khi
11+
RUN mkdir /var/www/project
12+
13+
# give www-data ability to run commands and interact with web-root
14+
RUN chsh -s /bin/bash www-data
15+
RUN chown -R www-data:www-data /var/www
16+
817
# move production build into docker and move
918
# nginx conf file into the docker
10-
COPY build /var/www/khi
11-
COPY package.json /var/www/khi/package.json
12-
COPY .env /var/www/khi/.env
19+
COPY public /var/www/project/public
20+
COPY src /var/www/project/src
21+
COPY .env /var/www/project/.env
22+
COPY package.json /var/www/project/package.json
23+
24+
# create symlink to .env
25+
RUN ln -s /var/www/project/.env /var/www/khi/.env
26+
RUN ln -s /var/www/project/package.json /var/www/khi/package.json
27+
28+
# build react app
29+
RUN su www-data -s /bin/sh -c "cd /var/www/project && npm install . && npm run build && cp -r build/* -t /var/www/khi"
30+
1331
COPY docker/khi /etc/nginx/conf.d/khi.conf
1432

1533
# move backend to web root
@@ -18,9 +36,6 @@ COPY backend /var/www/khi/backend
1836
# remove default nginx config
1937
RUN rm /etc/nginx/conf.d/default.conf
2038

21-
# give www-data ability to run commands and interact with web-root
22-
RUN chsh -s /bin/bash www-data
23-
RUN chown -R www-data:www-data /var/www
2439
# install needed nodejs packages to allow the backend to run
2540
RUN su www-data -s /bin/sh -c "cd /var/www/khi && npm install ."
2641

docker/init_mongo.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
2+
# THIS SCRIPT IS RESPONSIBLE FOR CREATING THE SUPER ADMIN
3+
# FOR THE KHI WEBSITE (THIS ADMIN CANNOT BE REMOVED FROM THE ADMIN PANEL)
24

35
username="admin" # OPTIONAL to change
46
password="admin" # CHANGE THIS IN PRODUCTION
7+
58
salt="" # SALT .env
69
hashed=$(echo -n "${salt}${password}" | sha256sum | awk '{print $1}')
710

0 commit comments

Comments
 (0)