FOR REVIEWERS: IF YOU DO NOT ALREADY HAVE DOCKER INSTALLED, DO NOT TRY TO START THE DEVELOPMENT SERVER
To start the development server, you have to have docker and docker-compose installed. The run from the directory project3-it2810
:
$ docker-compose up -d
The images are built to have hot-reload when code is changed in the src/
directories. When you do changes to other folders, you have to build again:
$ docker-compose build
If you do a change to the database or someething that would change the node_modules folder a lot (like npm uninstall
something or changing the database schema), you have to build everything from scratch with:
$ docker-compose build --no-cache
To develop in this environment, you have to do npm install
in three directories (just cd
into them):
- project3-it2810
- project3-frontend
- project3-backend
This can be done using the single command from the directory project3-it2810
:
$ npm run install:all
This runs npm install in all 3 directories.
If you do a fundamental change in the databse schema, you might have to delete the database for the project to run. To do so:
# Find the running docker containers (including the databse docker image)
$ docker ps
# Now take the container id of the postgres database, replace it with <containerid> and run the following command
$ docker exec -it <containerid> bash
# Log in to the database
$ psql -U postgres
# Find specific databse (probably it2810-project3)
$ \l
# Delete the database
$ DROP DATABASE "it2810-project3";
# You can also delete specific tables by logging directly into the database itself
$ psql -U postgres -d it2810-project3 # OR log in from psql postgres with `$ \connect it2810-project3`
# View tables
$ \dt
# Delete specific table with <tablename> (remeber to do it with "" if the name contains special chars)
$ DROP TABLE <tablename>;
At the moment there are tests in the unit tests in the frontend with React testing library and end-to-end testing with cypress. The unit tests in the frontend should be created in the folder of the component/function itself. The unit tests have to be run from the project3-frontend
directory, suing the command:
$ npm run test
The end-to-end tests with cypress can be run from the it2810-project3
directory. To run the tests you first have to start a test instance of the frontend, backend and database with:
WINDOWS:
$ ./scripts/cypress.ps1
Linux:
$ ./scripts/cypress.sh
This will run the frontend and backend with an instance of the database that will not persist accross docker instances.
From then you have to run (from it2810-project3
directory):
$ npm run cypress:open
This will make you able to run the tests once. If you want to run these tests more than once, you have to delete the database instance by restarting the docker containers by using the above ./scripts/cypress
script.
The content is currently in /usr/local/share/project3-it2810 on the VM.
On the VM we have git, docker, docker-compose and nginx installed. The apache server is stopped.
The nginx config file is in "/etc/nginx/sites-enabled/projects". The "etc/nginx/sites-enabled/projects" file has a hard link to the "/etc/nginx/sites-available/projects" file via the ln command.
The projects config file is as follows:
server {
listen 80;
location / {
root /var/www/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /project3 {
proxy_pass http://localhost:3500/project3;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /api {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
When a new version of the website should be deployed, push the changes to GitLab. Then pull the changes on the VM (the projects is already cloned in "/var/www/project3-it2810/, just cd in here and do sudo git checkout master && sudo git pull
").
Then stop the running server with
$ sudo docker-compose down
Build the new server with
$ sudo docker-compose -f docker-compose.prod.yml build
If substantial changes are made, the --no-cache
flag might need to be added. If big changes to the database has been made, then you might have to change the database itself, like explained earlier.
Run the server with
$ sudo docker-compose -f docker-compose.prod.yml up -d
If you do changes to the config file in /etc/nginx/sites-enables/projects, you have to restart the nginx server with
$ sudo systemctl restart nginx
You can check if the nginx config is valid with
$ sudo nginx -t