Skip to content

Instantly share code, notes, and snippets.

@aman207
Last active February 4, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aman207/40f97b9feead389d1378a7ad2cee0992 to your computer and use it in GitHub Desktop.
Save aman207/40f97b9feead389d1378a7ad2cee0992 to your computer and use it in GitHub Desktop.
playbook to create an instance of mealie without using docker
The files below are what I used to create an instance of mealie without having to use docker. It uses Ubuntu 20.04 as the OS.
Don't expect the ansible playbook to work via copy and paste, you'll need to edit it according to your setup.
This is just an example of the steps required.
{
auto_https off
admin off
}
:80 {
@proxied path /api/* /docs /openapi.json
@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *.webp
}
# Handles Recipe Images / Assets
handle_path /api/media/recipes/* {
header @static Cache-Control max-age=31536000
root * /app/data/recipes/
file_server
}
handle @proxied {
uri strip_suffix /
reverse_proxy http://127.0.0.1:9000
}
handle {
header @static Cache-Control max-age=31536000
root * /opt/mealie/frontend/dist
try_files {path}.html {path} /
file_server
}
}
[Unit]
Description=Mealie API
After=network.target
[Service]
Environment="TZ=..."
Environment="TOKEN_TIME=43800"
User=onionuser
Group=onionuser
WorkingDirectory=/opt/mealie
ExecStart=/usr/local/bin/poetry run uvicorn mealie.app:app --host 0.0.0.0 --port 9000
[Install]
WantedBy=default.target
#!/bin/bash
#Script to update mealie
set -e
sudo systemctl stop mealie-api caddy
cd /opt/mealie
sudo -u onionuser git fetch
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
sudo -u onionuser git checkout $latestTag
cd /opt/mealie/frontend
sudo rm -rf dist
sudo rm -rf node_modules
sudo -u onionuser npm install
sudo NODE_OPTIONS='--openssl-legacy-provider' -u onionuser npm run build
sudo -u onionuser /usr/local/bin/poetry env use /usr/bin/python3.9
sudo -u onionuser /usr/local/bin/poetry update
sudo -u onionuser /usr/local/bin/poetry install
sudo systemctl start mealie-api caddy
---
- hosts: all
remote_user: root
become: true
gather_facts: no
tasks:
- name: install nodejs 17 repo
shell:
cmd: 'curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -'
creates: /etc/apt/sources.list.d/nodesource.list
warn: false
- name: install caddy gpg key
shell:
cmd: 'curl -1sLf https://dl.cloudsmith.io/public/caddy/stable/gpg.key | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc'
creates: /etc/apt/trusted.gpg.d/caddy-stable.asc
warn: false
- name: install caddy repo
shell:
cmd: 'curl -1sLf https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt | sudo tee /etc/apt/sources.list.d/caddy-stable.list'
creates: /etc/apt/sources.list.d/caddy-stable.list
warn: false
#Required for python3.9
#I was using Ubuntu 20.04 which only had python3.8
- name: add deadsnakes/ppa
apt_repository:
repo: 'ppa:deadsnakes/ppa'
- name: install required packages
apt:
name:
- python3.9
- python3.9-dev
- python3.9-venv
- nodejs
- pip
- build-essential
- libpq-dev
- libwebp-dev
- libsasl2-dev
- libldap2-dev
- libssl-dev
- gnupg
- gnupg2
- gnupg1
- debian-keyring
- debian-archive-keyring
- apt-transport-https
- caddy
- acl
- git
state: latest
update_cache: yes
#mealie requires a specific version
- name: install poetry via pip
pip:
name: poetry==1.1.6
- name: git clone mealie
git:
repo: https://github.com/hay-kot/mealie
dest: /opt/mealie
force: no
- name: change permissions of mealie
file:
path: /opt/mealie
state: directory
owner: onionuser
group: onionuser
recurse: yes
- name: get latest tag
shell:
cmd: 'git describe --tags `git rev-list --tags --max-count=1`'
args:
chdir: /opt/mealie
register: latest_tag
become_user: onionuser
changed_when: false
- name: set fact
set_fact: mealie_latest="{{ latest_tag.stdout }}"
- name: get current checked-out tag
command:
cmd: 'git describe --tags --abbrev=0 --exact-match'
args:
chdir: /opt/mealie
register: current_tag
become_user: onionuser
failed_when: false
changed_when: false
- name: checkout to tag
command:
cmd: 'git checkout {{ mealie_latest }}'
args:
chdir: /opt/mealie
when: not current_tag.stdout | regex_search("{{ mealie_latest }}")
become_user: onionuser
- name: check if /opt/mealie/frontend/node_modules exists
stat:
path: /opt/mealie/frontend/node_modules
register: nodemodules_check
failed_when: false
changed_when: false
- name: check if /opt/mealie/frontend/dist exists
stat:
path: /opt/mealie/frontend/dist
register: nodedist_check
failed_when: false
changed_when: false
- name: get output of poetry env list
command:
cmd: /usr/local/bin/poetry env list
args:
chdir: /opt/mealie
register: poetry_env_list
become_user: onionuser
changed_when: false
- name: "check if /home/onionuser/.cache/pypoetry/virtualenvs/{{ poetry_env_list.stdout | regex_search('(mealie.*)') }} exists"
stat:
path: "/home/onionuser/.cache/pypoetry/virtualenvs/{{ poetry_env_list.stdout | regex_search('(mealie.*)') }}"
register: poetryinstall_check
failed_when: false
changed_when: false
- name: run npm install
command:
cmd: 'npm install'
args:
chdir: /opt/mealie/frontend
become_user: onionuser
when: not nodemodules_check.stat.exists
- name: run npm run build
command:
cmd: 'npm run build'
args:
chdir: /opt/mealie/frontend
become_user: onionuser
environment:
NODE_OPTIONS: '--openssl-legacy-provider'
when: not nodedist_check.stat.exists
- name: run /usr/local/bin/poetry install
command:
cmd: '/usr/local/bin/poetry install'
args:
chdir: /opt/mealie
become_user: onionuser
when: not poetryinstall_check.stat.exists
- name: create /app and set permissions
file:
path: /app
state: directory
owner: onionuser
group: onionuser
- name: initalize the database
command:
cmd: /usr/local/bin/poetry run python mealie/db/init_db.py
args:
chdir: /opt/mealie
become_user: onionuser
register: initdb_output
changed_when: not initdb_output.stdout | regex_search("Database Exists")
- name: copy Caddyfile to /etc/caddy/Caddyfile
copy:
src: templates/mealie/etc/caddy/Caddyfile
dest: /etc/caddy/Caddyfile
notify: restart caddy
- name: start caddy
systemd:
name: caddy
state: started
enabled: yes
- name: copy mealie-api.service
copy:
src: templates/mealie/etc/systemd/system/mealie-api.service
dest: /etc/systemd/system/mealie-api.service
owner: root
group: root
- name: start and enable mealie-api.service
systemd:
name: mealie-api.service
state: started
enabled: yes
handlers:
- name: restart caddy
systemd:
name: caddy
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment