From 2f767a18266c4024c759e4f095e2bc1f9bbed849 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Tue, 17 Dec 2024 17:52:46 +0530 Subject: [PATCH] Hugo --- hugo/files/Dockerfile | 23 +++++++++++++++++++++++ hugo/files/gitea | 2 ++ hugo/files/nginx.conf.j2 | 19 +++++++++++++++++++ hugo/playbook.yaml | 39 +++++++++++++++++++++++++++++++++++++++ hugo/vars/default.yml | 8 ++++++++ 5 files changed, 91 insertions(+) create mode 100644 hugo/files/Dockerfile create mode 100644 hugo/files/gitea create mode 100644 hugo/files/nginx.conf.j2 create mode 100644 hugo/playbook.yaml create mode 100644 hugo/vars/default.yml diff --git a/hugo/files/Dockerfile b/hugo/files/Dockerfile new file mode 100644 index 0000000..177a034 --- /dev/null +++ b/hugo/files/Dockerfile @@ -0,0 +1,23 @@ +FROM alpine:latest + +# Install dependencies +RUN apk add --no-cache git curl tar + +# Download and install Hugo +RUN HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep 'tag_name' | cut -d\" -f4) && \ + curl -L https://github.com/gohugoio/hugo/releases/download/${HUGO_VERSION}/hugo_extended_${HUGO_VERSION#v}_Linux-64bit.tar.gz | tar -xz && \ + mv hugo /usr/local/bin/ + +# Create a new Hugo site +RUN hugo new site mysite + +# Add Decap CMS +WORKDIR /mysite/static/admin +RUN git clone https://github.com/decapcms/decap.git . + +# Expose volume for Hugo site +VOLUME /mysite + +# Serve the site +EXPOSE 1313 +CMD ["hugo", "server", "--bind=0.0.0.0"] diff --git a/hugo/files/gitea b/hugo/files/gitea new file mode 100644 index 0000000..862a073 --- /dev/null +++ b/hugo/files/gitea @@ -0,0 +1,2 @@ +#!/bin/sh +ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@" diff --git a/hugo/files/nginx.conf.j2 b/hugo/files/nginx.conf.j2 new file mode 100644 index 0000000..b49ac7f --- /dev/null +++ b/hugo/files/nginx.conf.j2 @@ -0,0 +1,19 @@ +server { + + listen 80; + server_name {{ http_host }}; + +# location /_/static { + +# alias /path/to/gitea/public; +# } + + location / { + proxy_pass http://localhost:3000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} + diff --git a/hugo/playbook.yaml b/hugo/playbook.yaml new file mode 100644 index 0000000..c7a58f3 --- /dev/null +++ b/hugo/playbook.yaml @@ -0,0 +1,39 @@ +--- +- hosts: all + become: yes + tasks: + - name: Get the latest Hugo release + get_url: + url: https://github.com/gohugoio/hugo/releases/latest/download/hugo_extended_{{ ansible_system }}-64bit.tar.gz + dest: /tmp/hugo.tar.gz + mode: '0755' + + - name: Extract Hugo binary + unarchive: + src: /tmp/hugo.tar.gz + dest: /tmp + remote_src: yes + + - name: Move Hugo binary to /usr/local/bin + command: mv /tmp/hugo /usr/local/bin/hugo + + - name: Check if Hugo project exists + stat: + path: "{{ host_directory }}" + register: hugo_project + + - name: Create new Hugo project + command: hugo new site "{{ host_directory }}" + when: not hugo_project.stat.exists + + - name: Add Decap CMS with Gitea integration + block: + - name: Clone Decap CMS + git: + repo: 'https://github.com/decapcms/decap.git' + dest: "{{ host_directory }}/themes/decap" + + - name: Configure Gitea integration + lineinfile: + path: "{{ host_directory }}/config.toml" + line: 'theme = "decap"' \ No newline at end of file diff --git a/hugo/vars/default.yml b/hugo/vars/default.yml new file mode 100644 index 0000000..ce5f800 --- /dev/null +++ b/hugo/vars/default.yml @@ -0,0 +1,8 @@ +--- +http_host: "hugo.tanshu.com" +http_conf: "hugo.tanshu.com.conf" +http_url: "https://hugo.tanshu.com" + +container_name: gitea +container_image: gitea/gitea:latest +