diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 4f4db310e..0739729b5 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -509,16 +509,13 @@ jobs:
##########################################################################
# UNIT TESTS BACKEND #####################################################
##########################################################################
- - name: backend | docker-compose
+ - name: backend | docker-compose mariadb
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb
- name: Sleep for 30 seconds
run: sleep 30s
shell: bash
- name: backend | docker-compose database
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database
- - name: Sleep for 30 seconds
- run: sleep 30s
- shell: bash
- name: backend Unit tests | test
run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test
# run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T backend yarn test
diff --git a/backend/package.json b/backend/package.json
index 710d73a8c..79e5fd130 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -60,12 +60,12 @@
"typescript": "^4.3.4"
},
"_moduleAliases": {
- "@": "./src",
- "@arg": "./src/graphql/arg",
+ "@": "./build/src",
+ "@arg": "./build/src/graphql/arg",
"@dbTools": "../database/build/src",
"@entity": "../database/build/entity",
- "@enum": "./src/graphql/enum",
- "@model": "./src/graphql/model",
- "@repository": "./src/typeorm/repository"
+ "@enum": "./build/src/graphql/enum",
+ "@model": "./build/src/graphql/model",
+ "@repository": "./build/src/typeorm/repository"
}
}
diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts
index 05ff2b302..fd0936b9a 100644
--- a/backend/src/graphql/resolver/UserResolver.test.ts
+++ b/backend/src/graphql/resolver/UserResolver.test.ts
@@ -1,11 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
-import { testEnvironment, resetEntities, createUser } from '@test/helpers'
+import { testEnvironment, createUser, headerPushMock, cleanDB } from '@test/helpers'
import { createUserMutation, setPasswordMutation } from '@test/graphql'
import gql from 'graphql-tag'
import { GraphQLError } from 'graphql'
-import { resetDB } from '@dbTools/helpers'
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
import { User } from '@entity/User'
import CONFIG from '@/config'
@@ -30,29 +29,18 @@ jest.mock('@/apis/KlicktippController', () => {
})
*/
-let token: string
-
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-const headerPushMock = jest.fn((t) => (token = t.value))
-
-const context = {
- setHeaders: {
- push: headerPushMock,
- forEach: jest.fn(),
- },
-}
-
let mutate: any, query: any, con: any
beforeAll(async () => {
- const testEnv = await testEnvironment(context)
+ const testEnv = await testEnvironment()
mutate = testEnv.mutate
query = testEnv.query
con = testEnv.con
+ await cleanDB()
})
afterAll(async () => {
- await resetDB(true)
+ await cleanDB()
await con.close()
})
@@ -75,7 +63,7 @@ describe('UserResolver', () => {
})
afterAll(async () => {
- await resetEntities([User, LoginEmailOptIn])
+ await cleanDB()
})
it('returns success', () => {
@@ -213,7 +201,7 @@ describe('UserResolver', () => {
})
afterAll(async () => {
- await resetEntities([User, LoginEmailOptIn])
+ await cleanDB()
})
it('sets email checked to true', () => {
@@ -256,7 +244,7 @@ describe('UserResolver', () => {
})
afterAll(async () => {
- await resetEntities([User, LoginEmailOptIn])
+ await cleanDB()
})
it('throws an error', () => {
@@ -282,7 +270,7 @@ describe('UserResolver', () => {
})
afterAll(async () => {
- await resetEntities([User, LoginEmailOptIn])
+ await cleanDB()
})
it('throws an error', () => {
@@ -323,7 +311,7 @@ describe('UserResolver', () => {
let result: User
afterAll(async () => {
- await resetEntities([User, LoginEmailOptIn])
+ await cleanDB()
})
describe('no users in database', () => {
@@ -353,7 +341,7 @@ describe('UserResolver', () => {
})
afterAll(async () => {
- await resetEntities([User, LoginEmailOptIn])
+ await cleanDB()
})
it('returns the user object', () => {
diff --git a/backend/test/helpers.ts b/backend/test/helpers.ts
index f3588cd43..1048b16b7 100644
--- a/backend/test/helpers.ts
+++ b/backend/test/helpers.ts
@@ -7,8 +7,28 @@ import { resetDB, initialize } from '@dbTools/helpers'
import { createUserMutation, setPasswordMutation } from './graphql'
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
import { User } from '@entity/User'
+import { entities } from '@entity/index'
-export const testEnvironment = async (context: any) => {
+let token = ''
+
+export const headerPushMock = jest.fn((t) => (token = t.value))
+
+const context = {
+ token,
+ setHeaders: {
+ push: headerPushMock,
+ forEach: jest.fn(),
+ },
+}
+
+export const cleanDB = async () => {
+ // this only works as lond we do not have foreign key constraints
+ for (let i = 0; i < entities.length; i++) {
+ await resetEntity(entities[i])
+ }
+}
+
+export const testEnvironment = async () => {
const server = await createServer(context)
const con = server.con
const testClient = createTestClient(server.apollo)
@@ -27,12 +47,6 @@ export const resetEntity = async (entity: any) => {
}
}
-export const resetEntities = async (entities: any[]) => {
- for (let i = 0; i < entities.length; i++) {
- await resetEntity(entities[i])
- }
-}
-
export const createUser = async (mutate: any, user: any) => {
await mutate({ mutation: createUserMutation, variables: user })
const dbUser = await User.findOne({ where: { email: user.email } })
diff --git a/deployment/bare_metal/logrotate/gradido.conf.template b/deployment/bare_metal/logrotate/gradido.conf.template
index c038f8e75..c543b54c2 100644
--- a/deployment/bare_metal/logrotate/gradido.conf.template
+++ b/deployment/bare_metal/logrotate/gradido.conf.template
@@ -1,4 +1,4 @@
-$GRADIDO_LOG_PATH/* {
+$GRADIDO_LOG_PATH/*.log {
weekly
rotate 26
size 10M
diff --git a/deployment/bare_metal/nginx/update-page/updating.html.template b/deployment/bare_metal/nginx/update-page/updating.html.template
index a88a40b0f..cc6d7debb 100644
--- a/deployment/bare_metal/nginx/update-page/updating.html.template
+++ b/deployment/bare_metal/nginx/update-page/updating.html.template
@@ -1,3 +1,4 @@
-Gradido is currently updating...
-please stand by and try again in some minutes
-
\ No newline at end of file
+
+Gradido is currently updating... +please stand by and try again in some minutes + diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 616e4b8ab..250971419 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -42,30 +42,38 @@ if [ -f $LOCK_FILE ] ; then fi touch $LOCK_FILE +# find today string +TODAY=$(date +"%Y-%m-%d") + # Create a new updating.html from the template \cp $SCRIPT_DIR/nginx/update-page/updating.html.template $UPDATE_HTML +# redirect all output of the script to the UPDATE_HTML and also have things on console +# TODO: this might pose a security risk +exec > >(tee -a $UPDATE_HTML) 2>&1 + # configure nginx for the update-page -echo 'Configuring nginx to serve the update-page
' >> $UPDATE_HTML +echo 'Configuring nginx to serve the update-page' >> $UPDATE_HTML rm /etc/nginx/sites-enabled/gradido.conf ln -s /etc/nginx/sites-available/update-page.conf /etc/nginx/sites-enabled/ sudo /etc/init.d/nginx restart # stop all services -echo 'Stopping all Gradido services
' >> $UPDATE_HTML +echo 'Stopping all Gradido services' >> $UPDATE_HTML pm2 stop all # git BRANCH=${1:-master} -echo "Starting with git pull - branch:$BRANCH
" >> $UPDATE_HTML +echo "Starting with git pull - branch:$BRANCH" >> $UPDATE_HTML cd $PROJECT_ROOT -git fetch origin $BRANCH +# TODO: this overfetches alot, but ensures we can use start.sh with tags +git fetch origin --all git checkout $BRANCH git pull export BUILD_COMMIT="$(git rev-parse HEAD)" # Generate gradido.conf from template -echo 'Generate new gradido nginx config
' >> $UPDATE_HTML +echo 'Generate new gradido nginx config' >> $UPDATE_HTML case "$NGINX_SSL" in true) TEMPLATE_FILE="gradido.conf.ssl.template" ;; *) TEMPLATE_FILE="gradido.conf.template" ;; @@ -73,7 +81,7 @@ esac envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf # Generate update-page.conf from template -echo 'Generate new update-page nginx config
' >> $UPDATE_HTML +echo 'Generate new update-page nginx config' >> $UPDATE_HTML case "$NGINX_SSL" in true) TEMPLATE_FILE="update-page.conf.ssl.template" ;; *) TEMPLATE_FILE="update-page.conf.template" ;; @@ -91,7 +99,7 @@ envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/frontend/.env envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/admin/.env.template > $PROJECT_ROOT/admin/.env # Install & build database -echo 'Updating database
' >> $UPDATE_HTML +echo 'Updating database' >> $UPDATE_HTML cd $PROJECT_ROOT/database yarn install yarn build @@ -104,7 +112,7 @@ else fi # Install & build backend -echo 'Updating backend
' >> $UPDATE_HTML +echo 'Updating backend' >> $UPDATE_HTML cd $PROJECT_ROOT/backend # TODO maybe handle this differently? unset NODE_ENV @@ -113,11 +121,11 @@ yarn build # TODO maybe handle this differently? export NODE_ENV=production pm2 delete gradido-backend -pm2 start --name gradido-backend "yarn --cwd $PROJECT_ROOT/backend start" -l $GRADIDO_LOG_PATH/pm2.backend.log --log-date-format 'DD-MM HH:mm:ss.SSS' +pm2 start --name gradido-backend "yarn --cwd $PROJECT_ROOT/backend start" -l $GRADIDO_LOG_PATH/pm2.backend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save # Install & build frontend -echo 'Updating frontend
' >> $UPDATE_HTML +echo 'Updating frontend' >> $UPDATE_HTML cd $PROJECT_ROOT/frontend # TODO maybe handle this differently? unset NODE_ENV @@ -126,11 +134,11 @@ yarn build # TODO maybe handle this differently? export NODE_ENV=production pm2 delete gradido-frontend -pm2 start --name gradido-frontend "yarn --cwd $PROJECT_ROOT/frontend start" -l $GRADIDO_LOG_PATH/pm2.frontend.log --log-date-format 'DD-MM HH:mm:ss.SSS' +pm2 start --name gradido-frontend "yarn --cwd $PROJECT_ROOT/frontend start" -l $GRADIDO_LOG_PATH/pm2.frontend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save # Install & build admin -echo 'Updating admin
' >> $UPDATE_HTML +echo 'Updating admin' >> $UPDATE_HTML cd $PROJECT_ROOT/admin # TODO maybe handle this differently? unset NODE_ENV @@ -139,14 +147,17 @@ yarn build # TODO maybe handle this differently? export NODE_ENV=production pm2 delete gradido-admin -pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.log --log-date-format 'DD-MM HH:mm:ss.SSS' +pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save # let nginx showing gradido -echo 'Configuring nginx to serve gradido again
' >> $UPDATE_HTML +echo 'Configuring nginx to serve gradido again' >> $UPDATE_HTML ln -s /etc/nginx/sites-available/gradido.conf /etc/nginx/sites-enabled/ rm /etc/nginx/sites-enabled/update-page.conf sudo /etc/init.d/nginx restart +# keep the update log +cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log + # release lock rm $LOCK_FILE \ No newline at end of file