Parcourir la source

Docker automatic testing

rigwild il y a 5 ans
Parent
commit
59ba564a8f
5 fichiers modifiés avec 44 ajouts et 19 suppressions
  1. 4 2
      .dockerignore
  2. 19 13
      README.md
  3. 1 1
      back.Dockerfile
  4. 12 2
      test/api/_test_setup_start.js
  5. 8 1
      test/api/_test_setup_stop.js

+ 4 - 2
.dockerignore

@@ -1,5 +1,7 @@
 node_modules
 node_modules
 npm-debug.log
 npm-debug.log
 .git
 .git
-images
-dist
+/images
+/dist
+package-lock.json
+/test/images

+ 19 - 13
README.md

@@ -2,7 +2,7 @@
 A web app to collect data on noise detection by humans on images.
 A web app to collect data on noise detection by humans on images.
 
 
 ## Download project
 ## Download project
-```sh
+```console
 git clone https://gogs.univ-littoral.fr/Prise3D/Antoine_Internship.git
 git clone https://gogs.univ-littoral.fr/Prise3D/Antoine_Internship.git
 cd Antoine_Internship
 cd Antoine_Internship
 ```
 ```
@@ -32,7 +32,7 @@ Configure more deeply the way the app works by modifying *[config.js](config.js)
 
 
 ### Run server + client
 ### Run server + client
 Linux
 Linux
-```sh
+```console
 PORT=8080 SERVE_CLIENT=true IMAGE_PATH=/var/images docker-compose up
 PORT=8080 SERVE_CLIENT=true IMAGE_PATH=/var/images docker-compose up
 ```
 ```
 Windows
 Windows
@@ -45,7 +45,7 @@ docker-compose up
 
 
 ### Run server only
 ### Run server only
 Linux
 Linux
-```sh
+```console
 SERVE_CLIENT=false docker-compose up
 SERVE_CLIENT=false docker-compose up
 ```
 ```
 Windows
 Windows
@@ -55,14 +55,14 @@ docker-compose up
 ```
 ```
 
 
 ### Run client only
 ### Run client only
-```sh
+```console
 docker-compose -f docker-compose.frontapp_only.yml up
 docker-compose -f docker-compose.frontapp_only.yml up
 ```
 ```
 
 
 ### Notice
 ### Notice
 #### New version Docker build
 #### New version Docker build
 When using a new version of the project, you need to re-build the application with Docker.
 When using a new version of the project, you need to re-build the application with Docker.
-```sh
+```console
 # Server / Server + client versions
 # Server / Server + client versions
 docker-compose build
 docker-compose build
 
 
@@ -89,7 +89,7 @@ yarn install
 If this is a production build, set the `NODE_ENV` environment variable to `production` to enhance performance.
 If this is a production build, set the `NODE_ENV` environment variable to `production` to enhance performance.
 
 
 Linux
 Linux
-```sh
+```console
 export NODE_ENV=production
 export NODE_ENV=production
 ```
 ```
 Windows
 Windows
@@ -99,17 +99,17 @@ SET NODE_ENV=production
 
 
 ### API
 ### API
 #### Run the server
 #### Run the server
-```sh
+```console
 yarn run server:start
 yarn run server:start
 ```
 ```
 
 
 #### Run the server with hot-reload for development
 #### Run the server with hot-reload for development
-```sh
+```console
 yarn run server:dev
 yarn run server:dev
 ```
 ```
 
 
 #### Automatically fix the API code syntax with ESLint
 #### Automatically fix the API code syntax with ESLint
-```sh
+```console
 yarn run server:lint
 yarn run server:lint
 ```
 ```
 
 
@@ -117,24 +117,24 @@ yarn run server:lint
 ### Client
 ### Client
 #### Compile and minify for production
 #### Compile and minify for production
 Files will be built to the `dist/` directory.
 Files will be built to the `dist/` directory.
-```sh
+```console
 yarn run app:build
 yarn run app:build
 ```
 ```
 
 
 #### Run a hot-reload server for client development
 #### Run a hot-reload server for client development
-```sh
+```console
 yarn run app:dev
 yarn run app:dev
 ```
 ```
 
 
 
 
 #### Automatically fix the client code syntax with ESLint
 #### Automatically fix the client code syntax with ESLint
-```sh
+```console
 yarn run app:lint
 yarn run app:lint
 ```
 ```
 
 
 ## Automated deployment
 ## Automated deployment
 The app can be automatically deployed when a push event is sent to the master branch using Gogs. Open a port to the web and start *[webhook_deploy_gogs.js](webhook_deploy_gogs.js)*.
 The app can be automatically deployed when a push event is sent to the master branch using Gogs. Open a port to the web and start *[webhook_deploy_gogs.js](webhook_deploy_gogs.js)*.
-```sh
+```console
 WEBHOOK_SECRET=your_webhook_secret WEBHOOK_PORT=5000 SERVE_CLIENT=true PORT=8080 node webhook_deploy_gogs.js
 WEBHOOK_SECRET=your_webhook_secret WEBHOOK_PORT=5000 SERVE_CLIENT=true PORT=8080 node webhook_deploy_gogs.js
 ```
 ```
 You can pass any parameters to the script, they will be passed to the Docker instance. The following are required.
 You can pass any parameters to the script, they will be passed to the Docker instance. The following are required.
@@ -144,5 +144,11 @@ You can pass any parameters to the script, they will be passed to the Docker ins
 | `WEBHOOK_SECRET` | The secret set on Gogs to verify the identity |
 | `WEBHOOK_SECRET` | The secret set on Gogs to verify the identity |
 | `WEBHOOK_PORT` | The port the script is listening to |
 | `WEBHOOK_PORT` | The port the script is listening to |
 
 
+## Running tests
+The `docker-compose` script will automatically run tests. Use the following command to run them by hand.
+```console
+yarn test
+```
+
 ## License
 ## License
 [The MIT license](LICENSE)
 [The MIT license](LICENSE)

+ 1 - 1
back.Dockerfile

@@ -10,4 +10,4 @@ EXPOSE 5000
 RUN yarn install
 RUN yarn install
 
 
 # Build front if SERVE_CLIENT=true
 # Build front if SERVE_CLIENT=true
-CMD if [ "$SERVE_CLIENT" == "true" ] ; then yarn run app:build && yarn run server:start ; else yarn run server:start ; fi
+CMD if [ "$SERVE_CLIENT" == "true" ] ; then NODE_ENV=test yarn test && yarn run app:build && yarn run server:start ; else NODE_ENV=test yarn test && yarn run server:start ; fi

+ 12 - 2
test/api/_test_setup_start.js

@@ -4,9 +4,19 @@ const fs = require('fs-extra')
 const path = require('path')
 const path = require('path')
 
 
 const setup = async () => {
 const setup = async () => {
+  console.log('Running pre-tests script...')
+
   const testDir = path.resolve(__dirname, '..')
   const testDir = path.resolve(__dirname, '..')
-  await fs.remove(path.resolve(testDir, 'images'))
-  await fs.copy(path.resolve(testDir, 'images_test'), path.resolve(testDir, 'images'))
+  const imagesTestDir = path.resolve(testDir, 'images_test')
+  const imagesDir = path.resolve(testDir, 'images')
+
+  console.log('Removing /test/images directory...')
+  await fs.remove(imagesDir)
+
+  console.log('Copying /test/images_test directory to /test/images...')
+  await fs.copy(imagesTestDir, imagesDir)
+
+  console.log('Pre-tests script finished. Running tests...')
 }
 }
 
 
 setup()
 setup()

+ 8 - 1
test/api/_test_setup_stop.js

@@ -4,8 +4,15 @@ const fs = require('fs-extra')
 const path = require('path')
 const path = require('path')
 
 
 const setup = async () => {
 const setup = async () => {
+  console.log('Tests ran successfully. Running post-tests script...')
+
   const testDir = path.resolve(__dirname, '..')
   const testDir = path.resolve(__dirname, '..')
-  await fs.remove(path.resolve(testDir, 'images'))
+  const imagesDir = path.resolve(testDir, 'images')
+
+  console.log('Removing /test/images directory...')
+  await fs.remove(imagesDir)
+
+  console.log('Post-tests script finished.')
 }
 }
 
 
 setup()
 setup()