diff --git a/ansible/deploy.yml b/ansible/deploy.yml new file mode 100755 index 0000000..c7b5734 --- /dev/null +++ b/ansible/deploy.yml @@ -0,0 +1,84 @@ +--- +- name: Deploy gomoku project + hosts: all + become: yes + vars: + app_user: 'gomoku' + app_home: '/home/{{ app_user }}' + + tasks: + - name: Ensure user exists + user: + name: '{{ app_user }}' + shell: /bin/bash + create_home: yes + home: '{{ app_home }}' + + - name: Create data directory + file: + path: '{{ app_home }}/public' + state: directory + owner: '{{ app_user }}' + group: '{{ app_user }}' + + - name: Copy binary to target location + copy: + src: ../target/gomoku + dest: '{{ app_home }}/gomoku' + owner: '{{ app_user }}' + group: '{{ app_user }}' + mode: '0755' + + - name: Copy data directory + synchronize: + src: ../public/ + dest: '{{ app_home }}/public/' + recursive: yes + owner: no + group: no + archive: yes + delete: yes + + - name: Ensure Caddy directory exists + file: + path: /etc/caddy/sites + state: directory + + - name: Copy Caddy configuration + copy: + src: gomoku.caddy + dest: /etc/caddy/sites/gomoku.caddy + owner: root + group: root + mode: '0644' + register: caddy_config_copy + + - name: Restart Caddy service if config changed + systemd: + name: caddy + state: restarted + daemon_reload: yes + when: caddy_config_copy.changed + + - name: Ensure Supervisor directory exists + file: + path: /etc/supervisor/conf.d + state: directory + + - name: Copy Supervisor configuration + copy: + src: gomoku.supervisor + dest: /etc/supervisor/conf.d/gomoku.conf + owner: root + group: root + mode: '0644' + + - name: Reload Supervisor + supervisorctl: + name: gomoku + state: present + + - name: Restart the service + supervisorctl: + name: gomoku + state: restarted diff --git a/ansible/gomoku.caddy b/ansible/gomoku.caddy new file mode 100755 index 0000000..794590f --- /dev/null +++ b/ansible/gomoku.caddy @@ -0,0 +1,3 @@ +gomoku.sepiatones.xyz { + reverse_proxy localhost:3002 +} diff --git a/ansible/gomoku.supervisor b/ansible/gomoku.supervisor new file mode 100755 index 0000000..f5e5b3a --- /dev/null +++ b/ansible/gomoku.supervisor @@ -0,0 +1,10 @@ +[program:gomoku] +command=/home/gomoku/gomoku +directory=/home/gomoku +user=gomoku +autostart=true +autorestart=true +startretries=3 +stderr_logfile=/var/log/supervisor/gomoku.err.log +stdout_logfile=/var/log/supervisor/gomoku.out.log +environment=PORT=3002 diff --git a/ansible/hosts.ini b/ansible/hosts.ini new file mode 100755 index 0000000..2a3e189 --- /dev/null +++ b/ansible/hosts.ini @@ -0,0 +1,3 @@ +# It is expected that you have sepiatonesxyz defined in your .ssh/config +[production] +sepiatonesxyz ansible_host=sepiatonesxyz ansible_python_interpreter=/usr/bin/python3.11 diff --git a/justfile b/justfile index 1d39d3e..0e5ff4b 100755 --- a/justfile +++ b/justfile @@ -8,8 +8,7 @@ build: bun build --compile --minify --target bun --outfile ./target/gomoku ./src/index.ts deploy: build - rsync -avz target/gomoku sepiatonesxyz:~/gomoku/gomoku - rsync -avz --delete public/ sepiatonesxyz:~/gomoku/public + ansible-playbook -i ansible/hosts.ini ansible/deploy.yml test: bun test