Пример сборки статического сайта на node.js, деплой артефактов в S3 Bucket и инвалидация кеша в CloudFront'е.
version: 2 jobs: build: working_directory: ~/source docker: - image: circleci/node:10 steps: - checkout - restore_cache: # special step to restore the dependency cache key: dependency-cache-{{ checksum "package.json" }} - run: name: Replace ENV file command: cp .env.staging .env - run: name: Setup Dependencies command: yarn - run: name: Build static files command: yarn build - persist_to_workspace: root: ~/source paths: - . deploy: docker: - image: circleci/python:2.7 working_directory: ~/source environment: BUCKET: artem-services-bucket DISTRIBUTION_ID: XXXXXXXXXXXXX steps: - attach_workspace: at: ~/source - run: name: Install AWS Cli command: sudo pip install awscli - run: name: Deploy command: aws s3 sync build/ s3://${BUCKET} --region eu-central-1 --delete - run: name: CloudFront invalidation command: aws cloudfront create-invalidation --distribution-id=${DISTRIBUTION_ID} --paths '/index.html' workflows: version: 2 build-and-deploy: jobs: - build: filters: branches: only: staging - deploy: requires: - build filters: branches: only: staging
Переменные:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
указаны в переменных CircleCI, в целях безопасности.
IAM Policy для инвалидации кеша можно посмотреть тут.