diff --git a/defaults/main.yml b/defaults/main.yml index 93f7672..e615f09 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,6 +19,7 @@ shinyproxy_http_port: 8080 shinyproxy_log_retention: 10 shinyproxy_default_apps: True # Shinyproxy as docker service +shinyproxy_docker_image: 'adellamisti/shinyproxy:latest' shinyproxy_as_docker_src_dir: /srv/shinyproxy_service shinyproxy_as_docker_service_name: 'shinyproxy' shinyproxy_docker_network: 'shinyproxy' diff --git a/tasks/shinyproxy_docker_service.yml b/tasks/shinyproxy_docker_service.yml index 11c877a..5c9eb69 100644 --- a/tasks/shinyproxy_docker_service.yml +++ b/tasks/shinyproxy_docker_service.yml @@ -1,7 +1,7 @@ --- -- name: Manage the composition of shinyproxy as a docker swarm service +- name: Manage the composition of shinyproxy as a docker (non swarm) service block: - - name: Create the directory where the dockerfile and the configuration file will be copied to + - name: Create the directory where the dockerfile and the configuration file will be copied into file: dest={{ shinyproxy_as_docker_src_dir }} state=directory - name: Install the shinyproxy configuration file when using version 2.x @@ -10,12 +10,6 @@ - name: Install the shinyproxy docker file template: src=Dockerfile.j2 dest={{ shinyproxy_as_docker_src_dir }}/Dockerfile owner=root group=root mode=0444 - # - name: Create the docker network used by shinyproxy - # docker_network: - # name: '{{ shinyproxy_docker_network }}' - # driver: overlay - # state: present - - name: Install the docker compose file template: src=shinyproxy-docker-compose.yml.j2 dest={{ shinyproxy_as_docker_src_dir }}/docker-compose.yml @@ -24,6 +18,37 @@ project_src: '{{ shinyproxy_as_docker_src_dir }}' build: yes - run_once: True - when: docker_swarm_manager_main_node is defined and docker_swarm_manager_main_node | bool + when: shinyproxy_container_backend == 'docker' tags: [ 'shinyproxy', 'shinyproxy_docker', 'docker' ] + +- name: Manage the installation of the shinyproxy configuration + block: + - name: Create the directory where the dockerfile and the configuration file will be copied into + file: dest={{ shinyproxy_as_docker_src_dir }} state=directory + + - name: Install the shinyproxy configuration file + template: src=shinyproxy-2-conf.yml.j2 dest={{ shinyproxy_as_docker_src_dir }}/application.yml owner=root group=root mode=0400 + + when: shinyproxy_container_backend == 'docker-swarm' + tags: [ 'shinyproxy', 'shinyproxy_swarm', 'docker' ] + +- name: Manage the composition of shinyproxy as a docker swarm stack + block: + - name: Create the directory where the dockerfile and the configuration file will be copied into + file: dest={{ shinyproxy_as_docker_src_dir }} state=directory + + - name: Install the docker compose file + template: src=shinyproxy-docker-compose.yml.j2 dest={{ shinyproxy_as_docker_src_dir }}/docker-shinyproxy-stack.yml + + - name: Start the shinyproxy stack + docker_stack: + name: shinyproxy + state: present + compose: + - '{{ haproxy_docker_compose_dir }}/docker-shinyproxy-stack.yml' + + run_once: True + when: + - docker_swarm_manager_main_node is defined and docker_swarm_manager_main_node | bool + - shinyproxy_container_backend == 'docker-swarm' + tags: [ 'shinyproxy', 'shinyproxy_swarm', 'docker' ] diff --git a/templates/shinyproxy-docker-compose.yml.j2 b/templates/shinyproxy-docker-compose.yml.j2 index ea56191..c19a6a6 100644 --- a/templates/shinyproxy-docker-compose.yml.j2 +++ b/templates/shinyproxy-docker-compose.yml.j2 @@ -2,15 +2,19 @@ version: '3.6' services: shinyproxy: +{% if shinyproxy_container_backend == 'docker' %} build: . + ports: + - '{{ shinyproxy_http_port }}':'{{ shinyproxy_http_port }}' +{% else %} + image: {{ shinyproxy_docker_image }} +{% endif %} volumes: - /var/run/docker.sock:/var/run/docker.sock - #ports: - # - '{{ shinyproxy_http_port }}':'{{ shinyproxy_http_port }}' - expose: - - "{{ shinyproxy_http_port }}" + - {{ shinyproxy_as_docker_src_dir }}/application.yml:/opt/shinyproxy/application.yml:ro networks: - - '{{ shinyproxy_docker_network }}' + - shinyproxy_{{ shinyproxy_docker_network }} +{% if shinyproxy_container_backend == 'docker-swarm' %} deploy: mode: replicated replicas: {{ shinyproxy_docker_swarm_replicas }} @@ -22,6 +26,7 @@ services: delay: 5s max_attempts: 3 window: 120s +{% endif %} {% if docker_log_to_journal %} logging: driver: 'journald'