nuxt + circleciIntroduction\nWhat is CircleCi and what is it used for?\n\nCircleCi is a service that can help automate builds, tests and deployments and\ncan be used for anything, from web sites to mobile apps.\n\nWhat is it used for? Typically it alerts your if your setup fails, whether it be\nduring build, testing or development stage. CircleCi does not have to all 3, it\ncan be used for any, depending on your setup.\n\nPrerequisites\n * Sign up for a free account on CircleCi [https://circleci.com/signup/]\n * At this moment CircleCi only supports Github or Bitbucket accounts\n * In the Projects settings page, choose the repo that you will set up for.\n * Click setup.\n * This will add a .circleci/config.yml file to your repo and will commit it. At\n the same time it will run the config.\n * Congrats you have ran your first Ci.\n\nConfig\nHere is my config\n\njobs:\n test:\n executor:\n name: node/default\n tag: '10.22'\n steps:\n - checkout\n - node/install-packages:\n pkg-manager: yarn\n - run:\n name: Run tests\n command: yarn test\n deploy:\n executor:\n name: node/default\n tag: '10.22'\n steps:\n - checkout\n - node/install-yarn\n - run:\n name: Install pm2\n command: sudo yarn global add pm2\n - run:\n name: Add Cloud server to known hosts\n command: |\n ssh-keyscan <ip of server> >> ~/.ssh/known_hosts\n - run:\n name: Deploy\n command: yarn deploy\n\nversion: 2.1\norbs:\n node: firstname.lastname@example.org\nworkflows:\n test:\n jobs:\n - test\n - deploy:\n filters:\n branches:\n only:\n - master\n requires:\n - test\n\n\n\nOkay let's go through this config.\n\nversion: 2.1\norbs:\n node: email@example.com\nworkflows:\n test-deploy:\n jobs:\n - test\n - deploy:\n filters:\n branches:\n only:\n - master\n requires:\n - test\n\n\nI will be using config version 2.1 which supports orbs and workflows. An orb\n[https://circleci.com/orbs/] is like a preset such which helps simplify the\nconfig file a lot. You can still work without orbs but you would have set things\nup from scratch, like getting the image that you need, install the packages,\ncache the packages, restore the packages. The purpose of caching the packages is\nto speed up the Ci for future builds.\n\nI only have one workflow and thats to test my app and then deploy it. The deploy \njob only happens if the master branch is pushed and the deploy job can only\nhappen when the test job passes.\n\njobs:\n test:\n executor:\n name: node/default\n tag: '10.22'\n steps:\n - checkout\n - node/install-packages:\n pkg-manager: yarn\n - run:\n name: Run tests\n command: yarn test\n\n\nWith an orb I can choose the node version with the executor setting. Without\nthis you would have to define the steps to setup the right node version with an \nnvm.\n\n * checkout pulls your repo.\n * node/install-packages installs your packages using npm but you can also\n specify the package manager you want to use. This really simplifies the need\n to install yarn manually and this command also simplifies the need to define\n your own save/restore cache commands.\n * run the above steps were the build process. The next command is for running\n the tests that I have set up.\n\n deploy:\n executor:\n name: node/default\n tag: '10.22'\n steps:\n - checkout\n - node/install-yarn\n - run:\n name: Install pm2\n command: sudo yarn global add pm2\n - run:\n name: Add Cloud server to known hosts\n command: |\n ssh-keyscan <ip of server> >> ~/.ssh/known_hosts\n - run:\n name: Deploy\n command: yarn deploy\n\n\nBefore setting up deployment, make sure that you setup ssh keys for circleci. I\nwould follow the steps here under Settings\n[https://circleci.com/docs/2.0/add-ssh-key/] or another good place setup ssh is\nfrom this article on Medium\n[https://medium.com/@tomnashflex/how-we-use-circleci-with-git-and-digitalocean-to-streamline-our-deployments-49a6a02b6dd6]\n. I would follow the steps from 1-5, but I didn't create a new user for Ci on my\nserver, I just added the ssh keys to my own current user. The important thing is\nmaking sure that the ssh keys for Ci works by using\n\n$ ssh firstname.lastname@example.org -i ~/.ssh/id_rsa_circleci\n\n\nWith that all setup we can continue with the config.\n\n * executor same as before, we're using the same node version.\n * checkout pulls your repo.\n * node/install-yarn we've already previously done the building but we just need\n to install yarn\n * Install pm2 similar with the steps where we install pm2 on our local machine,\n but this time we translate this and install it on our Ci machine.\n * ssh-keyscan <ip of server> >> ~/.ssh/known_hosts replace <ip of server> with\n the IP of your server. This step is most important otherwise pm2 will not be\n able to ssh into your server.\n * yarn deploy deploys the app like we normally do locally.\n\nFinal Words\nCongrats! And with this setup we have managed to:\n\n * Add our project to CircleCi\n * Setup our config to make Ci do want we want to do\n * Run commands like running tests and deploy our app\n\nIt isn't easy getting Ci do the things you want to do and there's a fair bit of\ntrial and error. We can avoid waste our precious credits by installing a\n`Circleci cli` which can help validate our config and run our jobs locally. You\ncan find the documentations about what the cli can do here\n[https://circleci.com/docs/2.0/local-cli/#section=configuration].\n\nIf you have homebrew installed\n\n$ brew install circleci\n\n\nIf not\n\n$ curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | bash\n\n\nAnd you can use commands like\n\n$ circleci config validate .circleci/config.yml\n\n\nTo validate your config.\n\nHope this helps you kickstart your Ci journey.