Skip to content

Commit

Permalink
Merge pull request #450 from epicmaxco/introducing-CI-master
Browse files Browse the repository at this point in the history
Introducing ci master
  • Loading branch information
alexanderrudnik authored Jan 11, 2019
2 parents d3c6d66 + f35ae77 commit 61e8ddc
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 140 deletions.
130 changes: 84 additions & 46 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,92 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
aliases:
- &restore_cache
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}

- &install_dependencies
name: Install Dependencies
command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn

- &save_cache
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn

- &build |
yarn build

docker: &docker
docker:
- image: circleci/node:10.12.0

defaults: &defaults
<<: *docker
parallelism: 1
working_directory: ~/repo

version: 2
jobs:
deploy:
docker:
- image: circleci/node:10.12.0
parallelism: 1
working_directory: ~/repo
deploy-staging:
<<: *defaults
steps:
- checkout
- restore_cache: *restore_cache
- run: *install_dependencies
- save_cache: *save_cache
- run: *build
- run:
name: Deploy to hosting
command: |
tar -czf dist.tar.gz ~/repo/dist -C ~/repo/dist .
sudo apt install sshpass
ssh-keyscan -t rsa $DEPLOY_URL >> ~/.ssh/known_hosts
sshpass -p $DEPLOY_PASSWORD scp ~/repo/dist.tar.gz $DEPLOY_USER@$DEPLOY_URL:~/tmp
sshpass -p $DEPLOY_PASSWORD ssh $DEPLOY_USER@$DEPLOY_URL /bin/bash << EOF
rm -rf $DEPLOY_PATH/*
tar -xzf ~/tmp/dist.tar.gz -C $DEPLOY_PATH
rm -f ~/tmp/dist.tar.gz
EOF
deploy-production:
<<: *defaults
steps:
- checkout
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- run: yarn build
- run:
name: Deploy to hosting
# Package dist folder
# Do some hacks to be able to copy file without ssh key (only with user/password). That's not needed for normal hosting
# Copy package to tmp folder
# On remote host:
# - remove public folder contents
# - unpack bundle archive into public folder
# - remove bundle archive
command: |
tar -czf dist.tar.gz ~/repo/dist -C ~/repo/dist .
sudo apt install sshpass
ssh-keyscan -t rsa $DEPLOY_URL >> ~/.ssh/known_hosts
sshpass -p $DEPLOY_PASSWORD scp ~/repo/dist.tar.gz $DEPLOY_USER@$DEPLOY_URL:~/tmp
sshpass -p $DEPLOY_PASSWORD ssh $DEPLOY_USER@$DEPLOY_URL /bin/bash << EOF
rm -rf $DEPLOY_PATH/*
tar -xzf ~/tmp/dist.tar.gz -C $DEPLOY_PATH
rm -f ~/tmp/dist.tar.gz
EOF
- checkout
- run:
name: Add variables for Yandex Metrics and Drift live chat
command:
echo "VUE_APP_YANDEX_METRICS_KEY=$YANDEX_METRICS_KEY" >> .env.production.local &&
echo "VUE_APP_DRIFT_KEY=$DRIFT_KEY" >> .env.production.local
- restore_cache: *restore_cache
- run: *install_dependencies
- save_cache: *save_cache
- run: *build
- run:
name: Deploy to hosting
environment:
DEPLOY_PATH: /var/www/html/vuestic-admin
command: |
tar -czf dist.tar.gz ~/repo/dist -C ~/repo/dist .
ssh-keyscan -t rsa $SERVER_IP >> ~/.ssh/known_hosts
scp ~/repo/dist.tar.gz $SERVER_USER_NAME@$SERVER_IP:~/
ssh $SERVER_USER_NAME@$SERVER_IP << EOF
mkdir -p tmp
rm -rf $DEPLOY_PATH/*
tar -xzf ~/dist.tar.gz -C $DEPLOY_PATH
rm -rf ~/dist.tar.gz ~/tmp
EOF
workflows:
version: 2
build-and-deploy:
jobs:
- deploy:
filters:
branches:
only: develop
- deploy-staging:
filters:
branches:
only: develop
- deploy-production:
context: vuestic-production
filters:
branches:
only: master
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VUE_APP_YANDEX_METRICS_KEY=
VUE_APP_DRIFT_KEY=
Loading

0 comments on commit 61e8ddc

Please sign in to comment.