diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..9cf50af --- /dev/null +++ b/.drone.yml @@ -0,0 +1,55 @@ +--- +kind: pipeline +name: default + +steps: + - name: build and publish image + image: plugins/docker + settings: + repo: eumau/nginx + auto_tag: true + username: + from_secret: dockerhub_username + password: + from_secret: dockerhub_password + when: + branch: + - master + +--- +kind: pipeline +name: pull_request + +steps: + - name: build image only + image: plugins/docker + settings: + repo: eumau/nginx + auto_tag: true + dry_run: true + +trigger: + event: + - pull_request + +--- +kind: pipeline +name: tags + +steps: + - name: docker + image: plugins/docker + settings: + repo: eumau/nginx + username: + from_secret: dockerhub_username + password: + from_secret: dockerhub_password + tags: + - ${DRONE_TAG} + build_args: + - NGINX_VERSION=${DRONE_TAG} + +trigger: + event: + - tag diff --git a/.gitignore b/.gitignore index c24c661..adac7f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ *~ \#* .#* -*.pyc -*.bak -__pycache__ diff --git a/files/Dockerfile b/Dockerfile similarity index 91% rename from files/Dockerfile rename to Dockerfile index 558254d..b30f360 100644 --- a/files/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # nginx container with self-signed SSL certificates -FROM nginx -MAINTAINER Mauro Torrez +ARG NGINX_VERSION=latest +FROM nginx:${NGINX_VERSION} RUN apt-get update \ && apt-get install -y -q ssl-cert \ diff --git a/files/default.conf b/default.conf similarity index 100% rename from files/default.conf rename to default.conf diff --git a/defaults/main.yml b/defaults/main.yml deleted file mode 100644 index 3a9c1b4..0000000 --- a/defaults/main.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -# nombre del container -nginx_container_name: nginx - -# nombre de la imagen -nginx_image_name: my_nginx - -# nombre del volumen de configuracion -nginx_config_volume: nginx_config - -# nombre del volumen ssl -nginx_ssl_volume: nginx_ssl - -# nombre del volumen web -nginx_webroot_volume: nginx_webroot - -# nombre del volumen location -nginx_location_volume: nginx_location - -# puertos a publicar -nginx_publish_ports: - - 80:80 - - 443:443 diff --git a/files/dhparams.pem b/dhparams.pem similarity index 100% rename from files/dhparams.pem rename to dhparams.pem diff --git a/handlers/main.yml b/handlers/main.yml deleted file mode 100644 index 8cb294c..0000000 --- a/handlers/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: restart nginx container - docker_container: - name: nginx - state: started - restart: yes diff --git a/files/nginx.conf b/nginx.conf similarity index 100% rename from files/nginx.conf rename to nginx.conf diff --git a/tasks/domain.yml b/tasks/domain.yml deleted file mode 100644 index 870885e..0000000 --- a/tasks/domain.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -# template domain config -# vars: ng_domain_secure (True) -# ng_domain_flags (['http2']) -# ng_domain_name (no default) -# ng_domain_root ('/usr/share/nginx/html') -# ng_domain_common_locations (True) - -- name: domain locations directory - file: - path: "{{ nginx_location_mountpoint }}/{{ ng_domain_name }}" - state: directory - -- name: template domain config - template: - src: domain.conf.j2 - dest: "{{ nginx_config_mountpoint }}/{{ ng_domain_name }}.conf" - notify: restart nginx container diff --git a/tasks/location.yml b/tasks/location.yml deleted file mode 100644 index d7c2923..0000000 --- a/tasks/location.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -# template domain config -# ng_domain_name (no default) -# ng_location_name (no default) -# ng_location_content (no default) - -- name: template location config - template: - src: location.conf.j2 - dest: "{{ nginx_location_mountpoint }}/{{ ng_domain_name }}/{{ - ng_location_name|regex_replace('[^0-9a-zA-Z_.-]','_') }}.conf" - notify: restart nginx container diff --git a/tasks/main.yml b/tasks/main.yml deleted file mode 100644 index ecf5158..0000000 --- a/tasks/main.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -- name: Directorio de build nginx - file: - path: /root/.nginx-docker-image - state: directory - tags: skip_me - -- name: Copiar archivos de build - copy: - src: "{{ item }}" - dest: /root/.nginx-docker-image - loop: - - Dockerfile - - nginx.conf - - dhparams.pem - - default.conf - tags: skip_me - -- name: Crear imagen my_nginx - docker_image: - state: present - name: "{{ nginx_image_name }}" - path: /root/.nginx-docker-image - tags: skip_me - -- name: Activar container nginx - docker_container: - name: "{{ nginx_container_name }}" - state: started - restart_policy: unless-stopped - image: "{{ nginx_image_name }}" - volumes: - - "{{ nginx_ssl_volume }}:/etc/nginx/ssl/" - - "{{ nginx_config_volume }}:/etc/nginx/conf.d/" - - "{{ nginx_location_volume }}:/etc/nginx/location/" - - "{{ nginx_webroot_volume }}:/usr/share/nginx/html/" - networks: - - name: "{{ docker_network_name }}" - ports: "{{ nginx_publish_ports }}" - env: - register: container - -- name: Leer info de volumen {{ nginx_config_volume }} - docker_volume_info: - name: "{{ nginx_config_volume }}" - register: res_cnf - -- name: Leer info de volumen {{ nginx_ssl_volume }} - docker_volume_info: - name: "{{ nginx_ssl_volume }}" - register: res_ssl - -- name: Leer info de volumen {{ nginx_webroot_volume }} - docker_volume_info: - name: "{{ nginx_webroot_volume }}" - register: res_web - -- name: Leer info de volumen {{ nginx_location_volume }} - docker_volume_info: - name: "{{ nginx_location_volume }}" - register: res_loc - -- name: Exportar informacion de volumenes - set_fact: - nginx_container_name: "{{ lookup('vars','nginx_container_name') }}" - nginx_config_volume: "{{ lookup('vars','nginx_config_volume') }}" - nginx_config_mountpoint: "{{ res_cnf.volume.Mountpoint }}" - nginx_location_volume: "{{ lookup('vars','nginx_location_volume') }}" - nginx_location_mountpoint: "{{ res_loc.volume.Mountpoint }}" - nginx_webroot_volume: "{{ lookup('vars','nginx_webroot_volume') }}" - nginx_webroot_mountpoint: "{{ res_web.volume.Mountpoint }}" - nginx_ssl_volume: "{{ lookup('vars','nginx_ssl_volume') }}" - nginx_ssl_mountpoint: "{{ res_ssl.volume.Mountpoint }}" - -- name: default location dir - file: - path: "{{ nginx_location_mountpoint }}/default" - state: directory diff --git a/templates/domain.conf.j2 b/templates/domain.conf.j2 deleted file mode 100644 index 70f49d4..0000000 --- a/templates/domain.conf.j2 +++ /dev/null @@ -1,24 +0,0 @@ -{% if ng_domain_secure|default(True) %} -server { - listen 80; - listen [::]:80; - # redirect all HTTP requests to HTTPS with a 301 Moved Permanently response. - return 301 https://$host$request_uri; -} -{% endif %} - -server { - {% if not ng_domain_secure %} - listen 80 {{ ng_domain_flags | default(['http2']) | join(' ') }}; - listen [::]:80 {{ ng_domain_flags | default(['http2']) | join(' ') }}; - {% endif %} - listen 443 ssl {{ ng_domain_flags | default(['http2']) | join(' ') }}; - listen [::]:443 ssl {{ ng_domain_flags | default(['http2']) | join(' ') }}; - - server_name {{ ng_domain_name | regex_replace('^default$','_') }}; - root {{ ng_domain_root|default('/usr/share/nginx/html') }}; - include locations/{{ ng_domain_name }}/*.conf; - {% if ng_domain_common_locations | default(True) %} - include locations/common/*.conf; - {% endif %} -} diff --git a/templates/location.conf.j2 b/templates/location.conf.j2 deleted file mode 100644 index e527ed6..0000000 --- a/templates/location.conf.j2 +++ /dev/null @@ -1,3 +0,0 @@ -location {{ ng_location_name }} { - {{ ng_location_content }} -}