Skip to content
This repository has been archived by the owner on Aug 21, 2022. It is now read-only.

Commit

Permalink
feat: adjust volume folder owner if set
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Jan 17, 2021
1 parent ec913fe commit 6f47fe5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tasks/steps/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
block:
- name: "Container hooks location"
set_fact:
managedContainerFolders: ["{{ stackhead__containerhooks_location }}"]
managedContainerFolders: [{ 'path': "{{ stackhead__containerhooks_location }}" }]
- name: "Collect local volumes"
set_fact:
managedContainerFolders: "{{ managedContainerFolders|d([]) + [ ''~ stackhead__containerdata_location_services|format(item.0.name, item.1.src|d()) ~'' ] }}"
managedContainerFolders: "{{ managedContainerFolders|d([]) + [ { 'path': stackhead__containerdata_location_services|format(item.0.name, item.1.src|d()), 'user': item.1.user|d('') } ] }}"
when: item.1.type == 'local'
with_subelements:
- "{{ app_config.container.services }}"
Expand All @@ -16,7 +16,7 @@
skip_missing: True
- name: "Collect global volumes"
set_fact:
managedContainerFolders: "{{ managedContainerFolders|d([]) + [ '' ~ stackhead__containerdata_location_global|format(item.1.src|d()) ~ '' ] }}"
managedContainerFolders: "{{ managedContainerFolders|d([]) + [ { 'path': stackhead__containerdata_location_global|format(item.1.src|d()), 'user': item.1.user|d('') } ] }}"
when: item.1.type == 'global'
with_subelements:
- "{{ app_config.container.services }}"
Expand All @@ -25,7 +25,7 @@
skip_missing: True
- name: "Collect custom volumes"
set_fact:
managedContainerFolders: "{{ managedContainerFolders|d([]) + [ '' ~ item.1.src ~ '' ] }}"
managedContainerFolders: "{{ managedContainerFolders|d([]) + [ { 'path': item.1.src, 'user': item.1.user|d('') } ] }}"
when: item.1.type == 'custom'
with_subelements:
- "{{ app_config.container.services }}"
Expand All @@ -35,17 +35,27 @@
- block:
- name: "StackHead::Container || Checking project Docker folders"
stat:
path: "{{ item }}"
path: "{{ item.path }}"
register: folder_stats
with_items: "{{ managedContainerFolders }}"
- name: "StackHead::Container || Creating missing project Docker folders"
file:
path: "{{ item.item }}"
path: "{{ item.item.path }}"
state: directory
mode: 0755
owner: stackhead
group: stackhead
when: item.stat.exists == false
with_items: "{{ folder_stats.results }}"
- name: Adjust Docker folder permissions
file:
path: "{{ item.path }}"
owner: "{{ (item.user|string).split(':')[0] }}"
group: stackhead
when: item.user is defined and item.user != ''
with_items: "{{ managedContainerFolders }}"
when: managedContainerFolders|d([]) != []

- name: remove old hook files
raw: "rm -rf {{ stackhead__containerhooks_location }}/*"
- block:
Expand Down
18 changes: 18 additions & 0 deletions templates/terraform/docker.tf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ resource "docker_container" "stackhead-{{ project_name }}-{{ service.name }}" {
name = "stackhead-{{ project_name }}-{{ service.name }}"
restart = "always"

{# Ensure volume directories have correct user (there was an issue with mariadb) #}
{%- for volume in service.volumes|default([]) %}

{%- if volume.type == "local" %}
{%- set path = stackhead__containerdata_location_services|format(service.name, volume.src) %}
{%- elif volume.type == "custom" %}
{%- set path = volume.src %}
{%- elif volume.type == "global" %}
{%- set path = stackhead__containerdata_location_global|format(volume.src) %}
{%- endif %}

{%- if volume.user|d('') != '' and path|d('') != '' %}
provisioner "local-exec" {
command = "chown -R {{ volume.user }}:stackhead {{ path }}"
}
{%- endif %}
{%- endfor %}

{% if service.hooks is defined %}
{% if service.hooks.execute_after_setup is defined %}
provisioner "local-exec" {
Expand Down

0 comments on commit 6f47fe5

Please sign in to comment.