--- source: - http://dimafeng.com/2015/10/17/docker-distribution/ constants: config_path: ~/.vps/{{ host }} docker_compose_file: "{{ config_path }}/docker-compose.yml" nginx_conf_file: "{{ config_path }}/data/nginx/app.conf" tasks: - task: loop through: << upstreams >> as: upstream run: - task: generate_file template: docker/upstream/Dockerfile.{{ upstream.type }}.erb target: "{{ config_path }}/{{ upstream.name }}/Dockerfile" - description: Building '{{ upstream.name }}' image task: execute command: docker build --no-cache -f {{ config_path }}/{{ upstream.name }}/Dockerfile -t {{ upstream.name }} {{ upstream.path }} - description: Saving docker images as .gzip file task: loop through: << upstreams >> as: upstream run: - task: execute command: docker save {{ upstream.name }} | gzip > /tmp/{{ upstream.name }}.gzip - description: Uploading images task: loop through: << upstreams >> as: upstream run: - task: upload file: /tmp/{{ upstream.name }}.gzip - description: Stopping current containers task: remote_execute command: cd {{ release_path }} && docker-compose stop - description: Removing current containers task: loop through: << upstreams >> as: upstream run: - task: remote_execute command: docker container rm $(docker container ls -f ancestor={{ upstream.name }} -aq) - description: Removing current images task: loop through: << upstreams >> as: upstream run: - task: remote_execute command: docker image rm {{ upstream.name }} - task: run_tasks tasks: << preload >> - description: Unzipping and loading docker images task: loop through: << upstreams >> as: upstream run: - task: remote_execute command: gunzip < /tmp/{{ upstream.name }}.gzip | docker load - task: generate_file template: docker/docker-compose.yml.erb target: "{{ docker_compose_file }}" - description: Uploading docker-compose.yml task: upload file: "{{ docker_compose_file }}" remote_path: "{{ release_path }}/docker-compose.yml" - task: generate_file template: docker/data/nginx/app.conf.erb target: "{{ nginx_conf_file }}" - description: Uploading Nginx config task: upload file: "{{ nginx_conf_file }}" remote_path: "{{ release_path }}/data/nginx/app.conf" - task: loop through: << upstreams >> as: upstream run: - task: generate_file template: docker/upstream/init-letsencrypt.sh.erb target: "{{ config_path }}/{{ upstream.name }}/init-letsencrypt.sh" - description: Uploading Let’s Encrypt script task: upload file: "{{ config_path }}/{{ upstream.name }}/init-letsencrypt.sh" remote_path: "{{ release_path }}/init-letsencrypt/{{ upstream.name }}.sh" - description: Install SSL certificates (if required) task: remote_execute command: - chmod +x {{ release_path }}/init-letsencrypt/{{ upstream.name }}.sh - cd {{ release_path }} && if [ ! -d "data/certbot/conf/live/{{ domain:upstream }}" ]; then yes Y | sudo ./init-letsencrypt/{{ upstream.name }}.sh; fi - task: run_tasks tasks: << postload >> - description: Starting containers task: remote_execute command: cd {{ release_path }} && docker-compose up {{ up }} -d - description: Checking running docker images task: remote_execute command: docker ps