`
sillycat
  • 浏览: 2539485 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Circle CI build Project

 
阅读更多
Circle CI build Project

Recently our company start to use Circle CI to build and deploy our projects instead of Jenkins. Frankly speaking, I am an old man. I use jenkins a lot, I used to be a “DevOps” for sometime, I am a developer for 15 years, so I know in detail how these codes are compile and build to projects, so I think I am a better “DevOps”, haha. Ok, let’s try Circle CI, new tools should always be easier than old ones.

I put a .circleci directory under the GitHub project, add a config.yml according to the official document.

version: 2
jobs:
build:
  machine: true 
  enviroment:
   WORKSPACE: /home/circleci/repo
   VERSION: 1.4
  steps: 
    - checkout
    - run: make prepare
    - run: make build
    - run: make run-dev
    - run: make run-stage
    - run: make run-prod
    - run:
      name: Install awscli
      command: sudo pip install awscli
    - run:
      name: Deploy to S3
      command: aws s3 sync ./dist/ s3://sillycat.artifacts/services.xxxxxxx --region us-west-1 --acl public-read

I am not that totally understand these, but I just take some other projects as example. My build step begins from checkout source codes, and run a lot of shell scripts, finally it install awscli and upload the binary to S3.

Different ways to deploy
https://circleci.com/docs/2.0/deployment-integrations/#aws

Using variable
https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-project

We can integrate and use Jfrog Artifactory as well
http://sillycat.iteye.com/blog/2431253

Another Example Project
config.yml
defaults: &defaults
  working_directory: ~/repo
  docker:
      # specify the version you desire here
      - image: circleci/node:8.11.1
        environment:
          WORKSPACE: /home/circleci/repo

version: 2
jobs:
  build:
    <<: *defaults
    steps:
      - checkout

      - run:
          name: Write NPM Token to ~/.npmrc
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

      - run:
          name: Install global dependencies
          command: sudo npm i -g serverless@latest webpack webpack-dev-server gulp @types/node typescript

      - run:
          name: Old Build Script
          command: ./build.sh stage

  deploy-to-recording-prod:
    <<: *defaults
    steps:
      - checkout

      - run:
          name: Write NPM Token to ~/.npmrc
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

      - run:
          name: Install global dependencies
          command: sudo npm i -g serverless@latest webpack webpack-dev-server gulp @types/node typescript

      - run:
          name: Old Build Script
          command: ./build.sh prod


workflows:
  version: 2

  build-n-publish:
    jobs:
      - build:
          context: aws-staging
          filters:
            branches:
              only: /master/
      - recording-prod-approval:
          type: approval
          requires:
            - build
          context: aws-staging
      - deploy-to-recording-prod:
          requires:
            - recording-prod-approval
          context: aws-production
          filters:
            branches:
              only: /master/

build.sh is as follow
#!/usr/bin/env bash

STAGE=$1

# the following is from: https://circleci.com/docs/2.0/using-shell-scripts/
# Exit script if you try to use an uninitialized variable.
set -o nounset
# Exit script if a statement returns a non-true return value.
set -o errexit
# Use the error status of the first failure, rather than that of the last item in a pipeline.
set -o pipefail

# get current versions
node --version
npm --version



# # AWS Prod
# set +x
# export AWS_ACCESS_KEY_ID=$PROMOTED_AWS_ACCESS_KEY_ID_PROD
# export AWS_SECRET_ACCESS_KEY=$PROMOTED_AWS_SECRET_ACCESS_KEY_PROD
# export AWS_DEFAULT_REGION=us-west-2
# set -x

# npm i -g serverless@latest webpack webpack-dev-server gulp || exit 1

cd ${WORKSPACE}/auth || exit 1
npm install || exit 1
#aws sns create-topic --name user-clientapi-prod-crud || exit 1
serverless deploy --force --stage $STAGE || exit 1                             
#aws dynamodb put-item --table-name sillycatproxy__rpc_map_prod --item '{"call":{"S": “sillycat.user" },"endpoint":{ "S": "arn:aws:lambda:us-west-2:xxxxxxx:function:user-clientapi-prod-handler"}}' --region=us-west-2 || exit 1



References:
https://circleci.com
https://circleci.com/docs/2.0/deployment-integrations/#aws
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics