{"id":350214,"date":"2023-07-13T09:03:08","date_gmt":"2023-07-13T09:03:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=350214"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=350214","title":{"rendered":"<span>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 CI\/CD \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 \u0431\u0430\u0437\u0435 Docker \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c CodeBuild, CodeDeploy \u0438 Lambda<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>CI\/CD-\u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AWS, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CodeBuild \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u0432 \u0432\u0435\u0442\u043a\u0435. \u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437 Docker \u0432 ECR, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u043a\u043e\u0434\u0430 \u0432 S3, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Lambda \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 CodeDeploy, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u0442 \u043a\u043e\u0434 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0435 EC2-\u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/03e\/e50\/896\/03ee5089651b54afe1bdab7be2d11bfb.png\" width=\"780\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/03e\/e50\/896\/03ee5089651b54afe1bdab7be2d11bfb.png\"\/><\/figure>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CodePipeline?! \u041e\u0442\u0432\u0435\u0442 &#8212; \u043d\u0435 \u0432\u0435\u0437\u0434\u0435 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0437\u044b \u0432 ECR, \u0442\u043e \u0437\u0430\u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CodeDeploy \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 EC2-\u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b? \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u0447\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432 ECR.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c:\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d0a\/424\/cd2\/d0a424cd2b4d1782e2e8cc5d6a9d1f5e.png\" width=\"740\" height=\"707\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d0a\/424\/cd2\/d0a424cd2b4d1782e2e8cc5d6a9d1f5e.png\"\/><\/figure>\n<h4>\u041d\u0430\u0448 \u043a\u043e\u0434<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Python \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e flask<\/p>\n<pre><code class=\"python\"># app.py from flask import Flask  app = Flask(__name__)  @app.route('\/') def hello():     return \"Hello, Docker!\"  if __name__ == '__main__':     app.run(host='0.0.0.0',port=80)<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u044b \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u043e\u0434\u0430: \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043c\u044b \u043d\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043a\u043e\u0434 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438.  <\/p>\n<pre><code class=\"python\"># tests\/test_app.py from app import app  def test_index_route_success_status():     response = app.test_client().get('\/')     assert response.status_code == 200      def test_index_route_success_text():     response = app.test_client().get('\/')     assert response.data.decode('utf-8') == 'Hello, Docker!'<\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043f\u0438\u0448\u0435\u043c Dockerfile  <\/p>\n<pre><code class=\"python\"># Dockerfile FROM python:3.8-slim  # Set the working directory in the container WORKDIR \/app  # Install the dependencies RUN pip install flask pytest  # Copy the application code to the container COPY . .  # Set the command to run the application CMD [\"python\", \"app.py\"]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0433\u043e\u0442\u043e\u0432 \u043a \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0443 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044e.<\/p>\n<h4>CodeBuild<\/h4>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 AWS CodeBuild \u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0438\u043c\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043a\u043e\u0434\u0430 \u2014 bitBucket \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u0438 \u0432\u0435\u0442\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c. \u0412\u043a\u043b\u044e\u0447\u0438\u0442\u0435 webhooks.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c27\/119\/139\/c271191392ade7e72047e71c64024652.jpeg\" width=\"1247\" height=\"811\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c27\/119\/139\/c271191392ade7e72047e71c64024652.jpeg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0418 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u041e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u00bb \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c Docker-\u043e\u0431\u0440\u0430\u0437\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b97\/943\/d8a\/b97943d8a72172526564d947e0ac53eb.png\" width=\"1110\" height=\"895\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b97\/943\/d8a\/b97943d8a72172526564d947e0ac53eb.png\"\/><\/figure>\n<p>\u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0431\u043e\u0440\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/301\/e6b\/cfe\/301e6bcfe41a4a2d9b754e63430091ce.jpeg\" width=\"1164\" height=\"509\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/301\/e6b\/cfe\/301e6bcfe41a4a2d9b754e63430091ce.jpeg\" data-blurred=\"true\"\/><\/figure>\n<p><\/p>\n<p>AWS_DEFAULT_REGION: \u0440\u0435\u0433\u0438\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435<\/p>\n<p>IMAGE_TAG: \u0442\u0435\u0433 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0437\u0430 Docker<\/p>\n<p>IMAGE_REPO_NAME: \u0438\u043c\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f ECR<\/p>\n<p>AWS_ACCOUNT_ID: \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0443\u0447\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<p>\u042d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 buildspec.yml \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u044b. \u0424\u0430\u0439\u043b buildspec.yml \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u0435\u043d, \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435 \u0447\u0430\u0441\u0442\u0438, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u043e\u0439 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u043c.<\/p>\n<p>\u0412 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u0445 \u043c\u044b \u0432\u044b\u0431\u0435\u0440\u0435\u043c S3, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043a\u0443\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u0410\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Zip.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/06a\/a7d\/421\/06aa7d42196adc6836fef518aad5540c.jpeg\" width=\"914\" height=\"889\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/06a\/a7d\/421\/06aa7d42196adc6836fef518aad5540c.jpeg\" data-blurred=\"true\"\/><\/figure>\n<h4>buildspec.yml<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 CodeBuild, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u043e\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"python\">#buildspec.yml version: 0.2  phases:   pre_build:     commands:        - echo Logging in to Amazon ECR...        - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com   build:     commands:       - echo run tests first       - pip install flask pytest       - python3 -m pytest --junitxml=\/usr\/tests\/test-report.xml       - echo Build started on `date`       - echo Building the Docker image...                 - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .       - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com\/$IMAGE_REPO_NAME:$IMAGE_TAG    post_build:     commands:       - echo Build completed on `date`       - echo Pushing the Docker image...       - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com\/$IMAGE_REPO_NAME:$IMAGE_TAG        Reports:   pytest-reports:     files:       - test-report.xml     base-directory: \/usr\/tests\/     file-format: JUNITXML  Artifacts:   type: zip   files:     - '**\/*'<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u0430\u043f\u0435 pre_build \u043c\u044b \u0432\u043e\u0448\u043b\u0438 \u0432 \u043d\u0430\u0448\u0443 \u0443\u0447\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c ECR<\/p>\n<p>\u041d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0442\u0435\u0441\u0442, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b \u0438 \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043e\u0431\u0440\u0430\u0437<\/p>\n<p>\u041d\u0430 \u044d\u0442\u0430\u043f\u0435 post_build \u043c\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438 docker \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435.<\/p>\n<p>*\u0414\u0430\u043d\u043d\u044b\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0437\u0430\u0434\u0430\u043b\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c $<\/p>\n<p>\u041e\u0442\u0447\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 CodeBuild \u043f\u043e\u0437\u0436\u0435, \u0432\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0442\u0447\u0435\u0442\u0435<\/p>\n<p>\u0410\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/37a\/785\/ebd\/37a785ebd5e33dfe70844cec9d950311.jpeg\" width=\"1600\" height=\"378\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/37a\/785\/ebd\/37a785ebd5e33dfe70844cec9d950311.jpeg\" data-blurred=\"true\"\/><\/figure>\n<h4>CodeDeploy<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0433\u0440\u0443\u043f\u043f\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f. \u0420\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 EC2 \u0441 \u0442\u0435\u0433\u043e\u043c \u00abenv\u00bb \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u00abdev\u00bb.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/58a\/587\/837\/58a587837ca891f6ec51fcc6280df596.jpeg\" width=\"995\" height=\"849\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/58a\/587\/837\/58a587837ca891f6ec51fcc6280df596.jpeg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0418 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430. \u041b\u0443\u0447\u0448\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Codedeploy \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/960\/27b\/563\/96027b56331e50c6cfb7a11258604f55.jpeg\" width=\"1127\" height=\"540\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/960\/27b\/563\/96027b56331e50c6cfb7a11258604f55.jpeg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b CodeDeploy \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0448\u0430\u0433\u0438, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u0434. \u042d\u0442\u0438 \u0448\u0430\u0433\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 appspec.yml, \u0444\u0430\u0439\u043b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<pre><code>appspec.yml version: 0.0 os: linux # this to copy all files in the project to spacfic location files:   - source: \/     destination: \/usr\/src\/app\/ # overrite file if they are already there file_exists_behavior: OVERWRITE  hooks:   BeforeInstall:     - location: scripts\/before_install.sh       runas: root   ApplicationStart:     - location: scripts\/application_start.sh       runas: root<\/code><\/pre>\n<p>Hook \u2014 \u044d\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 AWS CodeDeploy \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434.  <\/p>\n<pre><code>#scripts\/before_install.sh  #stop all running containers docker kill $(docker ps -q)  #delete all images docker rmi -f $(docker images -aq)<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u043e\u0431\u0440\u0430\u0437\u044b:<\/p>\n<pre><code>#scripts\/application_start.sh  # build the docker image docker build -f \/usr\/src\/app\/Dockerfile \/usr\/src\/app\/ -t myapp  # run the container docker run -d -p 80:80 myapp<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0448 \u043e\u0431\u0440\u0430\u0437 \u0438 \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043f\u043e\u0440\u0442\u0443 80<\/p>\n<p>*CodeDpoly \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0435 EC2. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u043b\u0438 \u0432\u0435\u0441\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0441.<\/p>\n<p>\u0412\u043e\u0442 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/992\/afa\/b00\/992afab00dd969f3977db1534cc7d7d3.jpeg\" width=\"388\" height=\"404\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/992\/afa\/b00\/992afab00dd969f3977db1534cc7d7d3.jpeg\" data-blurred=\"true\"\/><\/figure>\n<h4>Lambda Functions<\/h4>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f\u00a0 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 CodeBuild \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u0432 S3. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 boto3, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442  \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u0442\u0430\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u0430\u043a Amazon S3 \u0438 Amazon EC2.<\/p>\n<pre><code>import boto3  def lambda_handler(event, context):     # Get the S3 bucket and object information from the event     s3_bucket = event['Records'][0]['s3']['bucket']['name']     s3_key = event['Records'][0]['s3']['object']['key']      # Create a CodeDeploy client     codedeploy_client = boto3.client('codedeploy')      # Create a deployment with the S3 revision     response = codedeploy_client.create_deployment(         applicationName='codedeply-ec2',            #change this to codedepoly application name         deploymentGroupName='codedeploy-ec2',       #change this to deployment group name         revision={             'revisionType': 'S3',             's3Location': {                 'bucket': s3_bucket,                 'key': s3_key,                 'bundleType': 'zip'             }         }     )      # Print the deployment ID     deployment_id = response['deploymentId']     print(f\"Deployment ID: {deployment_id}\")<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041e\u0442 \u0440\u0435\u0434\u0430\u043a\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 CI\/CD \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u041f\u041e \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430. \u041d\u0430 \u043a\u0443\u0440\u0441\u0435 \u00ab<a href=\"https:\/\/slurm.io\/gitlab-ci-cd\">CI\/CD \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Gitlab CI<\/a>\u00bb \u043c\u044b \u0443\u0447\u0438\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c CI\/CD: \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430\u043c\u0438, \u0431\u0438\u043b\u0434\u0430\u043c\u0438 \u0438 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u043c\u0438. \u0423\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u0430\u0439\u0442\u0435: <a href=\"https:\/\/slurm.io\/gitlab-ci-cd\">https:\/\/slurm.io\/gitlab-ci-cd<\/a>  <\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/companies\/southbridge\/articles\/747704\/\"> https:\/\/habr.com\/ru\/companies\/southbridge\/articles\/747704\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>CI\/CD-\u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AWS, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CodeBuild \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u0432 \u0432\u0435\u0442\u043a\u0435. \u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437 Docker \u0432 ECR, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u043a\u043e\u0434\u0430 \u0432 S3, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Lambda \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 CodeDeploy, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u0442 \u043a\u043e\u0434 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0435 EC2-\u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432.  <\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CodePipeline?! \u041e\u0442\u0432\u0435\u0442 &#8212; \u043d\u0435 \u0432\u0435\u0437\u0434\u0435 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0437\u044b \u0432 ECR, \u0442\u043e \u0437\u0430\u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CodeDeploy \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 EC2-\u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b? \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u0447\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432 ECR.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c:\u00a0<\/p>\n<figure class=\"full-width\"><\/figure>\n<h4>\u041d\u0430\u0448 \u043a\u043e\u0434<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Python \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e flask<\/p>\n<pre><code class=\"python\"># app.py from flask import Flask  app = Flask(__name__)  @app.route('\/') def hello():     return \"Hello, Docker!\"  if __name__ == '__main__':     app.run(host='0.0.0.0',port=80)<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u044b \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u043e\u0434\u0430: \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043c\u044b \u043d\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043a\u043e\u0434 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438.  <\/p>\n<pre><code class=\"python\"># tests\/test_app.py from app import app  def test_index_route_success_status():     response = app.test_client().get('\/')     assert response.status_code == 200      def test_index_route_success_text():     response = app.test_client().get('\/')     assert response.data.decode('utf-8') == 'Hello, Docker!'<\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043f\u0438\u0448\u0435\u043c Dockerfile  <\/p>\n<pre><code class=\"python\"># Dockerfile FROM python:3.8-slim  # Set the working directory in the container WORKDIR \/app  # Install the dependencies RUN pip install flask pytest  # Copy the application code to the container COPY . .  # Set the command to run the application CMD [\"python\", \"app.py\"]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0433\u043e\u0442\u043e\u0432 \u043a \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0443 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044e.<\/p>\n<h4>CodeBuild<\/h4>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 AWS CodeBuild \u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0438\u043c\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043a\u043e\u0434\u0430 \u2014 bitBucket \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u0438 \u0432\u0435\u0442\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c. \u0412\u043a\u043b\u044e\u0447\u0438\u0442\u0435 webhooks.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0418 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u041e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u00bb \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c Docker-\u043e\u0431\u0440\u0430\u0437\u044b.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0431\u043e\u0440\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:\u00a0<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><\/p>\n<p>AWS_DEFAULT_REGION: \u0440\u0435\u0433\u0438\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435<\/p>\n<p>IMAGE_TAG: \u0442\u0435\u0433 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0437\u0430 Docker<\/p>\n<p>IMAGE_REPO_NAME: \u0438\u043c\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f ECR<\/p>\n<p>AWS_ACCOUNT_ID: \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0443\u0447\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<p>\u042d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 buildspec.yml \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u044b. \u0424\u0430\u0439\u043b buildspec.yml \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u0435\u043d, \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435 \u0447\u0430\u0441\u0442\u0438, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u043e\u0439 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u043c.<\/p>\n<p>\u0412 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u0445 \u043c\u044b \u0432\u044b\u0431\u0435\u0440\u0435\u043c S3, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043a\u0443\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u0410\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Zip.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h4>buildspec.yml<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 CodeBuild, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u043e\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"python\">#buildspec.yml version: 0.2  phases:   pre_build:     commands:        - echo Logging in to Amazon ECR...        - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com   build:     commands:       - echo run tests first       - pip install flask pytest       - python3 -m pytest --junitxml=\/usr\/tests\/test-report.xml       - echo Build started on `date`       - echo Building the Docker image...                 - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .       - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com\/$IMAGE_REPO_NAME:$IMAGE_TAG    post_build:     commands:       - echo Build completed on `date`       - echo Pushing the Docker image...       - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com\/$IMAGE_REPO_NAME:$IMAGE_TAG        Reports:   pytest-reports:     files:       - test-report.xml     base-directory: \/usr\/tests\/     file-format: JUNITXML  Artifacts:   type: zip   files:     - '**\/*'<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u0430\u043f\u0435 pre_build \u043c\u044b \u0432\u043e\u0448\u043b\u0438 \u0432 \u043d\u0430\u0448\u0443 \u0443\u0447\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c ECR<\/p>\n<p>\u041d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0442\u0435\u0441\u0442, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b \u0438 \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043e\u0431\u0440\u0430\u0437<\/p>\n<p>\u041d\u0430 \u044d\u0442\u0430\u043f\u0435 post_build \u043c\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438 docker \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435.<\/p>\n<p>*\u0414\u0430\u043d\u043d\u044b\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0437\u0430\u0434\u0430\u043b\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c $<\/p>\n<p>\u041e\u0442\u0447\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 CodeBuild \u043f\u043e\u0437\u0436\u0435, \u0432\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0442\u0447\u0435\u0442\u0435<\/p>\n<p>\u0410\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h4>CodeDeploy<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0433\u0440\u0443\u043f\u043f\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f. \u0420\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 EC2 \u0441 \u0442\u0435\u0433\u043e\u043c \u00abenv\u00bb \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u00abdev\u00bb.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0418 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430. \u041b\u0443\u0447\u0448\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Codedeploy \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b CodeDeploy \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0448\u0430\u0433\u0438, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u0434. \u042d\u0442\u0438 \u0448\u0430\u0433\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 appspec.yml, \u0444\u0430\u0439\u043b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<pre><code>appspec.yml version: 0.0 os: linux # this to copy all files in the project to spacfic location files:   - source: \/     destination: \/usr\/src\/app\/ # overrite file if they are already there file_exists_behavior: OVERWRITE  hooks:   BeforeInstall:     - location: scripts\/before_install.sh       runas: root   ApplicationStart:     - location: scripts\/application_start.sh       runas: root<\/code><\/pre>\n<p>Hook \u2014 \u044d\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 AWS CodeDeploy \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434.  <\/p>\n<pre><code>#scripts\/before_install.sh  #stop all running containers docker kill $(docker ps -q)  #delete all images docker rmi -f $(docker images -aq)<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u043e\u0431\u0440\u0430\u0437\u044b:<\/p>\n<pre><code>#scripts\/application_start.sh  # build the docker image docker build -f \/usr\/src\/app\/Dockerfile \/usr\/src\/app\/ -t myapp  # run the container docker run -d -p 80:80 myapp<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0448 \u043e\u0431\u0440\u0430\u0437 \u0438 \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043f\u043e\u0440\u0442\u0443 80<\/p>\n<p>*CodeDpoly \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0435 EC2. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u043b\u0438 \u0432\u0435\u0441\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0441.<\/p>\n<p>\u0412\u043e\u0442 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<figure class=\"\"><\/figure>\n<h4>Lambda Functions<\/h4>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f\u00a0 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 CodeBuild \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u0432 S3. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 boto3, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442  \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u0442\u0430\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u0430\u043a Amazon S3 \u0438 Amazon EC2.<\/p>\n<pre><code>import boto3  def lambda_handler(event, context):     # Get the S3 bucket and object information from the event     s3_bucket = event['Records'][0]['s3']['bucket']['name']     s3_key = event['Records'][0]['s3']['object']['key']      # Create a CodeDeploy client     codedeploy_client = boto3.client('codedeploy')      # Create a deployment with the S3 revision     response = codedeploy_client.create_deployment(         applicationName='codedeply-ec2',            #change this to codedepoly application name         deploymentGroupName='codedeploy-ec2',       #change this to deployment group name         revision={             'revisionType': 'S3',             's3Location': {                 'bucket': s3_bucket,                 'key': s3_key,                 'bundleType': 'zip'             }         }     )      # Print the deployment ID     deployment_id = response['deploymentId']     print(f\"Deployment ID: {deployment_id}\")<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041e\u0442 \u0440\u0435\u0434\u0430\u043a\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 CI\/CD \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u041f\u041e \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430. \u041d\u0430 \u043a\u0443\u0440\u0441\u0435 \u00ab<a href=\"https:\/\/slurm.io\/gitlab-ci-cd\">CI\/CD \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Gitlab CI<\/a>\u00bb \u043c\u044b \u0443\u0447\u0438\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c CI\/CD: \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430\u043c\u0438, \u0431\u0438\u043b\u0434\u0430\u043c\u0438 \u0438 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430\u043c\u0438. \u0423\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u0430\u0439\u0442\u0435: <a href=\"https:\/\/slurm.io\/gitlab-ci-cd\">https:\/\/slurm.io\/gitlab-ci-cd<\/a>  <\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/companies\/southbridge\/articles\/747704\/\"> https:\/\/habr.com\/ru\/companies\/southbridge\/articles\/747704\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-350214","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350214"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350214\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}