fix create service script for infra and add phoneassistant role

This commit is contained in:
Elizabeth Hunt 2025-01-13 21:24:32 -08:00
parent 040994898b
commit c0ab7feac5
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
5 changed files with 69 additions and 9 deletions

View File

@ -20,16 +20,16 @@ SERVICE_ORIGIN=$(prompt_with_default "Enter service origin URL" "git@git.simponi
INTERNAL=$(prompt_with_default "Is the service internal? (yes/no)" "no")
SERVICE_HOST=$(prompt_with_default "Enter service host" "ryo")
PACKAGE_PATH=$(prompt_with_default "Enter package path" "$HOME/git/simponic/$SERVICE")
HATECOMPUTERS_API_KEY=$(prompt_with_default "Enter hatecomputers API key (paste from clipboard)" "$(pbpaste)")
HATECOMPUTERS_API_KEY=$(prompt_with_default "Enter hatecomputers API key (paste from clipboard)" "$(wl-paste)")
function render_template() {
cp -r template $PACKAGE_PATH
ggrep -rlZ "{{ service }}" $PACKAGE_PATH | xargs -0 gsed -i "s/{{ service }}/$SERVICE/g"
ggrep -rlZ "{{ service_host }}" $PACKAGE_PATH | xargs -0 gsed -i "s/{{ service_host }}/$SERVICE_HOST/g"
ggrep -rlZ "{{ service_repo }}" $PACKAGE_PATH | xargs -0 gsed -i "s/{{ service_repo }}/$(echo $SERVICE_REPO | sed 's/\//\\\//g')/g"
ggrep -rlZ "{{ service_port }}" $PACKAGE_PATH | xargs -0 gsed -i "s/{{ service_port }}/$SERVICE_PORT/g"
ggrep -rlZ "{{ service_title }}" $PACKAGE_PATH | xargs -0 gsed -i "s/{{ service_title }}/$SERVICE_TITLE/g"
grep -rlZ "{{ service }}" $PACKAGE_PATH | xargs -0 sed -i "s/{{ service }}/$SERVICE/g"
grep -rlZ "{{ service_host }}" $PACKAGE_PATH | xargs -0 sed -i "s/{{ service_host }}/$SERVICE_HOST/g"
grep -rlZ "{{ service_repo }}" $PACKAGE_PATH | xargs -0 sed -i "s/{{ service_repo }}/$(echo $SERVICE_REPO | sed 's/\//\\\//g')/g"
grep -rlZ "{{ service_port }}" $PACKAGE_PATH | xargs -0 sed -i "s/{{ service_port }}/$SERVICE_PORT/g"
grep -rlZ "{{ service_title }}" $PACKAGE_PATH | xargs -0 sed -i "s/{{ service_title }}/$SERVICE_TITLE/g"
}
function test_and_commit_code() {
@ -60,12 +60,12 @@ function add_dns_records() {
name="$SERVICE.internal.simponic.xyz."
content="$SERVICE_HOST.internal.simponic.xyz."
curl -H "Authorization: Bearer $HATECOMPUTERS_API_KEY" \
-F "type=CNAME&name=$name&content=$content.internal.simponic.xyz.&ttl=43200&internal=on" \
-F "type=CNAME&name=$name&content=$content&ttl=43200&internal=on" \
$DNS_ENDPOINT
else
name="$SERVICE.simponic.xyz."
content="$SERVICE_HOST.simponic.xyz."
gsed -i "s|;; CNAME Records|;; CNAME Records\n$name\t43200\tIN\tCNAME\t$content|" $BIND_FILE
sed -i "s|;; CNAME Records|;; CNAME Records\n$name\t43200\tIN\tCNAME\t$content|" $BIND_FILE
fi
}
@ -149,6 +149,14 @@ function create_role() {
group: root
mode: 0777
- name: ensure $SERVICE env exist
file:
path: /etc/docker/compose/$SERVICE/.env
state: file
owner: root
group: root
mode: 0700
- name: build $SERVICE docker-compose.yml.j2
template:
src: ../templates/docker-compose.yml.j2

View File

@ -0,0 +1,4 @@
- name: deploy phoneassistant
hosts: phoneassistant
roles:
- phoneassistant

View File

@ -93,4 +93,6 @@ ryo ansible_user=root ansible_connection=ssh
[something]
ryo ansible_user=root ansible_connection=ssh
[whois]
ryo ansible_user=root ansible_connection=ssh
ryo ansible_user=root ansible_connection=ssh
[phoneassistant]
johan ansible_user=root ansible_connection=ssh

View File

@ -0,0 +1,30 @@
---
- name: ensure phoneassistant docker/compose exist
file:
path: /etc/docker/compose/phoneassistant
state: directory
owner: root
group: root
mode: 0700
- name: ensure phoneassistant db exist
file:
path: /etc/docker/compose/phoneassistant/db
state: directory
owner: root
group: root
mode: 0777
- name: build phoneassistant docker-compose.yml.j2
template:
src: ../templates/docker-compose.yml.j2
dest: /etc/docker/compose/phoneassistant/docker-compose.yml
owner: root
group: root
mode: u=rw,g=r,o=r
- name: daemon-reload and enable phoneassistant
ansible.builtin.systemd_service:
state: restarted
enabled: true
name: docker-compose@phoneassistant

View File

@ -0,0 +1,16 @@
version: "3"
services:
api:
restart: always
image: git.simponic.xyz/simponic/phoneassistant
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:8080/api/health"]
interval: 5s
timeout: 10s
retries: 5
env_file: .env
volumes:
- ./db:/app/db
ports:
- "127.0.0.1:9082:8080"