From 5f018f03b9b52eee8ab753515f9d5b15755138ae Mon Sep 17 00:00:00 2001 From: Alexander G Date: Wed, 5 Sep 2018 18:45:00 +0300 Subject: [PATCH] Setup auto deployment via CircleCI #19 --- .circleci/config.yml | 30 ++++++++++++++++++++++++++---- deploy-circleci.sh | 9 +++++++++ deploy.sh | 4 ---- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 deploy-circleci.sh delete mode 100644 deploy.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 83e596b..58ea1c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 # List of jobs jobs: # The build and test job - build_and_test: + build-test: working_directory: ~/angular-universal docker: - image: circleci/node:8.9.0-browsers @@ -54,10 +54,32 @@ jobs: - run: name: Unit Testing command: cd project/application && npm run test -- --watch=false + # The deploy job + deploy: + machine: + enabled: true + environment: + FINGERPRINT: 8c:c8:d3:84:56:47:d7:28:13:2a:d8:2b:4e:53:0e:c0 + SSH_USER: la + SSH_HOST: angular-universal.lazy-ants.com + steps: + - add_ssh_keys: + fingerprints: + - "$FINGERPRINT" #https://circleci.com/docs/2.0/add-ssh-key + - run: + name: Deploy Over SSH + command: | + ssh $SSH_USER@$SSH_HOST "cd /var/www/angular-universal && bash deploy-circleci.sh" workflows: version: 2 - # The build and test - build_and_test: + # The build, test and deploy + build-test_deploy: jobs: - - build_and_test + - build-test + - deploy: + requires: + - build-test + filters: + branches: + only: master diff --git a/deploy-circleci.sh b/deploy-circleci.sh new file mode 100644 index 0000000..6c69dae --- /dev/null +++ b/deploy-circleci.sh @@ -0,0 +1,9 @@ +echo 'Before checkout' +git status +git checkout -- . +echo 'After checkout' +git pull origin master +docker-compose up -d --build +docker exec -i angular-universal_nodejs npm install +docker exec -i angular-universal_nodejs bash -c 'npm run build:ssr' +docker exec -i angular-universal_nodejs bash -c 'npm run serve:ssr' diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index fd211ca..0000000 --- a/deploy.sh +++ /dev/null @@ -1,4 +0,0 @@ -docker-compose up -d --build -docker exec -ti angular-universal_nodejs npm install -docker exec -ti angular-universal_nodejs bash -c 'npm run build:ssr' -docker exec -ti angular-universal_nodejs bash -c 'npm run serve:ssr'