From 81af66f2474e51f808531c94f3997d47667352ee Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 23 Jul 2021 13:03:24 +0300 Subject: [PATCH] Updated docker ansible script --- data/ansible/docker/docker.yaml | 2 +- data/ansible/docker/main.yaml | 16 ++++++++++++---- data/ansible/docker/nginx.conf.j2 | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/data/ansible/docker/docker.yaml b/data/ansible/docker/docker.yaml index d2b7f91a1..72c28652a 100644 --- a/data/ansible/docker/docker.yaml +++ b/data/ansible/docker/docker.yaml @@ -53,7 +53,7 @@ - name: Start registry become: yes - shell: docker run -d --name {{ registry_name }} --restart=always -v "$(pwd)":/var/lib/{{ registry_name }} -p 5000:5000 registry:2 + shell: docker run -d --name {{ registry_name }} --restart=always -v "$(pwd)":/var/lib/{{ registry_name }} -p {{ registry_port }}:5000 registry:2 args: chdir: /var/docker/{{ registry_name }} when: continerList.stdout_lines|length == 0 diff --git a/data/ansible/docker/main.yaml b/data/ansible/docker/main.yaml index ae3653a19..254406567 100644 --- a/data/ansible/docker/main.yaml +++ b/data/ansible/docker/main.yaml @@ -28,6 +28,7 @@ registry_site: "dkr.cgrates.org" # the web site registry_name: "registry" # the name of the registry container users_filename: "" # the file containing the htpasswd users + registry_port: 5000 dependencies: - build-essential @@ -99,6 +100,13 @@ ########################################################################################################################### ########################################################################################################################### # Install CGRateS + - name: create cgrates directory + become: yes + file: + state: absent + dest: '{{ cgrates_dir }}' + become_user: "{{ user }}" + - name: create cgrates directory become: yes file: @@ -184,7 +192,7 @@ - name: build Docker image become: yes shell: - docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} -f="{{ item }}.doker" {{ cgrates_dir }}/data/docker/scratch/; + docker build -t 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} -f="{{ item }}.doker" {{ cgrates_dir }}/data/docker/scratch/; args: chdir: '{{ cgrates_dir }}/data/docker/scratch' with_items: "{{ build_execs }}" @@ -192,20 +200,20 @@ - name: push docker image to repo become: yes shell: - docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }}; + docker image push 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }}; with_items: "{{ build_execs }}" - name: tag docker master image become: yes shell: - docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:latest; + docker tag 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:latest; when: cgrates_branch == "master" or cgrates_branch == "1.0" with_items: "{{ build_execs }}" - name: push docker master image to repo become: yes shell: - docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:latest; + docker image push 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:latest; when: cgrates_branch == "master" or cgrates_branch == "1.0" with_items: "{{ build_execs }}" diff --git a/data/ansible/docker/nginx.conf.j2 b/data/ansible/docker/nginx.conf.j2 index 1118f8888..ee8a2adce 100644 --- a/data/ansible/docker/nginx.conf.j2 +++ b/data/ansible/docker/nginx.conf.j2 @@ -25,19 +25,20 @@ server { } # To add basic authentication to v2 use auth_basic setting. - limit_except GET HEAD OPTIONS { - deny all; - } {% if users_filename|length > 0 %} auth_basic "Registry realm"; auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd; + {% else %} + limit_except GET HEAD OPTIONS { + deny all; + } {% endif %} ## If $docker_distribution_api_version is empty, the header is not added. ## See the map directive above where this variable is defined. add_header 'Docker-Distribution-Api-Version' $docker_distribution_api_version always; - proxy_pass http://127.0.0.1:5000; + proxy_pass http://127.0.0.1:{{ registry_port }}; proxy_set_header Host $http_host; # required for docker client's sake proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;