用Github Action 做了一個簡單的CI/CD,這一次我上傳cloudformation的 yaml文件,首先把他推送到我的一個S3 Bucket裏面,然後利用這個yaml文件來生成對應的服務。
https://github.com/vetpartner/cf
workflow 文件如下所示,首先checkout,然後檢測cloudformation的語法,然後通過secret的值進行aws的登錄驗證,然後拷貝文件,然後配置cloudformation。Github action上有其他人寫好的各種action來進行各種高大上的操作,我這裏是直接用aws cli進行的操作
# This is a basic workflow to help you get started with Actions
name: aws
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches:
- master
jobs:
deploy:
name: Upload to Amazon
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check cloudformation yaml file
uses: scottbrenner/cfn-lint-action@master
with:
args: "*.yaml"
- name: Configure AWS credentials from Production account
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-2
- name: Copy files to the production website with the AWS CLI
run: |
aws s3 sync . s3://yuanlitest
- name: Deploy to AWS CloudFormation
run: aws cloudformation create-stack --stack-name myteststack2 --template-body file://vpc.yaml --parameter ParameterKey=S3BucketName,ParameterValue=githubtestcicds3bucket1 ParameterKey=UserName,ParameterValue=githubuser1 ParameterKey=PolicyName,ParameterValue=githubtests3bucket1 --capabilities CAPABILITY_NAMED_IAM
可以看見我的cf成功執行了