From 548ee0bbad6f44228b3aaa9cfa8c0ba05a2e9d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vic=20Sh=C3=B3stak?= Date: Wed, 5 May 2021 20:19:04 +0300 Subject: [PATCH] Fix Ansible roles --- README.md | 2 +- pkg/registry/defaults.go | 2 +- pkg/registry/roles/docker/tasks/main.yml | 10 ++++++++++ pkg/registry/roles/nginx/tasks/main.yml | 4 ++-- .../roles/nginx/templates/default-http.conf.j2 | 4 ++-- pkg/registry/roles/postgres/tasks/main.yml | 8 ++++++-- pkg/registry/roles/redis/tasks/main.yml | 2 +- pkg/registry/templates/hosts.ini.tmpl | 8 +++++++- 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5b39314..b8c68b7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

Create a new production-ready project with backend (Golang), frontend (JavaScript, TypeScript)
and deploy automation (Ansible, Docker) by running one CLI command.

Focus on writing code and thinking of business-logic! The CLI will take care of the rest.

-

cli version go version go cover go report license

+

cli version go version go cover go report license

## ⚡️ Quick start diff --git a/pkg/registry/defaults.go b/pkg/registry/defaults.go index de1274d..bbfc53f 100644 --- a/pkg/registry/defaults.go +++ b/pkg/registry/defaults.go @@ -11,7 +11,7 @@ import ( ) // CLIVersion version of Create Go App CLI. -const CLIVersion string = "2.1.0" +const CLIVersion string = "2.1.1" // Variables struct for Ansible variables (inventory, hosts). type Variables struct { diff --git a/pkg/registry/roles/docker/tasks/main.yml b/pkg/registry/roles/docker/tasks/main.yml index 78a46d9..ffba97c 100755 --- a/pkg/registry/roles/docker/tasks/main.yml +++ b/pkg/registry/roles/docker/tasks/main.yml @@ -55,3 +55,13 @@ - name: Create a new Docker network community.docker.docker_network: name: "{{ docker_network }}" + +# +# Create folder for project files. +# +- name: Create folder for project files + file: + state: directory + path: "{{ server_dir }}" + owner: "{{ server_user }}" + group: "{{ server_group }}" diff --git a/pkg/registry/roles/nginx/tasks/main.yml b/pkg/registry/roles/nginx/tasks/main.yml index c6f3a2a..5f0e20a 100755 --- a/pkg/registry/roles/nginx/tasks/main.yml +++ b/pkg/registry/roles/nginx/tasks/main.yml @@ -54,7 +54,7 @@ - "80:80" volumes: - "{{ server_dir }}/webserver/nginx.conf:/etc/nginx/nginx.conf:ro" - - "{{ server_dir }}/webserver/default.conf:/etc/nginx/conf.d/default.conf:ro" + - "{{ server_dir }}/webserver/default.conf:/etc/nginx/conf.d/default.conf" when: nginx_use_only_https == 'no' # @@ -73,5 +73,5 @@ - "443:443" volumes: - "{{ server_dir }}/webserver/nginx.conf:/etc/nginx/nginx.conf:ro" - - "{{ server_dir }}/webserver/default.conf:/etc/nginx/conf.d/default.conf:ro" + - "{{ server_dir }}/webserver/default.conf:/etc/nginx/conf.d/default.conf" when: nginx_use_only_https == 'yes' diff --git a/pkg/registry/roles/nginx/templates/default-http.conf.j2 b/pkg/registry/roles/nginx/templates/default-http.conf.j2 index fa49244..1ea3330 100755 --- a/pkg/registry/roles/nginx/templates/default-http.conf.j2 +++ b/pkg/registry/roles/nginx/templates/default-http.conf.j2 @@ -14,8 +14,8 @@ server { # Main server server { - listen 80 default_server; - listen [::]:80 default_server; + listen 80; + listen [::]:80; {% if nginx_redirect_to_non_www %} server_name {{ project_domain }}; {% else %} diff --git a/pkg/registry/roles/postgres/tasks/main.yml b/pkg/registry/roles/postgres/tasks/main.yml index 27d077d..ba56b33 100644 --- a/pkg/registry/roles/postgres/tasks/main.yml +++ b/pkg/registry/roles/postgres/tasks/main.yml @@ -18,7 +18,7 @@ # - name: Run PostgreSQL container community.docker.docker_container: - name: cgapp-postgres + name: "{{ postgres_container_name }}" image: "postgres:{{ postgres_version }}" restart_policy: unless-stopped recreate: true @@ -26,6 +26,10 @@ - name: "{{ docker_network }}" ports: - "{{ postgres_port }}:{{ postgres_port }}" + env: + POSTGRES_USER: "{{ postgres_user }}" + POSTGRES_PASSWORD: "{{ postgres_password }}" + POSTGRES_DB: "{{ postgres_db }}" volumes: - "{{ server_dir }}/database/data/:/var/lib/postgresql/data" @@ -44,7 +48,7 @@ "-path", "/migrations", "-database", - "postgres://{{ postgres_user }}:{{ postgres_password }}@localhost:{{ postgres_port }}/{{ postgres_db }}?sslmode={{ postgres_ssl_mode }}", + "postgres://{{ postgres_user }}:{{ postgres_password }}@{{ postgres_container_name }}:{{ postgres_port }}/{{ postgres_db }}?sslmode={{ postgres_ssl_mode }}", "up", "{{ migrate_number }}", ] diff --git a/pkg/registry/roles/redis/tasks/main.yml b/pkg/registry/roles/redis/tasks/main.yml index 75f3c30..43c2055 100644 --- a/pkg/registry/roles/redis/tasks/main.yml +++ b/pkg/registry/roles/redis/tasks/main.yml @@ -18,7 +18,7 @@ # - name: Run Redis container community.docker.docker_container: - name: cgapp-redis + name: "{{ redis_container_name }}" image: "redis:{{ redis_version }}" restart_policy: unless-stopped recreate: true diff --git a/pkg/registry/templates/hosts.ini.tmpl b/pkg/registry/templates/hosts.ini.tmpl index 3aed4e6..ff6c096 100644 --- a/pkg/registry/templates/hosts.ini.tmpl +++ b/pkg/registry/templates/hosts.ini.tmpl @@ -56,6 +56,9 @@ backend_port=5000 # PostgreSQL configuration (backend DB): # +# Set PostgreSQL container name +# MUST BE MATCH to the port that is listed in your `./backend/.env` file! +postgres_container_name=cgapp-postgres # Set PostgreSQL version (for example, 13.2) postgres_version=latest # Set PostgreSQL port number, @@ -75,7 +78,7 @@ postgres_db=postgres postgres_ssl_mode=disable # -# Go-Migrate configuration: +# Go-Migrate configuration (DB migrations): # # Set migration number, @@ -87,6 +90,9 @@ migrate_number=1 # Redis configuration (backend cache): # +# Set Redis container name +# MUST BE MATCH to the port that is listed in your `./backend/.env` file! +redis_container_name=cgapp-redis # Set Redis version (for example, 6.2) redis_version=latest # Set Redis port number,