{"id":1794,"date":"2021-04-11T12:19:25","date_gmt":"2021-04-11T09:19:25","guid":{"rendered":"https:\/\/amorev.ru\/?p=1794"},"modified":"2021-07-24T20:02:28","modified_gmt":"2021-07-24T17:02:28","slug":"gmoreva-1-bash-docker-compose","status":"publish","type":"post","link":"https:\/\/amorev.ru\/en\/gmoreva-1-bash-docker-compose\/","title":{"rendered":"Application deploy through bash and docker-compose"},"content":{"rendered":"\n<p>Deploy of your project makes the application visible for your audience. We're here in Wormsoft tried a lot of variations of deploy. For the small projects we picked a simple bash script together with the properly set docker-compose file.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/amorev.ru\/wp-content\/uploads\/2021\/04\/image-1024x578.png\" alt=\"\" class=\"wp-image-1795\" width=\"586\" height=\"330\" srcset=\"https:\/\/amorev.ru\/wp-content\/uploads\/2021\/04\/image-1024x578.png 1024w, https:\/\/amorev.ru\/wp-content\/uploads\/2021\/04\/image-300x169.png 300w, https:\/\/amorev.ru\/wp-content\/uploads\/2021\/04\/image-768x433.png 768w, https:\/\/amorev.ru\/wp-content\/uploads\/2021\/04\/image.png 1370w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0444\u043b\u043e\u0443<\/figcaption><\/figure><\/div>\n\n\n\n<p>In the end of the day we got the result that our microservice application declaratively deploys itself at the client's server and easily updates once the new versions of sources are out.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Experimental video<\/h3>\n\n\n\n<p>This time I decided to share my experience as a <a href=\"https:\/\/www.youtube.com\/watch?v=iGrLNOzE_2Q\" data-rel=\"lightbox-video-0\" target=\"_blank\" rel=\"noreferrer noopener nofollow sponsored ugc\">video-lesson<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"fitvids-video\"><iframe loading=\"lazy\" title=\"Bash  + Docker Compose. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u0435\u043f\u043b\u043e\u0439 docker \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 Ubuntu \u0441\u0435\u0440\u0432\u0435\u0440\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/iGrLNOzE_2Q?feature=oembed&enablejsapi=1&origin=https:\/\/amorev.ru\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<p>I'd be grateful for watching and leaving a feedback. If I'm doing something wrong I'd be glad to be aware of that. And If you liked the video I'd also be glad to be aware \ud83d\ude42<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Docker-compose with env variables together with Bash creates magic!<\/h3>\n\n\n\n<p>The primary idea is that you can place a file .env next to docker-compose.yml with the following content:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">MICROSERVICE_1_SRC_DIR=\/var\/src\/microservice_1\nMICROSERVICE_2_SRC_DIR=\/var\/src\/microservice_2\nMICROSERVICE_3_SRC_DIR=\/var\/src\/microservice_3\nPROJECTS_BRANCH=master<\/pre>\n\n\n\n<p>And to make the block build in docker-compose as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">service1:\n    build:\n      context: ${MICROSERVICE_1_SRC_DIR}\n      dockerfile: Dockerfile<\/pre>\n\n\n\n<p>And in bash script that will handle the deploy of the whole service we make the following record:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">folders=(\\\n    $MICROSERVICE_1_SRC_DIR\\\n    $MICROSERVICE_2_SRC_DIR\\\n    $MICROSERVICE_3_SRC_DIR\\\n      )\n\nfor folder in ${folders[*]}\ndo\n    echo \"update \" $folder\n    cd $folder && git fetch\n    cd $folder && git reset --hard origin\/$PROJECT_BRANCH\ndone\ndocker-compose up -d --build<\/pre>\n\n\n\n<p>And we get the new freshly compiled version of the project with all microservices. If the new version of some service is out, we just launch this script that will update the sources, recompile the images and launch the containers so the application works correctly. All these ideas are scrupulously disclosed in my video, so you're welcome to enjoy it!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Helpful links<\/h3>\n\n\n\n<p>Also in this video I refer to my repositories with the example of the project. So, here are the links:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/github.com\/gmoreva\/1-bdc-interface\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" title=\"https:\/\/github.com\/gmoreva\/1-bdc-interface\">github.com\/gmoreva\/1-bdc-interface<\/a> - the example of interface that communicates with the public microservice.<\/li><li><a href=\"https:\/\/github.com\/gmoreva\/1-bdc-service-example\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" title=\"https:\/\/github.com\/gmoreva\/1-bdc-service-example\">github.com\/gmoreva\/1-bdc-service-example<\/a> - the example of microservices which communicate one with another through REST and one of them is open to public and available for the interface<\/li><li><a href=\"https:\/\/github.com\/gmoreva\/1-bdc-prod\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" title=\"https:\/\/github.com\/gmoreva\/1-bdc-prod\">github.com\/gmoreva\/1-bdc-prod<\/a> - repository with the example of production docker-compose file, bash script and the example of .env<\/li><\/ol>\n\n\n\n<p>Thank you for your attention!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deploy of your project makes the application visible for your audience. We&#8217;re here in Wormsoft tried a lot of variations of deploy. For the small &hellip; <\/p>\n","protected":false},"author":1,"featured_media":1795,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[270],"tags":[14,271,37,36,272,188,273,264],"class_list":["post-1794","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-galera-moreva","tag-bash","tag-deploy","tag-devops","tag-docker","tag-docker-compose","tag-videozapis","tag-galera-moreva","tag-uroki"],"_links":{"self":[{"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/posts\/1794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/comments?post=1794"}],"version-history":[{"count":0,"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/posts\/1794\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/media\/1795"}],"wp:attachment":[{"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/media?parent=1794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/categories?post=1794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amorev.ru\/en\/wp-json\/wp\/v2\/tags?post=1794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}