summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcreate_service.sh24
-rw-r--r--deploy-phoneassistant.yml4
-rw-r--r--inventory4
-rw-r--r--roles/phoneassistant/tasks/main.yml30
-rw-r--r--roles/phoneassistant/templates/docker-compose.yml.j216
5 files changed, 69 insertions, 9 deletions
diff --git a/create_service.sh b/create_service.sh
index 7f6766c..febf42a 100755
--- a/create_service.sh
+++ b/create_service.sh
@@ -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
diff --git a/deploy-phoneassistant.yml b/deploy-phoneassistant.yml
new file mode 100644
index 0000000..3f73f95
--- /dev/null
+++ b/deploy-phoneassistant.yml
@@ -0,0 +1,4 @@
+- name: deploy phoneassistant
+ hosts: phoneassistant
+ roles:
+ - phoneassistant
diff --git a/inventory b/inventory
index 6182f0a..d429abe 100644
--- a/inventory
+++ b/inventory
@@ -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 \ No newline at end of file
+ryo ansible_user=root ansible_connection=ssh
+[phoneassistant]
+johan ansible_user=root ansible_connection=ssh \ No newline at end of file
diff --git a/roles/phoneassistant/tasks/main.yml b/roles/phoneassistant/tasks/main.yml
new file mode 100644
index 0000000..2e35377
--- /dev/null
+++ b/roles/phoneassistant/tasks/main.yml
@@ -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
diff --git a/roles/phoneassistant/templates/docker-compose.yml.j2 b/roles/phoneassistant/templates/docker-compose.yml.j2
new file mode 100644
index 0000000..38b6101
--- /dev/null
+++ b/roles/phoneassistant/templates/docker-compose.yml.j2
@@ -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"