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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值