{"id":1175,"date":"2019-06-20T17:40:10","date_gmt":"2019-06-20T14:40:10","guid":{"rendered":"https:\/\/artem.services\/?p=1175"},"modified":"2019-06-25T18:21:31","modified_gmt":"2019-06-25T15:21:31","slug":"circleci-node-js-%d1%81%d0%b0%d0%b9%d1%82-%d0%b4%d0%b5%d0%bf%d0%bb%d0%be%d0%b9-%d0%bd%d0%b0-s3","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1175","title":{"rendered":"CircleCI &#8212; node.js \u0441\u0430\u0439\u0442 \u0434\u0435\u043f\u043b\u043e\u0439 \u043d\u0430 AWS S3 Bucket"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-1198 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/06\/circleci-logo.png\" alt=\"\" width=\"389\" height=\"129\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/06\/circleci-logo.png 389w, https:\/\/artem.services\/wp-content\/uploads\/2019\/06\/circleci-logo-300x99.png 300w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0431\u043e\u0440\u043a\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 <strong>node.js<\/strong>, \u0434\u0435\u043f\u043b\u043e\u0439 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u043e\u0432 \u0432 <strong>S3 Bucket<\/strong> \u0438 \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043a\u0435\u0448\u0430 \u0432 <strong>CloudFront<\/strong>&#39;\u0435.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nversion: 2\r\njobs:\r\n  build:\r\n    working_directory: ~\/source\r\n    docker:\r\n      - image: circleci\/node:10\r\n    steps:\r\n      - checkout\r\n      - restore_cache: # special step to restore the dependency cache\r\n          key: dependency-cache-{{ checksum &quot;package.json&quot; }}\r\n      - run:\r\n          name: Replace ENV file\r\n          command: cp .env.staging .env\r\n      - run:\r\n          name: Setup Dependencies\r\n          command: yarn\r\n      - run:\r\n          name: Build static files\r\n          command: yarn build\r\n      - persist_to_workspace:\r\n          root: ~\/source\r\n          paths:\r\n            - .\r\n\r\n  deploy:\r\n    docker:\r\n      - image: circleci\/python:2.7\r\n    working_directory: ~\/source\r\n    environment:\r\n      BUCKET: artem-services-bucket\r\n      DISTRIBUTION_ID: XXXXXXXXXXXXX\r\n    steps:\r\n      - attach_workspace:\r\n          at: ~\/source\r\n      - run:\r\n          name: Install AWS Cli\r\n          command: sudo pip install awscli\r\n      - run:\r\n          name: Deploy\r\n          command: aws s3 sync build\/ s3:\/\/${BUCKET} --region eu-central-1 --delete\r\n      - run:\r\n          name: CloudFront invalidation\r\n          command: aws cloudfront create-invalidation --distribution-id=${DISTRIBUTION_ID} --paths '\/index.html'\r\n\r\nworkflows:\r\n  version: 2\r\n  build-and-deploy:\r\n    jobs:\r\n      - build:\r\n          filters:\r\n            branches:\r\n              only: staging\r\n      - deploy:\r\n          requires:\r\n            - build\r\n          filters:\r\n            branches:\r\n              only: staging\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435:<\/p>\n<ul>\n<li>AWS_ACCESS_KEY_ID<\/li>\n<li>AWS_SECRET_ACCESS_KEY<\/li>\n<\/ul>\n<p>\u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <strong>CircleCI<\/strong>, \u0432 \u0446\u0435\u043b\u044f\u0445 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>IAM Policy<\/strong> \u0434\u043b\u044f \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043a\u0435\u0448\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/artem.services\/?p=1173\" target=\"_blank\" rel=\"noopener noreferrer\">\u0442\u0443\u0442<\/a>.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0431\u043e\u0440\u043a\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 node.js, \u0434\u0435\u043f\u043b\u043e\u0439 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u043e\u0432 \u0432 S3 Bucket \u0438 \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043a\u0435\u0448\u0430 \u0432 CloudFront&#39;\u0435. &nbsp; \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 CircleCI, \u0432 \u0446\u0435\u043b\u044f\u0445 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. &nbsp; IAM Policy \u0434\u043b\u044f \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043a\u0435\u0448\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[37],"tags":[25,27,39,923,919,925,35],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1175"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1175"}],"version-history":[{"count":5,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1175\/revisions"}],"predecessor-version":[{"id":1202,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1175\/revisions\/1202"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}