Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add candles api #12

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions roles/candles_api/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
candles_api_binary_repository: nebula-dex/candles-api
candles_api_binary_version: v0.0.1
candles_api_twelvedata_api_key: ""
candles_api_polygonio_api_key: ""
candles_api_with_caddy_config: false
candles_api_caddy_config_destination: /etc/caddy/sites/candles-api.caddy
candles_api_domains: []
9 changes: 9 additions & 0 deletions roles/candles_api/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Restart candles-api
ansible.builtin.service:
state: "restarted"
daemon_reload: true
enabled: true
name: candles-api
listen: "Restart candles-api"
when: not ansible_check_mode
3 changes: 3 additions & 0 deletions roles/candles_api/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- vega_caddy_server
56 changes: 56 additions & 0 deletions roles/candles_api/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Ensure group "candles-api" exists
ansible.builtin.group:
name: candles-api
state: present

- name: Ensure a 'candles-api' user exists
ansible.builtin.user:
name: candles-api
create_home: true
password: ''
shell: /bin/bash
groups: sudo,candles-api
append: true

- name: Download candles-api binary
ansible.builtin.get_url:
force: true
url: "https://github.com/{{- candles_api_binary_repository -}}/releases/download/{{- candles_api_binary_version -}}/candles-api-linux-amd64.zip"
dest: &bin_dest /tmp/candles_api.zip
mode: '0600'

- name: Unpack candles-api
ansible.builtin.unarchive:
src: *bin_dest
remote_src: true
dest: /tmp
when: not ansible_check_mode

- name: Copy candles-api binary
ansible.builtin.copy:
remote_src: true
src: "/tmp/candles-api-linux-amd64"
dest: /usr/local/bin/candles-api
owner: root
group: root
mode: '0755'
when: not ansible_check_mode

- name: Install candles-api systemd files
ansible.builtin.template:
src: "lib/systemd/system/candles-api.service.j2"
dest: "/lib/systemd/system/candles-api.service"
owner: "root"
group: "root"
mode: "0644"
notify: "Restart candles-api"

- name: Install Caddyfile
ansible.builtin.template:
src: "etc/caddy/sites/candles-api.caddy.j2"
dest: "{{- candles_api_caddy_config_destination -}}"
owner: "caddy"
group: "caddy"
mode: "0644"
notify: "Restart caddy"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- candles_api_domains | map('ansible.builtin.regex_replace', '$', ':443') | join(', ') }} {
reverse_proxy http://localhost:8889
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[Unit]
Description=vegavisor
Documentation=https://github.com/nebula-dex/candles-api
After=network.target network-online.target
Requires=network-online.target
# Configure unit start rate limiting. Units which are started more than burst times within an interval time span are not permitted to start any more.
# Use StartLimitIntervalSec= to configure the checking interval and StartLimitBurst= to configure how many starts per interval are allowed.
StartLimitIntervalSec=30s
StartLimitBurst=3

[Service]
Environment="TWELVE_DATA_API_KEY={{- candles_api_twelvedata_api_key -}}"
Environment="POLYGON_API_KEY={{- candles_api_polygonio_api_key -}}"
User=candles-api
Group=candles-api
ExecStart=/usr/local/bin/candles-api
TimeoutStopSec=10s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=false
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
# Configures the time to sleep before restarting a service
RestartSec=30s
# Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached
Restart=always

[Install]
WantedBy=multi-user.target