diff --git a/._gitlab-ci.elife.yml b/._gitlab-ci.elife.yml new file mode 100644 index 0000000000000000000000000000000000000000..9b924f5105128597317114085da28b747876d8c7 --- /dev/null +++ b/._gitlab-ci.elife.yml @@ -0,0 +1,273 @@ +variables: + IMAGE_ORG: kotahi + IMAGE_NAME: kotahi + ELIFE_SERVER_IP: 54.87.88.111 + +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/elife.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 \ + --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_ELIFE + - 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 $ELIFE_SERVER_IP >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - | + ssh ubuntu@$ELIFE_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 + INSTANCE_NAME: elife + services: + - postgres + +.script_template: &run_script_template + - cd ${HOME} + - apt-get -y install postgresql-client + # this is needed for pgboss initial setup + - 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:$TEST_ITEM + +test-chrome: + <<: *run_test_template + variables: + TEST_ITEM: elife + script: + - *run_script_template + +# .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 +# # this is used to ignore self signed certs +# START_SERVER_AND_TEST_INSECURE: 1 +# INSTANCE_NAME: elife +# services: +# - postgres + +# #.script_template: &run_script_template +# # - cd ${HOME} +# # - apt-get -y install postgresql-client +# # # this is needed for pgboss initial setup +# # - 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:$TEST_ITEM + +# test-chrome: +# <<: *run_test_template +# variables: +# TEST_ITEM: elife +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:elife + +# test-chrome-samsung: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:elife:samsung + +# test-chrome-samsung-tablet: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:elife:samsung:tablet + +# test-chrome-iPhone: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:elife:iPhone + +# test-chrome-iPhone-tablet: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:elife:iPhone:tablet + +# test-chrome-hd-laptop: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:elife:hd:laptop + +# test-firefox: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:firefox:elife + +# test-firefox-samsung: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:firefox:elife:samsung + +# test-firefox-samsung-tablet: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:firefox:elife:samsung:tablet + +# test-firefox-iPhone: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:firefox:elife:iPhone + +# test-firefox-iPhone-tablet: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:firefox:elife:iPhone:tablet + +# test-firefox-hd-laptop: +# <<: *run_test_template +# script: +# - cd ${HOME} +# - apt-get -y install postgresql-client +# # this is needed for pgboss initial setup +# - 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:firefox:elife:hd:laptop \ No newline at end of file diff --git a/.gitlab-ci.elife.yml b/.gitlab-ci.elife.yml index 3b729ecbbd0c9f0f3df3b0dc57cce78aabbebfb6..773af70b97a1ff059b0a3b1ea61aa68987e938b6 100644 --- a/.gitlab-ci.elife.yml +++ b/.gitlab-ci.elife.yml @@ -78,8 +78,6 @@ lint: # used by psql PGUSER: kotahidev PGPASSWORD: kotahidev - # this is used to ignore self signed certs - #START_SERVER_AND_TEST_INSECURE: 1 INSTANCE_NAME: elife services: - postgres @@ -92,184 +90,88 @@ lint: # 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:$TEST_ITEM + - POSTGRES_HOST=postgres yarn test:all:$TEST_ITEM test-chrome: <<: *run_test_template variables: - TEST_ITEM: elife + TEST_ITEM: "chrome:elife" script: - *run_script_template -# .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 -# # this is used to ignore self signed certs -# START_SERVER_AND_TEST_INSECURE: 1 -# INSTANCE_NAME: elife -# services: -# - postgres - -# #.script_template: &run_script_template -# # - cd ${HOME} -# # - apt-get -y install postgresql-client -# # # this is needed for pgboss initial setup -# # - 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:$TEST_ITEM - -# test-chrome: -# <<: *run_test_template -# variables: -# TEST_ITEM: elife -# script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:elife - # test-chrome-samsung: # <<: *run_test_template +# variables: +# TEST_ITEM: "chrome:elife:samsung" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:elife:samsung +# - *run_script_template # test-chrome-samsung-tablet: # <<: *run_test_template +# variables: +# TEST_ITEM: "chrome:elife:samsung:tablet" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:elife:samsung:tablet +# - *run_script_template # test-chrome-iPhone: # <<: *run_test_template +# variables: +# TEST_ITEM: "chrome:elife:iPhone" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:elife:iPhone +# - *run_script_template # test-chrome-iPhone-tablet: # <<: *run_test_template +# variables: +# TEST_ITEM: "chrome:elife:iPhone:tablet" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:elife:iPhone:tablet +# - *run_script_template # test-chrome-hd-laptop: # <<: *run_test_template +# variables: +# TEST_ITEM: "chrome:elife:hd:laptop" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:elife:hd:laptop +# - *run_script_template # test-firefox: # <<: *run_test_template +# variables: +# TEST_ITEM: "firefox:elife" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:firefox:elife +# - *run_script_template # test-firefox-samsung: # <<: *run_test_template +# variables: +# TEST_ITEM: "firefox:elife:samsung" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:firefox:elife:samsung +# - *run_script_template # test-firefox-samsung-tablet: # <<: *run_test_template +# variables: +# TEST_ITEM: "firefox:elife:samsung:tablet" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:firefox:elife:samsung:tablet +# - *run_script_template # test-firefox-iPhone: # <<: *run_test_template +# variables: +# TEST_ITEM: "firefox:elife:iPhone" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:firefox:elife:iPhone +# - *run_script_template # test-firefox-iPhone-tablet: # <<: *run_test_template +# variables: +# TEST_ITEM: "firefox:elife:iPhone:tablet" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:firefox:elife:iPhone:tablet +# - *run_script_template # test-firefox-hd-laptop: # <<: *run_test_template +# variables: +# TEST_ITEM: "firefox:elife:hd:laptop" # script: -# - cd ${HOME} -# - apt-get -y install postgresql-client -# # this is needed for pgboss initial setup -# - 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:firefox:elife:hd:laptop \ No newline at end of file +# - *run_script_template