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

Ansible (Debian-only) #309

Open
martin-braun opened this issue Jun 4, 2024 · 2 comments
Open

Ansible (Debian-only) #309

martin-braun opened this issue Jun 4, 2024 · 2 comments

Comments

@martin-braun
Copy link

martin-braun commented Jun 4, 2024

The "Manual, from source" steps could be incorporated into an Ansible script. I used to do this for Directus deployments and it should be pretty straight forward if we limit ourselves to Debian.

Reasons for this:

  • No docker, not everyone likes Docker, it's just another layer, especially when using Proxmox which doesn't officially support Docker
  • Easier updates, since Ansible deployments can be written in a way that it always rolls over, it's just a simple redeployment
  • Mass deployment, since an inventory file with many hosts can be provided, this is handy when you want to keep public and private password protected instances as well as personal and work-related environments apart

Cons for this:

  • nvm and node don't ship for Debian, but I have a solution for this (nodesource.org), but it makes the Ansible script less portable, hence only Debian would be supported. I might consider Alpine Linux, though.

I'm making this issue to see if someone else is interested in this? (You could assign me to this issue right away)

@martin-braun martin-braun changed the title Ansible Ansible (Debian-only) Jun 4, 2024
@lpirl
Copy link

lpirl commented Jun 4, 2024

Great idea.

It is probably hard to create a role that fits the taste of everyone, but if we don't try, we don't know.

I use the following quick-and-dirty role for updating a small deployment. Initial installation would need some more steps, as installing npm, etc.

# file: <role_name>/defaults/main.yml

file_transfer_app_user_name: file-transfer
# file: <role_name>/tasks/main.yml

- name: create user for file transfer app
  register: create_file_transfer_app_user_result
  user:
    name: "{{ file_transfer_app_user_name }}"
    comment: "user for running the file transfer Web app"
    group: www-data



- name: reset PsiTransfer sources
  register: git_checkout
  command: git checkout .
  args:
    chdir: >-
      {{ create_file_transfer_app_user_result.home }}/psitransfer
  changed_when: "'Updated 0 paths' not in git_checkout.stderr"
  become_user: "{{ file_transfer_app_user_name }}"

- name: update PsiTransfer sources
  register: git_pull
  command: git pull
  args:
    chdir: >-
      {{ create_file_transfer_app_user_result.home }}/psitransfer
  changed_when: "'is up to date' not in git_pull.stdout"
  become_user: "{{ file_transfer_app_user_name }}"



- name: build
  command: "{{ item.cmd }}"
  args:
    chdir: "{{ item.dir }}"
  with_items:
    - cmd: npm install
      dir: "{{ create_file_transfer_app_user_result.home }}/psitransfer/app"
    - cmd: npm run build
      dir: "{{ create_file_transfer_app_user_result.home }}/psitransfer/app"
    - cmd: npm install
      dir: "{{ create_file_transfer_app_user_result.home }}/psitransfer"

  become_user: "{{ file_transfer_app_user_name }}"
  when: git_pull.changed



- name: restart file transfer app
  service:
    name: psitransfer
    state: restarted
  when: git_pull.changed

Could maybe serve as a starting point.

@martin-braun
Copy link
Author

martin-braun commented Jun 4, 2024

@lpirl Thanks, that's great, but there is obviously more to it, especially on Debian you need to install node through nodesource. Luckily, I have those things all prepared so it really is just a copy-over. What also need to be part of it is a proxy (such as nginx), and configuration that can be adjusted beforehand. Ansible supports jinja and I went through the pain to setup such things already. Lastly, we need a service to run the app, and systemd is probably the most straight-forward method here when targeting Debian only, for Alpine this would be a different story. But, I just don't like to leverage things like pm2, because I hate to learn service runners for each and every language out there. I like to use what I already have available.

I'm glad that you share your starting point, because it gives me an important thing to answer: How to deploy?

When it comes to node projects, I always use Ansible's synchronize module (rsync) to deploy the files and then build it on the target to cover native code dependencies that needs to be built on the target platform. git clone is also a nice way of solving things, although my perspective is that you have to clone the project to get the necessary playbook and all the configuration. You then need to setup your inventory.cfg, might as well upload your local project instead of doing git clone on the target. This would also allow to deploy with local modifications.

How do you think about that?


Here is how I did this approach with a Deno application: https://github.com/martin-braun/cronmon/blob/master/playbook.yml

The ansible folder contains configuration templates. Would love to have some feedback on my approach. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants