diff --git a/all.yml b/all.yml index efa6de0..11dd419 100644 --- a/all.yml +++ b/all.yml @@ -43,3 +43,7 @@ - funwkhale - music - docker + - role: hugo + tags: + - docker + - hugo diff --git a/roles/hugo/tasks/main.yml b/roles/hugo/tasks/main.yml new file mode 100644 index 0000000..50057f0 --- /dev/null +++ b/roles/hugo/tasks/main.yml @@ -0,0 +1,37 @@ +--- +- name: Create Hugo directory + file: + path: "{{ hugo_folder_name }}" + state: directory + owner: "{{ base_user_name }}" + group: "{{ base_user_name }}" + mode: 0755 + +- name: Copy Hugo Compose file + template: + src: docker-compose.yml.j2 + # Remove .j2 extension + dest: "{{ hugo_folder_name }}/docker-compose.yml" + owner: "{{ base_user_name }}" + group: "{{ base_user_name }}" + mode: 0644 + +- name: Clone blog + ansible.builtin.git: + repo: "{{ repository_url }}" + dest: "{{ hugo_website }}" + force: yes + ignore_errors: yes + +- name: Pull new stuff + shell: + cmd: git pull + chdir: "{{ hugo_website }}" + +- name: Ensure container is up to date + community.docker.docker_compose: + project_src: "{{ hugo_folder_name }}" + remove_orphans: yes + pull: yes + recreate: smart + state: present diff --git a/roles/hugo/templates/docker-compose.yml.j2 b/roles/hugo/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..9942c99 --- /dev/null +++ b/roles/hugo/templates/docker-compose.yml.j2 @@ -0,0 +1,48 @@ +version: "{{ compose_version }}" + +networks: + proxy: + name: "{{ traefik_network }}" + +# Use a bind mount for Hugo data, easier to pull new versions of blog +volumes: + website_files: + driver: local + driver_opts: + type: none + device: "{{ hugo_website }}" + o: bind + website_public: + driver: local + driver_opts: + type: none + device: "{{ hugo_website }}/public" + o: bind + +services: + builder: + container_name: hugo_builder + image: "klakegg/hugo:{{ hugo_version }}" + volumes: + - website_files:/src + # Hugo will build only + # when triggered + restart: on-failure + + front: + container_name: hugo_front + image: nginx:alpine + volumes: + - website_public:/usr/share/nginx/html:ro + labels: + traefik.http.routers.hugo.entrypoints: websecure + traefik.http.routers.hugo.rule: "Host(`blog.{{ domain_name }}`)" + traefik.http.services.hugo.loadbalancer.server.port: 80 + traefik.enable: true + networks: + - proxy + read_only: true + tmpfs: + - /var/cache/nginx + - /run + restart: unless-stopped diff --git a/roles/hugo/vars/main.yml b/roles/hugo/vars/main.yml new file mode 100644 index 0000000..604cb34 --- /dev/null +++ b/roles/hugo/vars/main.yml @@ -0,0 +1,6 @@ +hugo_folder_name: "{{ docker_files }}/hugo" +hugo_website: "{{ hugo_folder_name }}/website" +# Use extended edition with Git inside +# to read git info (useful for lastmod) +hugo_version: 0.83.1-ext-alpine +repository_url: https://git.chosto.me/Chosto/blog.git