Application deploy through bash and docker-compose

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.

Примерный желаемый флоу

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.

Experimental video

This time I decided to share my experience as a video-lesson.

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 🙂

Docker-compose with env variables together with Bash creates magic!

The primary idea is that you can place a file .env next to docker-compose.yml with the following content:

MICROSERVICE_1_SRC_DIR=/var/src/microservice_1
MICROSERVICE_2_SRC_DIR=/var/src/microservice_2
MICROSERVICE_3_SRC_DIR=/var/src/microservice_3
PROJECTS_BRANCH=master

And to make the block build in docker-compose as follows:

service1:
    build:
      context: ${MICROSERVICE_1_SRC_DIR}
      dockerfile: Dockerfile

And in bash script that will handle the deploy of the whole service we make the following record:

folders=(\
    $MICROSERVICE_1_SRC_DIR\
    $MICROSERVICE_2_SRC_DIR\
    $MICROSERVICE_3_SRC_DIR\
      )

for folder in ${folders[*]}
do
    echo "update " $folder
    cd $folder && git fetch
    cd $folder && git reset --hard origin/$PROJECT_BRANCH
done
docker-compose up -d --build

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!

Helpful links

Also in this video I refer to my repositories with the example of the project. So, here are the links:

  1. github.com/gmoreva/1-bdc-interface - the example of interface that communicates with the public microservice.
  2. github.com/gmoreva/1-bdc-service-example - the example of microservices which communicate one with another through REST and one of them is open to public and available for the interface
  3. github.com/gmoreva/1-bdc-prod - repository with the example of production docker-compose file, bash script and the example of .env

Thank you for your attention!