diff --git a/.gitignore b/.gitignore index 4ca00931a3a2ee5cca3d1a0e3f0af3c49ecffe37..9f57917d7a6dc4f6a6facb99d7025b77f1aa117f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ config/local*.* config/*.env minio/data/* minio\data\* +db-data\* +db-data/* diff --git a/.gitlab-ci.elife.yml b/.gitlab-ci.elife.yml index 8df426f6de84cd2d292237534a2506bcfc803702..6862fa450390509a485cb992a35dd75cf2810f6d 100644 --- a/.gitlab-ci.elife.yml +++ b/.gitlab-ci.elife.yml @@ -1,7 +1,6 @@ variables: IMAGE_ORG: kotahi IMAGE_NAME: kotahi - ELIFE_SERVER_IP: 54.87.88.111 stages: - build diff --git a/.gitlab-ci.ncrc.yml b/.gitlab-ci.ncrc.yml new file mode 100644 index 0000000000000000000000000000000000000000..b273b60c94afc847dcd049757e881f4982a587fb --- /dev/null +++ b/.gitlab-ci.ncrc.yml @@ -0,0 +1,109 @@ +variables: + IMAGE_ORG: kotahi + IMAGE_NAME: kotahi + +stages: + - build + - deploy + - test + +build: + image: docker:20.10.5 + variables: + DOCKER_BUILDKIT: 1 + services: + - docker:20.10.5-dind + stage: build + before_script: + - cp app/brand-instances-configs/ncrc.json app/brandConfig.json + script: + - | + if [ -z "$DOCKERHUB_USERNAME_ELIFE" ] || [ -z "$DOCKERHUB_PASSWORD_ELIFE" ]; then echo "Not pushing" && exit 0; fi + docker login -u $DOCKERHUB_USERNAME_ELIFE -p $DOCKERHUB_PASSWORD_ELIFE + docker pull $IMAGE_ORG/$IMAGE_NAME:latest || true + docker build \ + --build-arg instance_name=ncrc \ + --file ./Dockerfile-production \ + --cache-from $CI_REGISTRY_IMAGE:latest \ + --tag $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA \ + --tag $IMAGE_ORG/$IMAGE_NAME:latest . + docker build --file ./Dockerfile-ci --cache-from $IMAGE_ORG/$IMAGE_NAME-dev:latest --tag $IMAGE_ORG/$IMAGE_NAME-dev:$CI_COMMIT_SHA --tag $IMAGE_ORG/$IMAGE_NAME-dev:latest . + docker push $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA + docker push $IMAGE_ORG/$IMAGE_NAME:latest + docker push $IMAGE_ORG/$IMAGE_NAME-dev:$CI_COMMIT_SHA + docker push $IMAGE_ORG/$IMAGE_NAME-dev:latest + +deploy: + stage: deploy + image: docker:19.03.13 + before_script: + - export SSH_KEY=$SSH_KEY_NCRC + - export DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME_ELIFE + - export DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD_ELIFE + - export IMAGE_ORG=$IMAGE_ORG + - export IMAGE_NAME=$IMAGE_NAME + - eval $(ssh-agent -s) + - echo "$SSH_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan $NCRC_SERVER_IP >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - | + ssh ubuntu@$NCRC_SERVER_IP "sudo docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD && + sudo docker pull $IMAGE_ORG/$IMAGE_NAME:latest && + sudo supervisorctl stop kotahi && + cd /home/ubuntu/kotahi && + sudo docker-compose down && + sudo supervisorctl start kotahi" + +# lint: +# allow_failure: true +# image: $IMAGE_ORG/$IMAGE_NAME-dev:$CI_COMMIT_SHA +# stage: test +# variables: +# GIT_STRATEGY: none +# script: +# - cd ${HOME} +# - npm run lint + +.test_template: &run_test_template + image: $IMAGE_ORG/$IMAGE_NAME-dev:$CI_COMMIT_SHA + stage: test + variables: + GIT_STRATEGY: none + # setup data for postgres image + POSTGRES_USER: kotahidev + POSTGRES_PASSWORD: kotahidev + # used by psql + PGUSER: kotahidev + PGPASSWORD: kotahidev + services: + - postgres + +test-chrome: + image: $IMAGE_ORG/$IMAGE_NAME-dev:$CI_COMMIT_SHA + stage: test + variables: + GIT_STRATEGY: none + # setup data for postgres image + POSTGRES_USER: kotahidev + POSTGRES_PASSWORD: kotahidev + # used by psql + PGUSER: kotahidev + PGPASSWORD: kotahidev + # this is used to ignore self signed certs + #START_SERVER_AND_TEST_INSECURE: 1 + services: + - postgres + script: + - cd ${HOME} + - apt-get -y install postgresql-client + # this is needed for pgboss initial setup + - hostname + - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;" + # use the example env for tests + - cp .env.example .env + # specify host here else it confuses the linked postgres image + - POSTGRES_HOST=postgres yarn test:all:chrome:ncrc + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc2862fcdb6c7e1f7428d7ea00eef6bc11bc2fb9..f6193f59aa7349b670c552e08b95cf4c0036a8b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,6 +11,16 @@ elife-pipeline: - local: .gitlab-ci.elife.yml strategy: depend +ncrc-pipeline: + only: + refs: + - main + stage: run-pipeline + trigger: + include: + - local: .gitlab-ci.ncrc.yml + strategy: depend + coko-pipeline: stage: run-pipeline trigger: diff --git a/app/brand-instances-configs/ncrc.json b/app/brand-instances-configs/ncrc.json new file mode 100644 index 0000000000000000000000000000000000000000..6ec62ecd16751dcc48f48473e309ceb9c2264320 --- /dev/null +++ b/app/brand-instances-configs/ncrc.json @@ -0,0 +1,6 @@ +{ + "logoPath": "/public/logo-ncrc.svg", + "primaryColor": "#0A9DD9", + "secondaryColor": "#0A9DD9", + "brandName": "NCRC" +} diff --git a/docker-compose.production.ncrc.yml b/docker-compose.production.ncrc.yml new file mode 100644 index 0000000000000000000000000000000000000000..1265a0d861b0ad48a576d62c47768eb4a88f01b0 --- /dev/null +++ b/docker-compose.production.ncrc.yml @@ -0,0 +1,86 @@ +version: '3' + +services: + server: + image: kotahi/kotahi:latest + depends_on: + - db + ports: + - ${SERVER_PORT:-3000}:${SERVER_PORT:-3000} + environment: + - NODE_ENV=${NODE_ENV:-production} + - POSTGRES_HOST=${POSTGRES_HOST:-db} + - POSTGRES_PORT=${POSTGRES_PORT:-5432} + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - PUBSWEET_SECRET=${PUBSWEET_SECRET} + - CLIENT_PROTOCOL=${CLIENT_PROTOCOL} + - CLIENT_HOST=${CLIENT_HOST} + - CLIENT_PORT=${CLIENT_PORT} + - PUBLIC_CLIENT_HOST=${PUBLIC_CLIENT_HOST:-0.0.0.0} + - SERVER_PROTOCOL=${SERVER_PROTOCOL} + - SERVER_HOST=${SERVER_HOST} + - SERVER_PORT=${SERVER_PORT} + - ORCID_CLIENT_ID=${ORCID_CLIENT_ID} + - ORCID_CLIENT_SECRET=${ORCID_CLIENT_SECRET} + - USE_SANDBOXED_ORCID=${USE_SANDBOXED_ORCID:-false} + - ORCID_AUTH_REDIRECT_PORT=${ORCID_AUTH_REDIRECT_PORT:-4000} + - ORCID_AUTH_REDIRECT_HOSTNAME=${ORCID_AUTH_REDIRECT_HOSTNAME:-localhost} + - ORCID_AUTH_REDIRECT_PROTOCOL=${ORCID_AUTH_REDIRECT_PROTOCOL:-http} + - INSTANCE_NAME=${INSTANCE_NAME:-ncrc} + entrypoint: + [ + 'bash', + './scripts/wait-for-it.sh', + '${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}', + '--', + 'sh', + 'scripts/setupProdServer.sh', + ] + command: ['node', './startServer.js'] + db: + image: postgres:10-alpine + ports: + - ${POSTGRES_PORT:-5432}:5432 + environment: + - POSTGRES_USER + - POSTGRES_DB + - POSTGRES_PASSWORD + - PGDATA=/var/lib/postgresql/data/kotahi + volumes: + - ./scripts/test.sql:/docker-entrypoint-initdb.d/test.sql + - ./db-data:/var/lib/postgresql/data/kotahi:z + + job-xsweet: + image: pubsweet/job-xsweet:1.5.0 + environment: + - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST:-db}:${POSTGRES_PORT}/${POSTGRES_DB} + depends_on: + - server + command: + [ + 'bash', + './scripts/wait-for-it.sh', + 'server:${SERVER_PORT}', + --, + 'node', + 'src/xsweet.js', + ] + volumes: + - ./scripts/wait-for-it.sh:/home/node/scripts/wait-for-it.sh + + minio: + image: minio/minio + command: ['server', '/data'] + volumes: + - ./minio/data:/data + ports: + - 9000:9000 + environment: + MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:-test} #Access key length should be at least 3 characters + MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-password} #Secret key length should be at least 8 characters + +volumes: + db-data: + driver: local \ No newline at end of file