diff --git a/defaults/main.yml b/defaults/main.yml index fb5e968..c6f98f0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,7 +5,13 @@ hedy_user_username: hedy hedy_user_groupname: hedy hedy_base_path: /home/hedy hedy_data_path: /home/hedy/data + +# Building. Default is to build on the target. To build elsewhere, +# change host ('localhost' for Ansible host) and perhaps path. hedy_docker_src_files_path: /home/hedy/docker-src +hedy_builder_host: "{{ ansible_host }}" +hedy_builder_username: "{{ hedy_user_username }}" +hedy_builder_groupname: "{{ hedy_builder_username }}" hedy_docker_image: hedy:latest hedy_container_image_self_build: true diff --git a/tasks/build-hedy.yml b/tasks/build-hedy.yml new file mode 100644 index 0000000..f8618de --- /dev/null +++ b/tasks/build-hedy.yml @@ -0,0 +1,36 @@ +--- + +- name: Hedy build paths + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0700 + owner: "{{ hedy_builder_username }}" + group: "{{ hedy_builder_groupname }}" + with_items: + - {path: "{{ hedy_docker_src_files_path }}"} + +- name: Hedy build git repository + ansible.builtin.git: + repo: "{{ hedy_container_image_self_build_repo }}" + dest: "{{ hedy_docker_src_files_path }}" + version: "{{ hedy_container_image_self_build_version }}" + force: "yes" + register: hedy_git_pull_results + +- name: Hedy build translations + command: + cmd: "pybabel compile -f -d translations" + chdir: "{{ hedy_docker_src_files_path }}" + #when: "hedy_git_pull_results.changed" + +- name: Hedy build Docker image + community.docker.docker_image: + name: "{{ hedy_docker_image }}" + source: build + force_source: "{{ hedy_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ hedy_docker_src_files_path }}" + pull: true + push: true diff --git a/tasks/main.yml b/tasks/main.yml index 651d739..5e86677 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,45 +15,25 @@ with_items: - {path: "{{ hedy_base_path }}", when: true} - {path: "{{ hedy_data_path }}", when: true} - - {path: "{{ hedy_docker_src_files_path }}", when: "{{ hedy_container_image_self_build }}"} when: "item.when | bool" -- name: Ensure Hedy repository is present on self-build - ansible.builtin.git: - repo: "{{ hedy_container_image_self_build_repo }}" - dest: "{{ hedy_docker_src_files_path }}" - version: "{{ hedy_container_image_self_build_version }}" - force: "yes" +- delegate_to: "{{ hedy_builder_host }}" + when: "hedy_container_image_self_build | bool" become: true - become_user: "{{ hedy_user_username }}" - register: hedy_git_pull_results - when: "hedy_container_image_self_build | bool" - -- command: - cmd: "pybabel compile -f -d translations" - chdir: "{{ hedy_docker_src_files_path }}" - #when: "hedy_container_image_self_build | bool and hedy_git_pull_results.changed" - -- name: Ensure Hedy Docker image is built - community.docker.docker_image: - name: "{{ hedy_docker_image }}" - source: build - force_source: "{{ hedy_git_pull_results.changed }}" - build: - dockerfile: Dockerfile - path: "{{ hedy_docker_src_files_path }}" - pull: true - when: "hedy_container_image_self_build | bool" + become_user: "{{ hedy_builder_username }}" + block: + - include_tasks: "build-hedy.yml" - name: Hedy container running community.docker.docker_container: name: "hedy" image: "{{ hedy_docker_image }}" + pull: "{{ hedy_pull and hedy_docker_image.endswith(':latest') }}" restart_policy: unless-stopped published_ports: - "8080:8080" volumes: - #- "{{ hedy_data_path }}:/app" + - "{{ hedy_data_path }}/dev_database.json:/app/dev_database.json" env: BASE_URL: "{{ hedy_base_url }}" # https://github.com/hedyorg/hedy/wiki/Hedy-Development-Process#environment-variables